diff --git a/res/lvl0.png b/res/lvl0.png index aa7e2ea..3798fd3 100644 Binary files a/res/lvl0.png and b/res/lvl0.png differ diff --git a/res/pacman_1.png b/res/pacman_1.png index 1357dcb..600ca39 100644 Binary files a/res/pacman_1.png and b/res/pacman_1.png differ diff --git a/res/pacman_2.png b/res/pacman_2.png index 767a169..71b7baa 100644 Binary files a/res/pacman_2.png and b/res/pacman_2.png differ diff --git a/scenes/game_objects/ghost.py b/scenes/game_objects/ghost.py index 63116c2..ce93f55 100644 --- a/scenes/game_objects/ghost.py +++ b/scenes/game_objects/ghost.py @@ -38,7 +38,7 @@ class Ghost(Entity): self.direction = Direction(randint(1, 4)) def on_col(self, c): - if isinstance(c.parent, PacDot): + if not c.solid: return if c.parent.name == 'pacman': diff --git a/scenes/game_objects/level.py b/scenes/game_objects/level.py index 2bda6bd..a2f0e0e 100644 --- a/scenes/game_objects/level.py +++ b/scenes/game_objects/level.py @@ -9,7 +9,7 @@ from engine.components.collide_rect import CollideRect from engine.components.sprite import Sprite from .common import S -from .pacdot import PacDot +from .pacdot import PacDot, EnsmallmentDot class Level(Entity): @@ -36,4 +36,9 @@ class Level(Entity): pc.y = y * S self.scene.add(pc) PacDot.tot += 1 + elif col == (193, 193, 193): + pc = EnsmallmentDot() + pc.x = x * S + pc.y = y * S + self.scene.add(pc) self.add(Sprite(self.surf, 0)) diff --git a/scenes/game_objects/pacdot.py b/scenes/game_objects/pacdot.py index 174179a..4bec626 100644 --- a/scenes/game_objects/pacdot.py +++ b/scenes/game_objects/pacdot.py @@ -5,13 +5,12 @@ from engine.components.collide_rect import CollideRect from engine.components.sprite import Sprite from .common import S -from .pacman import PacMan class PacDot(Entity): tot = 0 s = Surface((S, S)) - draw.circle(s, (255, 255, 0), (S//2, S//2), S//4) + draw.circle(s, (255, 255, 0), (S//2, S//2), 2) def __init__(self): super().__init__(self.__repr__()) @@ -32,3 +31,24 @@ class PacDot(Entity): exit(0) if c.parent.name == 'pacman': self.unregister() + + +class EnsmallmentDot(Entity): + s = Surface((S, S)) + draw.circle(s, (255, 0, 255), (S//2, S//2), 4) + + def __init__(self): + super().__init__(self.__repr__()) + self.add(CollideRect(Rect(0, 0, S, S), + static=True, solid=False, cb=self.cb)) + self.add(Sprite(EnsmallmentDot.s, 1)) + self.dead = False + + def cb(self, c): + if c.parent.name != 'pacman': + return + if self.dead: + return + self.dead = True + if c.parent.name == 'pacman': + self.unregister() diff --git a/scenes/game_objects/pacman.py b/scenes/game_objects/pacman.py index 7285708..bc7dc3a 100644 --- a/scenes/game_objects/pacman.py +++ b/scenes/game_objects/pacman.py @@ -8,24 +8,24 @@ from engine.components.collide_rect import CollideRect from engine.components.sprite import Sprite from .common import S +from .pacdot import EnsmallmentDot class PacMan(Entity): - SIZE = 1 SPEED = 2 def __init__(self, x, y): super().__init__('pacman') - - # surf = Surface((S//PacMan.SIZE, S//PacMan.SIZE)).convert() - # surf.fill((0, 0, 0)) - # draw.circle(surf, - # (255, 255, 0), - # (S//(2*PacMan.SIZE), S//(2*PacMan.SIZE)), - # S//(2*PacMan.SIZE)) surf_1 = image.load(res('pacman_1.png')).convert() surf_2 = image.load(res('pacman_2.png')).convert() + self.smol_surf = Surface((S//2, S//2)).convert() + self.smol_surf.fill((0, 0, 0)) + draw.circle(self.smol_surf, + (255, 255, 0), + (S//4, S//4), + S//4) + self.surf = [[transform.rotate(surf_1, 90), transform.rotate(surf_1, -90), transform.flip(surf_1, True, False), @@ -39,18 +39,49 @@ class PacMan(Entity): self.sprite = self.add(Sprite(self.surf[self.cur_anim][0], 2)) - self.phys = self.add( - CollideRect(Rect(self.x, self.y, - self.sprite.width, self.sprite.width), - static=False)) + self.smol_rect = Rect(self.x, self.y, + self.sprite.width//2, self.sprite.width//2) + self.rect = Rect(self.x, self.y, + self.sprite.width, self.sprite.width) + self.phys = CollideRect(self.rect, + static=False, + cb=self.cb) + + self.add(self.phys) + self.script = PacMan.update self.x = x self.y = y + self.smol = False + self.smol_since = None + + def cb(self, c): + if not isinstance(c.parent, EnsmallmentDot): + return + if not self.smol: + self.x += S//4 + self.y += S//4 + PacMan.SPEED *= 2 + self.smol_rect.x = self.x + self.smol_rect.y = self.y + self.phys.rect = self.smol_rect + self.smol = True + self.smol_since = Game.cur_tick def update(self): p = self.phys s = self.sprite + # Expiration du pouvoir + if self.smol and Game.cur_tick - self.smol_since > 60*2: + self.x -= self.x % S + self.y -= self.y % S + self.rect.x = self.x + self.rect.y = self.y + self.phys.rect = self.rect + self.smol = False + PacMan.SPEED = PacMan.SPEED//2 + # Avance l’animation if Game.cur_tick % 5 == 0: self.cur_anim += 1 @@ -66,8 +97,11 @@ class PacMan(Entity): elif p.vx > 0: s.surf = self.surf[self.cur_anim][3] + if self.smol: + s.surf = self.smol_surf + inputs = key.get_pressed() - if PacMan.SIZE > 1: + if self.smol: p.vx = 0 p.vy = 0 if inputs[K_UP]: