diff --git a/scenes/game_objects/ghost.py b/scenes/game_objects/ghost.py index 5ec01f7..959ed4c 100644 --- a/scenes/game_objects/ghost.py +++ b/scenes/game_objects/ghost.py @@ -55,20 +55,17 @@ class Ghost(Entity): return def script(self): - graph = SceneManager().scene.entities['level'].graph + level = SceneManager().scene.entities['level'] + if self.x >= level.w: + self.x = 0 + if self.x < 0: + self.x = level.w-1 if self.x % S != 0 or self.y % S != 0: return - - # cur_node = graph[self.y//S][self.x//S] - # print(self.y//S, self.x//S) + graph = SceneManager().scene.entities['level'].graph pacman = SceneManager().scene.entities['pacman'] - # x_dist = pacman.x - self.x - # y_dist = pacman.y - self.y - # s = 1 - # print(pacman.y//S, pacman.x//S) p = self.find_shortest_path(graph[pacman.y//S][pacman.x//S]) - # print([x[1] for x in p]) cur_dir = p[0][1] if cur_dir == Direction.UP: self.phys.vx = 0 @@ -83,19 +80,6 @@ class Ghost(Entity): self.phys.vx = 1 self.phys.vy = 0 - # if self.direction == Direction.UP: - # self.phys.vy = -Ghost.SPEED - # self.phys.vx = 0 - # elif self.direction == Direction.DOWN: - # self.phys.vy = Ghost.SPEED - # self.phys.vx = 0 - # elif self.direction == Direction.LEFT: - # self.phys.vx = -Ghost.SPEED - # self.phys.vy = 0 - # elif self.direction == Direction.RIGHT: - # self.phys.vx = Ghost.SPEED - # self.phys.vy = 0 - def find_shortest_path(self, final_node): if final_node is None: print('oups') diff --git a/scenes/game_objects/level.py b/scenes/game_objects/level.py index 3351b58..62d6b89 100644 --- a/scenes/game_objects/level.py +++ b/scenes/game_objects/level.py @@ -53,6 +53,8 @@ class Level(Entity): def load(self): desc = image.load(res(self.path)) w, h = desc.get_size() + self.w = w * S + self.h = h * S GraphicsServer().resize((w * S, h * S)) self.surf = Surface((w * S, h * S)).convert() self.surf.fill((0, 0, 0)) diff --git a/scenes/game_objects/pacman.py b/scenes/game_objects/pacman.py index c373d35..70c66c6 100644 --- a/scenes/game_objects/pacman.py +++ b/scenes/game_objects/pacman.py @@ -3,6 +3,7 @@ from pygame.locals import K_UP, K_DOWN, K_LEFT, K_RIGHT from engine.entity import Entity from engine.game import Game +from engine.scene_manager import SceneManager from engine.resources import res from engine.components.collide_rect import CollideRect from engine.components.sprite import Sprite @@ -82,6 +83,12 @@ class PacMan(Entity): p = self.phys s = self.sprite + level = SceneManager().scene.entities['level'] + if self.x >= level.w: + self.x = 0 + if self.x < 0: + self.x = level.w-1 + # Expiration du rapetissement. if self.smol and Game.cur_tick - self.smol_since > 60*2: # On se réaligne dans le couloir.