First attempt on ghost movement. /JL
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from .enums import GhostColor, GhostMode, GhostBehavior
|
||||
from .ghost_behaviors import path_toward # required if you want a fallback
|
||||
import actors.ghost_behaviors as GB
|
||||
import pygame
|
||||
|
||||
class Ghost(pygame.sprite.Sprite):
|
||||
@@ -16,13 +16,22 @@ class Ghost(pygame.sprite.Sprite):
|
||||
self.mode = GhostMode.SCATTER
|
||||
self.home_position = position
|
||||
|
||||
def decide_direction(self, ghost, pacman, maze):
|
||||
strategy = {
|
||||
GhostBehavior.BLINKY: GB.blinky_behavior,
|
||||
GhostBehavior.PINKY: GB.pinky_behavior,
|
||||
GhostBehavior.INKY: GB.inky_behavior,
|
||||
GhostBehavior.CLYDE: GB.clyde_behavior,
|
||||
}
|
||||
return strategy[self.behavior](ghost, pacman, maze)
|
||||
|
||||
def update(self, maze, pacman):
|
||||
if self.mode == GhostMode.FRIGHTENED:
|
||||
self.change_direction_randomly(maze)
|
||||
else:
|
||||
self.direction = self.behavior.decide_direction(self, pacman, maze)
|
||||
self.direction = self.decide_direction(self, pacman, maze)
|
||||
new_pos = self.rect.move(self.direction.x * self.speed, self.direction.y * self.speed)
|
||||
if not maze.is_wall(new_pos.center):
|
||||
if not maze.is_wall(new_pos[0], new_pos[1]):
|
||||
self.rect = new_pos
|
||||
|
||||
def change_direction_randomly(self, maze):
|
||||
|
||||
Reference in New Issue
Block a user