Compare commits
No commits in common. "main" and "5.l" have entirely different histories.
2
main.py
2
main.py
|
@ -10,7 +10,7 @@ class Game:
|
|||
def __init__(self) -> None:
|
||||
self.running = True
|
||||
self.is_pause = False
|
||||
self.pl = Player()
|
||||
self.pl = Player(self)
|
||||
self.out = Out(self.pl)
|
||||
|
||||
kb.add_hotkey(QUIT_BUTTON, self.stop_game)
|
||||
|
|
13
player.py
13
player.py
|
@ -4,8 +4,7 @@ from food import Food
|
|||
|
||||
|
||||
class Player:
|
||||
def __init__(self) -> None:
|
||||
self.start_direciton = MAIN_DIRECTION
|
||||
def __init__(self, game) -> None:
|
||||
self.direction = MAIN_DIRECTION
|
||||
self.body = [Point(MAIN_X, MAIN_Y)]
|
||||
|
||||
|
@ -35,8 +34,6 @@ class Player:
|
|||
raise IndexError("Player has collision with self")
|
||||
|
||||
def update(self) -> None:
|
||||
self.start_direction = self.direction
|
||||
|
||||
if self.body[-1] == self.food:
|
||||
self.food.generate_new()
|
||||
self.score += 1
|
||||
|
@ -46,17 +43,17 @@ class Player:
|
|||
Player._check_collision(self.body)
|
||||
|
||||
def left(self, game) -> None:
|
||||
if not game.is_pause and self.start_direction != D_RIGHT:
|
||||
if not game.is_pause and self.direction != D_RIGHT:
|
||||
self.direction = D_LEFT
|
||||
|
||||
def right(self, game) -> None:
|
||||
if not game.is_pause and self.start_direction != D_LEFT:
|
||||
if not game.is_pause and self.direction != D_LEFT:
|
||||
self.direction = D_RIGHT
|
||||
|
||||
def up(self, game) -> None:
|
||||
if not game.is_pause and self.start_direction != D_DOWN:
|
||||
if not game.is_pause and self.direction != D_DOWN:
|
||||
self.direction = D_UP
|
||||
|
||||
def down(self, game) -> None:
|
||||
if not game.is_pause and self.start_direction != D_UP:
|
||||
if not game.is_pause and self.direction != D_UP:
|
||||
self.direction = D_DOWN
|
||||
|
|
Loading…
Reference in New Issue