aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoromagdy7 <omar.professional8777@gmail.com>2023-05-08 23:18:26 +0300
committeromagdy7 <omar.professional8777@gmail.com>2023-05-08 23:18:26 +0300
commit5b2e6b7e660865b6db9bfb61e1b1d0fecc536858 (patch)
treec559cf0ffe2b524982aec1f93ec2c1dae29eeeb9
parentaaf0194f9b5d93bd6612bc0b419c4b8f89b4aa21 (diff)
downloadMacpan-5b2e6b7e660865b6db9bfb61e1b1d0fecc536858.tar.xz
Macpan-5b2e6b7e660865b6db9bfb61e1b1d0fecc536858.zip
Added EatenMode
-rw-r--r--src/clyde.py7
-rw-r--r--src/ghost.py15
-rw-r--r--src/inky.py6
-rw-r--r--src/pinky.py6
4 files changed, 29 insertions, 5 deletions
diff --git a/src/clyde.py b/src/clyde.py
index 755eafd..2fd4aee 100644
--- a/src/clyde.py
+++ b/src/clyde.py
@@ -42,7 +42,7 @@ class Clyde(Ghost):
rand_pos = (0, 0)
- if game_state.pacman.powerup:
+ if game_state.pacman.powerup and self.mode != MODE.EATEN:
self.mode = MODE.FRIGHETENED
rand_pos = random.randint(0, 900), random.randint(0, 990)
@@ -77,7 +77,10 @@ class Clyde(Ghost):
if settings.debug:
pygame.draw.line(screen, self.color, (game_state.pacman.x, game_state.pacman.y),
(self.x, self.y), 1)
-
+ elif self.mode == MODE.EATEN:
+ pos = self.get_intial_tile()
+ self.x = pos[0]
+ self.y = pos[1]
min_h = min(ret)
# Favour going up when there is a conflict
diff --git a/src/ghost.py b/src/ghost.py
index c05eb1b..8568ff4 100644
--- a/src/ghost.py
+++ b/src/ghost.py
@@ -3,6 +3,7 @@ import time
import random
import math
from util import get_sprites
+from timer import Timer
from settings import settings
from mode import MODE
from direction import DIRECTION
@@ -25,6 +26,7 @@ class Ghost():
self.color = color
self.last_move = 3 # this represents the direction based on the dx, dy arrays
self.speed = 3
+ self.timer = None
self.mode = MODE.SCATTERED
def in_bounds(self, pos):
@@ -69,6 +71,8 @@ class Ghost():
def check_pacman_collision(self, game_state):
if game_state.pacman.powerup and abs(game_state.pacman.x - self.x) <= 30 and abs(game_state.pacman.y - self.y) <= 30:
initial_position = self.get_intial_tile()
+ self.mode = MODE.EATEN
+ self.timer = Timer(2 * 1000)
time.sleep(1)
game_state.score += 200
self.x = initial_position[0]
@@ -87,7 +91,7 @@ class Ghost():
rand_pos = (0, 0)
- if game_state.pacman.powerup:
+ if game_state.pacman.powerup and self.mode != MODE.EATEN:
self.mode = MODE.FRIGHETENED
rand_pos = random.randint(0, 900), random.randint(0, 990)
@@ -108,6 +112,10 @@ class Ghost():
elif self.mode == MODE.FRIGHETENED:
ret[i] = self.heuristic(
(nx, ny), rand_pos[0], rand_pos[1])
+ elif self.mode == MODE.EATEN:
+ pos = self.get_intial_tile()
+ self.x = pos[0]
+ self.y = pos[1]
if settings.debug:
pygame.draw.line(screen, self.color, (game_state.pacman.x, game_state.pacman.y),
(self.x, self.y), 1)
@@ -134,6 +142,11 @@ class Ghost():
self.last_move = min_idx
def draw(self, screen, powerup, counter):
+ if self.timer is not None:
+ elapsed_time = pygame.time.get_ticks() - self.timer.start
+ if elapsed_time > self.timer.duration:
+ self.mode = MODE.CHASING
+
radius = 30 // 2
pos = (self.x - radius, self.y - radius)
if powerup:
diff --git a/src/inky.py b/src/inky.py
index 2b48ede..be2e62c 100644
--- a/src/inky.py
+++ b/src/inky.py
@@ -76,7 +76,7 @@ class Inky(Ghost):
rand_pos = (0, 0)
- if game_state.pacman.powerup:
+ if game_state.pacman.powerup and self.mode != MODE.EATEN:
self.mode = MODE.FRIGHETENED
rand_pos = random.randint(0, 900), random.randint(0, 990)
@@ -101,6 +101,10 @@ class Inky(Ghost):
elif self.mode == MODE.CHASING:
ret[i] = self.heuristic(
(nx, ny), target[0], target[1])
+ elif self.mode == MODE.EATEN:
+ pos = self.get_intial_tile()
+ self.x = pos[0]
+ self.y = pos[1]
min_h = min(ret)
diff --git a/src/pinky.py b/src/pinky.py
index 5f58f54..bb50c5b 100644
--- a/src/pinky.py
+++ b/src/pinky.py
@@ -70,7 +70,7 @@ class Pinky(Ghost):
new_target = self.get_four_tiles_ahead_of_pacman(game_state.pacman)
- if game_state.pacman.powerup:
+ if game_state.pacman.powerup and self.mode != MODE.EATEN:
self.mode = MODE.FRIGHETENED
rand_pos = random.randint(0, 900), random.randint(0, 990)
@@ -91,6 +91,10 @@ class Pinky(Ghost):
elif self.mode == MODE.CHASING:
ret[i] = self.heuristic(
(nx, ny), new_target[0], new_target[1])
+ elif self.mode == MODE.EATEN:
+ pos = self.get_intial_tile()
+ self.x = pos[0]
+ self.y = pos[1]
if settings.debug:
pygame.draw.line(screen, self.color, (new_target),
(self.x, self.y), 1)