I've been making pong with pygame and I got the ball to bounce around the screen and on the paddles. However, the speed is too high and I want to decrease it. This is what the code looks like for the Ball object:
import pygame as pg
BLACK = (0, 0, 0)
class Ball(pg.sprite.Sprite):
def __init__(self, color, width, height, radius):
super().__init__()
self.x_vel = 1
self.y_vel = 1
self.image = pg.Surface([width * 2, height * 2])
self.image.fill(BLACK)
self.image.set_colorkey(BLACK)
pg.draw.circle(self.image, color, center=[width, height], radius=radius)
self.rect = self.image.get_rect()
def update_ball(self):
self.rect.x += self.x_vel
self.rect.y += self.y_vel
If I try to set the velocity as a float, it stops the ball completely. Can someone help me?