55 lines
1.4 KiB
Python
55 lines
1.4 KiB
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
|
||
|
||
|
||
class PacDot(Entity):
|
||
tot = 0
|
||
s = Surface((S, S))
|
||
draw.circle(s, (255, 255, 0), (S//2, S//2), 2)
|
||
|
||
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()
|
||
|
||
|
||
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()
|