aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoromagdy7 <omar.professional8777@gmail.com>2023-05-08 18:32:04 +0300
committeromagdy7 <omar.professional8777@gmail.com>2023-05-08 18:32:04 +0300
commit1584574267bae0ec4b0096ace7a7cbbe08787c05 (patch)
tree912cd58e7e21c35c0afebe125e6badf69c12ed52
parent9621f880a03337a8a252cf5cd3993d5a1a29969c (diff)
downloadMacpan-1584574267bae0ec4b0096ace7a7cbbe08787c05.tar.xz
Macpan-1584574267bae0ec4b0096ace7a7cbbe08787c05.zip
Fixed a bug in inky's algorithms and also now the ghost reset to chase mode after pacman finishes his powerup
-rw-r--r--src/clyde.py3
-rw-r--r--src/ghost.py6
-rw-r--r--src/inky.py7
-rw-r--r--src/mode.py1
-rw-r--r--src/pinky.py9
-rw-r--r--src/settings.py2
6 files changed, 19 insertions, 9 deletions
diff --git a/src/clyde.py b/src/clyde.py
index 140ce16..7dcf54e 100644
--- a/src/clyde.py
+++ b/src/clyde.py
@@ -41,6 +41,9 @@ class Clyde(Ghost):
self.mode = MODE.FRIGHETENED
rand_pos = random.randint(0, 900), random.randint(0, 990)
+ if pacman.powerup is False and self.mode == MODE.FRIGHETENED:
+ self.mode = MODE.CHASING
+
for i in range(len(dx)):
nx = self.x + dx[i] * self.speed
ny = self.y + dy[i] * self.speed
diff --git a/src/ghost.py b/src/ghost.py
index cfd3068..e785afc 100644
--- a/src/ghost.py
+++ b/src/ghost.py
@@ -75,10 +75,11 @@ class Ghost():
if pacman.powerup:
self.mode = MODE.FRIGHETENED
- pacman.sprite = get_sprites(pygame.image.load(
- '../assets/blinky.png').convert_alpha())
rand_pos = random.randint(0, 900), random.randint(0, 990)
+ if pacman.powerup is False and self.mode == MODE.FRIGHETENED:
+ self.mode = MODE.CHASING
+
for i in range(len(dx)):
nx = self.x + dx[i] * self.speed
ny = self.y + dy[i] * self.speed
@@ -119,6 +120,7 @@ class Ghost():
self.last_move = min_idx
def draw(self, screen, powerup, counter):
+ print(f"{self.color} -> mode: {self.mode}")
radius = 30 // 2
pos = (self.x - radius, self.y - radius)
if powerup:
diff --git a/src/inky.py b/src/inky.py
index 1989048..1f5bb8b 100644
--- a/src/inky.py
+++ b/src/inky.py
@@ -43,8 +43,8 @@ class Inky(Ghost):
return (2 * 30 + 15, 30 * 30 + 15)
def get_target(self, inter_tile, blinky):
- target = (inter_tile[0] - (blinky.x - inter_tile[0]),
- inter_tile[1] - (blinky.y - inter_tile[1]))
+ target = (max(inter_tile[0] - (blinky.x - inter_tile[0]) % 900, 0),
+ max(inter_tile[1] - (blinky.y - inter_tile[1]) % 990, 0))
return target
@override
@@ -76,7 +76,8 @@ class Inky(Ghost):
self.mode = MODE.FRIGHETENED
rand_pos = random.randint(0, 900), random.randint(0, 990)
- # y = mx + c
+ if pacman.powerup is False and self.mode == MODE.FRIGHETENED:
+ self.mode = MODE.CHASING
if settings.debug:
pygame.draw.line(screen, self.color, (target),
diff --git a/src/mode.py b/src/mode.py
index 9e7f572..b06bce5 100644
--- a/src/mode.py
+++ b/src/mode.py
@@ -5,3 +5,4 @@ class MODE(Enum):
SCATTERED = 0
FRIGHETENED = 1
CHASING = 2
+ EATEN = 3
diff --git a/src/pinky.py b/src/pinky.py
index 416e7d8..29949a7 100644
--- a/src/pinky.py
+++ b/src/pinky.py
@@ -43,7 +43,7 @@ class Pinky(Ghost):
return (27 * 30 + 15, 30 * 30 + 15)
@override
- def get_next_move(self, target, maze, screen, blinky):
+ def get_next_move(self, pacman, maze, screen, blinky):
default_tile = self.get_default_tile()
dx = [1, 0, -1, 0]
@@ -64,17 +64,20 @@ class Pinky(Ghost):
rand_pos = (0, 0)
- new_target = self.get_four_tiles_ahead_of_pacman(target)
+ new_target = self.get_four_tiles_ahead_of_pacman(pacman)
if settings.debug:
pygame.draw.circle(screen, self.color,
(new_target[0], new_target[1]), 15)
pygame.draw.circle(screen, self.color,
default_tile, 15)
- if target.powerup:
+ if pacman.powerup:
self.mode = MODE.FRIGHETENED
rand_pos = random.randint(0, 900), random.randint(0, 990)
+ if pacman.powerup is False and self.mode == MODE.FRIGHETENED:
+ self.mode = MODE.CHASING
+
for i in range(len(dx)):
if i != forbidden:
nx = self.x + dx[i] * self.speed
diff --git a/src/settings.py b/src/settings.py
index a8dfa24..d1cc93c 100644
--- a/src/settings.py
+++ b/src/settings.py
@@ -3,7 +3,7 @@ class Settings():
self.width = 900
self.height = 990
self.fps = 60
- self.debug = False
+ self.debug = True
self.sound = False