aboutsummaryrefslogtreecommitdiff
path: root/src/player.py
diff options
context:
space:
mode:
authorMoisis <moisis.george@yahoo.com>2023-05-17 14:04:38 +0300
committerMoisis <moisis.george@yahoo.com>2023-05-17 14:04:38 +0300
commit3d7e3d1eba26cc57b31337b0708fce3747f8a988 (patch)
treee9f47e18b3a6365ca383a6da0cbbc424e8b6d3fd /src/player.py
parent8eeb31dba61e8c9b29704c5988f95dcba4338fca (diff)
downloadMacpan-3d7e3d1eba26cc57b31337b0708fce3747f8a988.tar.xz
Macpan-3d7e3d1eba26cc57b31337b0708fce3747f8a988.zip
Improved GUI
Settings added (Debug , Sound) SoundSystem added (Become sometimes laggy)
Diffstat (limited to 'src/player.py')
-rw-r--r--src/player.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/player.py b/src/player.py
index 92c4a84..590405a 100644
--- a/src/player.py
+++ b/src/player.py
@@ -6,7 +6,9 @@ import pygame
class Player():
- def __init__(self, sprite_sheet):
+
+ def __init__(self, sprite_sheet, settings):
+ self.settings = settings
self.x = 30 * 17 - 15
self.y = 30 * 25 - 15
self.sprite_sheet = sprite_sheet
@@ -18,6 +20,7 @@ class Player():
# checks if the current position of pacman is either a dot, big dot or free
def is_valid(self, game_state, x, y):
+
if x >= 0 and x < 30:
is_dot = game_state.map.maze[y][x] == Map.D
is_big_dot = game_state.map.maze[y][x] == Map.BD
@@ -27,6 +30,8 @@ class Player():
game_state.food += 1
if is_dot:
game_state.score += 10
+
+
if is_big_dot:
self.powerup = True
self.timer = Timer(5 * 1000)
@@ -53,11 +58,15 @@ class Player():
return True
def draw(self, screen, counter):
+ voice = pygame.mixer.Channel(2)
+ Soundpowerup = pygame.mixer.Sound('../assets/sfx/power_pellet.wav')
if self.timer is not None:
elapsed_time = pygame.time.get_ticks() - self.timer.start
if elapsed_time > self.timer.duration:
self.powerup = False
+
+
radius = 30 // 2
pos = (self.x - radius, self.y - radius)
sprite_sheet = [2, 0, 3, 1]
@@ -67,7 +76,12 @@ class Player():
image = pygame.transform.scale(
self.sprite[sprite_sheet[self.direction.value]], (40, 40))
screen.blit(image, pos)
+ if self.settings.sound:
+ if not (voice.get_busy()):
+ voice.play(Soundpowerup)
+
else:
+ voice.stop()
self.sprite = get_sprites(self.sprite_sheet)
image = pygame.transform.scale(self.sprite[counter // 5], (35, 35))
if self.direction == DIRECTION.UP: