Added maze constricted movement. /JL
This commit is contained in:
@@ -15,7 +15,7 @@ class ActorPacman:
|
|||||||
self.max_mouth_deg = 45
|
self.max_mouth_deg = 45
|
||||||
self.animate_speed = 2
|
self.animate_speed = 2
|
||||||
self.mouth_closing = False
|
self.mouth_closing = False
|
||||||
self.location = start_location
|
self.location = list(start_location)
|
||||||
self.maze = maze
|
self.maze = maze
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
@@ -53,18 +53,34 @@ class ActorPacman:
|
|||||||
def move_right(self):
|
def move_right(self):
|
||||||
for _ in range(16):
|
for _ in range(16):
|
||||||
self.x += self.speed
|
self.x += self.speed
|
||||||
|
self.location[0] += 1
|
||||||
|
if self.location[0] > 28:
|
||||||
|
self.location[0] = 0
|
||||||
|
self.x = 16
|
||||||
|
|
||||||
def move_left(self):
|
def move_left(self):
|
||||||
for _ in range(16):
|
for _ in range(16):
|
||||||
self.x -= self.speed
|
self.x -= self.speed
|
||||||
|
self.location[0] -= 1
|
||||||
|
if self.location[0] < 0:
|
||||||
|
self.location[0] = 28
|
||||||
|
self.x = (32 * 29) - 16
|
||||||
|
|
||||||
def move_up(self):
|
def move_up(self):
|
||||||
for _ in range(16):
|
for _ in range(16):
|
||||||
self.y -= self.speed
|
self.y -= self.speed
|
||||||
|
self.location[1] -= 1
|
||||||
|
if self.location[1] < 0:
|
||||||
|
self.location[1] = 32
|
||||||
|
self.y = (32 * 30) + 48
|
||||||
|
|
||||||
def move_down(self):
|
def move_down(self):
|
||||||
for _ in range(16):
|
for _ in range(16):
|
||||||
self.y += self.speed
|
self.y += self.speed
|
||||||
|
self.location[1] += 1
|
||||||
|
if self.location[1] > 32:
|
||||||
|
self.location[1] = 0
|
||||||
|
self.y = 48
|
||||||
|
|
||||||
def set_direction(self, dir: PlayerDirection):
|
def set_direction(self, dir: PlayerDirection):
|
||||||
self.direction = dir
|
self.direction = dir
|
18
pman.py
18
pman.py
@@ -7,7 +7,7 @@ from actors.ghost_mode_controller import GhostModeController
|
|||||||
from hud import HUD
|
from hud import HUD
|
||||||
from maze import Maze
|
from maze import Maze
|
||||||
|
|
||||||
__version__ = "0.3.2"
|
__version__ = "0.3.3"
|
||||||
|
|
||||||
|
|
||||||
def spawn_ghosts(center_position):
|
def spawn_ghosts(center_position):
|
||||||
@@ -61,29 +61,45 @@ def main() -> None:
|
|||||||
case pygame.KEYDOWN:
|
case pygame.KEYDOWN:
|
||||||
match event.key:
|
match event.key:
|
||||||
case pygame.K_RIGHT:
|
case pygame.K_RIGHT:
|
||||||
|
if maze.is_wall(player.location[0] + 1, player.location[1]):
|
||||||
|
break
|
||||||
player.direction = PlayerDirection.DirectionRight
|
player.direction = PlayerDirection.DirectionRight
|
||||||
player.move_right()
|
player.move_right()
|
||||||
case pygame.K_LEFT:
|
case pygame.K_LEFT:
|
||||||
|
if maze.is_wall(player.location[0] - 1, player.location[1]):
|
||||||
|
break
|
||||||
player.direction = PlayerDirection.DirectionLeft
|
player.direction = PlayerDirection.DirectionLeft
|
||||||
player.move_left()
|
player.move_left()
|
||||||
case pygame.K_UP:
|
case pygame.K_UP:
|
||||||
|
if maze.is_wall(player.location[0], player.location[1] - 1):
|
||||||
|
break
|
||||||
player.direction = PlayerDirection.DirectionUp
|
player.direction = PlayerDirection.DirectionUp
|
||||||
player.move_up()
|
player.move_up()
|
||||||
case pygame.K_DOWN:
|
case pygame.K_DOWN:
|
||||||
|
if maze.is_wall(player.location[0], player.location[1] + 1):
|
||||||
|
break
|
||||||
player.direction = PlayerDirection.DirectionDown
|
player.direction = PlayerDirection.DirectionDown
|
||||||
player.move_down()
|
player.move_down()
|
||||||
case pygame.JOYHATMOTION:
|
case pygame.JOYHATMOTION:
|
||||||
hat_x, hat_y = event.value
|
hat_x, hat_y = event.value
|
||||||
if hat_x == 1:
|
if hat_x == 1:
|
||||||
|
if maze.is_wall(player.location[0] + 1, player.location[1]):
|
||||||
|
break
|
||||||
player.direction = PlayerDirection.DirectionRight
|
player.direction = PlayerDirection.DirectionRight
|
||||||
player.move_right()
|
player.move_right()
|
||||||
elif hat_x == -1:
|
elif hat_x == -1:
|
||||||
|
if maze.is_wall(player.location[0] - 1, player.location[1]):
|
||||||
|
break
|
||||||
player.direction = PlayerDirection.DirectionLeft
|
player.direction = PlayerDirection.DirectionLeft
|
||||||
player.move_left()
|
player.move_left()
|
||||||
elif hat_y == 1:
|
elif hat_y == 1:
|
||||||
|
if maze.is_wall(player.location[0], player.location[1] - 1):
|
||||||
|
break
|
||||||
player.direction = PlayerDirection.DirectionUp
|
player.direction = PlayerDirection.DirectionUp
|
||||||
player.move_up()
|
player.move_up()
|
||||||
elif hat_y == -1:
|
elif hat_y == -1:
|
||||||
|
if maze.is_wall(player.location[0], player.location[1] + 1):
|
||||||
|
break
|
||||||
player.direction = PlayerDirection.DirectionDown
|
player.direction = PlayerDirection.DirectionDown
|
||||||
player.move_down()
|
player.move_down()
|
||||||
# Handle hotplugging
|
# Handle hotplugging
|
||||||
|
Reference in New Issue
Block a user