From 3634fcc4f9f62d40ea03ba890a3290e05ed20ed8 Mon Sep 17 00:00:00 2001 From: omagdy7 Date: Sun, 16 Apr 2023 17:49:50 +0200 Subject: Added all ghosts with A* search for now --- src/Game.py | 16 ++++++++-------- src/Ghost.py | 10 ---------- src/map.py | 3 ++- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/Game.py b/src/Game.py index 19901a6..e4784c9 100644 --- a/src/Game.py +++ b/src/Game.py @@ -25,10 +25,10 @@ class Game(): '../assets/pacman_left_sprite.png').convert_alpha() player = Player.Player(sprite_sheet) - inky = Ghost.Ghost("green", 75, 75) - pinky = Ghost.Ghost("cyan", 27 * 30, 30 * 30 + 15) - clyde = Ghost.Ghost("red", 27 * 30 + 15, 75) - winky = Ghost.Ghost("purple", 75, 30 * 30 + 15) + blinky = Ghost.Ghost("red", 75, 75) + pinky = Ghost.Ghost("pink", 27 * 30, 30 * 30 + 15) + inky = Ghost.Ghost("orange", 75, 30 * 30 + 15) + clyde = Ghost.Ghost("cyan", 27 * 30 + 15, 75) # Set the pacman velocity dx = 0 @@ -152,15 +152,15 @@ class Game(): player.y += dy - inky.move(maze.maze, (player.x, player.y)) + blinky.move(maze.maze, (player.x, player.y)) pinky.move(maze.maze, (player.x, player.y)) - winky.move(maze.maze, (player.x, player.y)) + inky.move(maze.maze, (player.x, player.y)) clyde.move(maze.maze, (player.x, player.y)) maze.draw_map(screen) player.draw(screen, counter) - inky.draw(screen) + blinky.draw(screen) pinky.draw(screen) - winky.draw(screen) + inky.draw(screen) clyde.draw(screen) # Update the screen diff --git a/src/Ghost.py b/src/Ghost.py index 11c195b..d4bc683 100644 --- a/src/Ghost.py +++ b/src/Ghost.py @@ -1,9 +1,7 @@ -from typing import List import pygame import math from Direction import DIRECTION import map as Map -import random class Ghost(): def __init__(self, color, x, y): @@ -69,15 +67,7 @@ class Ghost(): if self.check_collision(nx, ny, 30, 30, maze): ret[i] = self.heuristic((nx, ny), pacman_pos) - print("--------------------") - min_idx = ret.index(min(ret)) - print(f"last_move: {self.last_move}, current_move: {min_idx}") - x1 = self.x + dx[2] * self.speed - y1 = self.y + dy[2] * self.speed - x2 = self.x + dx[0] * self.speed - y2 = self.y + dy[0] * self.speed - print(f"hl = {self.heuristic((x1, y1), pacman_pos)}, h2 = {self.heuristic((x2, y2), pacman_pos)}") return min_idx diff --git a/src/map.py b/src/map.py index 9248241..34f066a 100644 --- a/src/map.py +++ b/src/map.py @@ -12,6 +12,7 @@ TL = 32 BL = 64 BR = 128 G = 256 +P = 512 PI = math.pi @@ -34,7 +35,7 @@ class Map(): [V, 0, 0, 0, 0, 0, V, D, V, V, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, V, V, D, V, 0, 0, 0, 0, 0, V], [BR, 0, 0, 0, 0, 0, V, D, V, V, 0, TL, H, H, G, G, H, H, TR, 0, V, V, D, V, 0, 0, 0, 0, 0, BL], [H, H, H, H, H, H, BR, D, BL, BR, 0, V, 0, 0, 0, 0, 0, 0, V, 0, BL, BR, D, BL, H, H, H, H, H, H], - [0, 0, 0, 0, 0, 0, 0, D, 0, 0, 0, V, 0, 0, 0, 0, 0, 0, V, 0, 0, 0, D, 0, 0, 0, 0, 0, 0, 0], + [P, 0, 0, 0, 0, 0, 0, D, 0, 0, 0, V, 0, 0, 0, 0, 0, 0, V, 0, 0, 0, D, 0, 0, 0, 0, 0, 0, P], [H, H, H, H, H, H, TR, D, TL, TR, 0, V, 0, 0, 0, 0, 0, 0, V, 0, TL, TR, D, TL, H, H, H, H, H, H], [TR, 0, 0, 0, 0, 0, V, D, V, V, 0, BL, H, H, H, H, H, H, BR, 0, V, V, D, V, 0, 0, 0, 0, 0, TL], [V, 0, 0, 0, 0, 0, V, D, V, V, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, V, V, D, V, 0, 0, 0, 0, 0, V], -- cgit v1.2.3