at Chris: how could i get the ball too collide

with the paddle?
This commit is contained in:
gsanders
2025-12-17 09:46:53 -05:00
parent b40bbcb499
commit d41f61c3bd
5 changed files with 82 additions and 0 deletions

20
ball.py Normal file
View File

@@ -0,0 +1,20 @@
# ball.py
class Ball:
character = "O"
def __init__(self, position):
self.position = position
self.velocity = (1, 1)
def play_turn(self, game):
x, y = self.position
vx, vy = self.velocity
new_x = x + vx
new_y = y + vy
board_x, board_y = game.board_size
if new_x < 0 or board_x <= new_x:
self.velocity = (-vx, vy)
elif new_y < 0 or board_y <= new_y:
self.velocity = (vx, -vy)
else:
self.position = (new_x, new_y)