This repository has been archived on 2019-12-09. You can view files and clone it, but cannot push or open issues or pull requests.
pacman2/scenes/game_objects/pacdot.py

35 lines
899 B
Python
Raw Normal View History

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
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()