2019-12-09 12:36:42 +01:00
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PacDot(Entity):
|
|
|
|
|
tot = 0
|
|
|
|
|
s = Surface((S, S))
|
2019-12-09 13:21:33 +01:00
|
|
|
|
draw.circle(s, (255, 255, 0), (S//2, S//2), 2)
|
2019-12-09 12:36:42 +01:00
|
|
|
|
|
|
|
|
|
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()
|
2019-12-09 13:21:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|