generated from mwc/project_game
at Chris: how could i get the ball too collide
with the paddle?
This commit is contained in:
20
ball.py
Normal file
20
ball.py
Normal 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)
|
||||
Reference in New Issue
Block a user