generated from mwc/project_game
at Chris: how could i get the ball too collide
with the paddle?
This commit is contained in:
47
paddle.py
Normal file
47
paddle.py
Normal file
@@ -0,0 +1,47 @@
|
||||
# paddle.py
|
||||
class PaddlePiece:
|
||||
character = "X"
|
||||
def __init__(self, position):
|
||||
self.position = position
|
||||
|
||||
class Paddle:
|
||||
width = 5
|
||||
display = False
|
||||
pieces = []
|
||||
|
||||
def __init__(self, position):
|
||||
self.position = position
|
||||
|
||||
def play_turn(self, game):
|
||||
if not self.pieces:
|
||||
self.create_pieces(game)
|
||||
check_collision()
|
||||
|
||||
def check_collision:
|
||||
x, y = self.position
|
||||
print (retro.game.Game.get_agent_by_name(ball))
|
||||
|
||||
def handle_keystroke(self, keystroke, game):
|
||||
x, y = self.position
|
||||
width, height = game.board_size
|
||||
if keystroke.name == "KEY_LEFT":
|
||||
if 0 < x:
|
||||
self.position = (x-1, y)
|
||||
self.update_piece_positions()
|
||||
if keystroke.name == "KEY_RIGHT":
|
||||
if x + self.width < width:
|
||||
self.position = (x+1, y)
|
||||
self.update_piece_positions()
|
||||
|
||||
def create_pieces(self, game):
|
||||
x, y = self.position
|
||||
self.pieces = []
|
||||
for i in range(self.width):
|
||||
piece = PaddlePiece((x + i, y))
|
||||
self.pieces.append(piece)
|
||||
game.add_agent(piece)
|
||||
|
||||
def update_piece_positions(self):
|
||||
x, y = self.position
|
||||
for i, piece in enumerate(self.pieces):
|
||||
piece.position = (x + i, y)
|
||||
Reference in New Issue
Block a user