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

55 lines
1.4 KiB
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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