35 lines
899 B
Python
35 lines
899 B
Python
from pygame import Surface, draw, Rect
|
||
|
||
from engine.entity import Entity
|
||
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)
|
||
|
||
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(PacDot.s, 1))
|
||
self.dead = False
|
||
|
||
def cb(self, c):
|
||
if c.parent.name != 'pacman':
|
||
return
|
||
if self.dead:
|
||
return
|
||
self.dead = True
|
||
PacDot.tot -= 1
|
||
if PacDot.tot == 0:
|
||
print('Gagné !')
|
||
exit(0)
|
||
if c.parent.name == 'pacman':
|
||
self.unregister()
|