aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Ghost.py24
-rw-r--r--src/pinky.pngbin2911 -> 0 bytes
-rw-r--r--src/pinky.py9
3 files changed, 19 insertions, 14 deletions
diff --git a/src/Ghost.py b/src/Ghost.py
index a26de62..668c943 100644
--- a/src/Ghost.py
+++ b/src/Ghost.py
@@ -1,7 +1,6 @@
-import pygame
import math
from util import get_sprites
-from Direction import DIRECTION
+from settings import settings
import map as Map
class Ghost():
@@ -13,10 +12,12 @@ class Ghost():
self.last_move = 3
self.speed = 3
- def heuristic(self, pacman_pos, next_pos):
- return abs(next_pos[0] - pacman_pos[0]) + abs(next_pos[1] - pacman_pos[1])
-
+ def in_bounds(self, pos):
+ (x, y) = pos
+ return (x >= 0) and (y >= 0) and (x < settings.width - 30) and (y < settings.height)
+ def heuristic(self, next_pos, tx, ty):
+ return abs(next_pos[0] - tx) + abs(next_pos[1] - ty)
# checks if the current position of pacman is either a dot, big dot or free
@@ -38,7 +39,7 @@ class Ghost():
py = ny + direct_y[i] * 14
x = px // gx
y = py // gy
- if not self.is_valid(maze, x, y):
+ if not self.in_bounds((px, py)) or not self.is_valid(maze, x, y):
return False
return True
@@ -66,7 +67,7 @@ class Ghost():
nx = self.x + dx[i] * self.speed
ny = self.y + dy[i] * self.speed
if self.check_collision(nx, ny, 30, 30, maze):
- ret[i] = self.heuristic((nx, ny), (pacman.x, pacman.y))
+ ret[i] = self.heuristic((nx, ny), pacman.x, pacman.y)
min_idx = ret.index(min(ret))
return min_idx
@@ -85,4 +86,11 @@ class Ghost():
def draw(self, screen):
radius = 30 // 2
pos = (self.x - radius , self.y - radius)
- screen.blit(self.sprite[0], pos)
+ if self.last_move == 0:
+ screen.blit(self.sprite[2], pos)
+ elif self.last_move == 1:
+ screen.blit(self.sprite[0], pos)
+ elif self.last_move == 2:
+ screen.blit(self.sprite[3], pos)
+ elif self.last_move == 3:
+ screen.blit(self.sprite[1], pos)
diff --git a/src/pinky.png b/src/pinky.png
deleted file mode 100644
index 59661ee..0000000
--- a/src/pinky.png
+++ /dev/null
Binary files differ
diff --git a/src/pinky.py b/src/pinky.py
index f89865d..c8324bb 100644
--- a/src/pinky.py
+++ b/src/pinky.py
@@ -9,12 +9,8 @@ class Pinky(Ghost):
super().__init__(sprite_sheet,"pink", x, y)
-
- def in_bounds(self, pos):
- return pos[0] >= 0 and pos[1] >= 0 and pos[0] < settings.width and pos[1] < settings.height
-
-
def get_four_tiles_ahead_of_pacman(self, pacman):
+ print("Before", pacman.x, pacman.y)
if pacman.direction == DIRECTION.UP:
new_target = (pacman.x - 30 * 4, pacman.y - 30 * 4)
if self.in_bounds(new_target):
@@ -59,13 +55,14 @@ class Pinky(Ghost):
forbidden = 1
new_target = self.get_four_tiles_ahead_of_pacman(target)
+ print("After: ", new_target)
for i in range(len(dx)):
if i != forbidden:
nx = self.x + dx[i] * self.speed
ny = self.y + dy[i] * self.speed
if self.check_collision(nx, ny, 30, 30, maze):
- ret[i] = self.heuristic((nx, ny), new_target)
+ ret[i] = self.heuristic((nx, ny), new_target[0], new_target[1])
min_idx = ret.index(min(ret))
return min_idx