diff --git a/scenes/game_objects/ghost.py b/scenes/game_objects/ghost.py index fea0e62..5ec01f7 100644 --- a/scenes/game_objects/ghost.py +++ b/scenes/game_objects/ghost.py @@ -3,7 +3,6 @@ from random import random, randint from pygame import Rect, image 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 @@ -61,12 +60,12 @@ class Ghost(Entity): if self.x % S != 0 or self.y % S != 0: return - cur_node = graph[self.y//S][self.x//S] + # cur_node = graph[self.y//S][self.x//S] # print(self.y//S, self.x//S) pacman = SceneManager().scene.entities['pacman'] - x_dist = pacman.x - self.x - y_dist = pacman.y - self.y - s = 1 + # 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]) diff --git a/scenes/game_objects/level.py b/scenes/game_objects/level.py index 9b20fcc..3351b58 100644 --- a/scenes/game_objects/level.py +++ b/scenes/game_objects/level.py @@ -1,4 +1,5 @@ from itertools import product +from enum import Enum, auto from pygame import Surface, Rect, image @@ -31,10 +32,24 @@ class Node(): class Level(Entity): + class Tile(Enum): + AIR = auto() + WALL = auto() + def __init__(self, path): super().__init__('level') self.path = path + colors = {(0, 0, 0): Tile.AIR, # empty + (0, 0, 255): Tile.WALL, # wall + (255, 0, 0): Tile.AIR, # tele + (255, 255, 0): Tile.WALL, # idk + (255, 0, 255): Tile.WALL, # inside cage + (0, 255, 0): Tile.WALL, # cage entrance + (0, 255, 255): Tile.WALL, # cage wall + (139, 139, 139): Tile.AIR, # pac-dot + (193, 193, 193): Tile.AIR} # ensmallment dot + def load(self): desc = image.load(res(self.path)) w, h = desc.get_size() @@ -45,21 +60,22 @@ class Level(Entity): wall.fill((0, 0, 255)) self.graph = [[None for x in range(w)] for y in range(h)] for x, y in product(range(w), range(h)): - col = desc.get_at((x, y)) + col = desc.get_at((x, y))[:3] - if col in ((0, 0, 0), (255, 0, 0), (139, 139, 139), - (193, 193, 193)): + if Level.colors[col] == Level.Tile.AIR: self.graph[y][x] = Node() - if col == (0, 0, 255): + elif Level.colors[col] == Level.Tile.WALL: self.add(CollideRect(Rect(x * S, y * S, S, S))) + wall.fill(col) self.surf.blit(wall, (x * S, y * S)) - elif col == (139, 139, 139): + + if col == (139, 139, 139): # pac-dot pc = PacDot() pc.x = x * S pc.y = y * S self.scene.add(pc) PacDot.tot += 1 - elif col == (193, 193, 193): + elif col == (193, 193, 193): # ensmallment dot pc = EnsmallmentDot() pc.x = x * S pc.y = y * S