les pouVOAR!!1

This commit is contained in:
papush! 2019-12-09 13:21:33 +01:00
parent 9dac58f8bd
commit 4214c5819c
7 changed files with 76 additions and 17 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.6 KiB

After

Width:  |  Height:  |  Size: 711 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 739 B

After

Width:  |  Height:  |  Size: 712 B

View File

@ -38,7 +38,7 @@ class Ghost(Entity):
self.direction = Direction(randint(1, 4)) self.direction = Direction(randint(1, 4))
def on_col(self, c): def on_col(self, c):
if isinstance(c.parent, PacDot): if not c.solid:
return return
if c.parent.name == 'pacman': if c.parent.name == 'pacman':

View File

@ -9,7 +9,7 @@ from engine.components.collide_rect import CollideRect
from engine.components.sprite import Sprite from engine.components.sprite import Sprite
from .common import S from .common import S
from .pacdot import PacDot from .pacdot import PacDot, EnsmallmentDot
class Level(Entity): class Level(Entity):
@ -36,4 +36,9 @@ class Level(Entity):
pc.y = y * S pc.y = y * S
self.scene.add(pc) self.scene.add(pc)
PacDot.tot += 1 PacDot.tot += 1
elif col == (193, 193, 193):
pc = EnsmallmentDot()
pc.x = x * S
pc.y = y * S
self.scene.add(pc)
self.add(Sprite(self.surf, 0)) self.add(Sprite(self.surf, 0))

View File

@ -5,13 +5,12 @@ from engine.components.collide_rect import CollideRect
from engine.components.sprite import Sprite from engine.components.sprite import Sprite
from .common import S from .common import S
from .pacman import PacMan
class PacDot(Entity): class PacDot(Entity):
tot = 0 tot = 0
s = Surface((S, S)) s = Surface((S, S))
draw.circle(s, (255, 255, 0), (S//2, S//2), S//4) draw.circle(s, (255, 255, 0), (S//2, S//2), 2)
def __init__(self): def __init__(self):
super().__init__(self.__repr__()) super().__init__(self.__repr__())
@ -32,3 +31,24 @@ class PacDot(Entity):
exit(0) exit(0)
if c.parent.name == 'pacman': if c.parent.name == 'pacman':
self.unregister() 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()

View File

@ -8,24 +8,24 @@ from engine.components.collide_rect import CollideRect
from engine.components.sprite import Sprite from engine.components.sprite import Sprite
from .common import S from .common import S
from .pacdot import EnsmallmentDot
class PacMan(Entity): class PacMan(Entity):
SIZE = 1
SPEED = 2 SPEED = 2
def __init__(self, x, y): def __init__(self, x, y):
super().__init__('pacman') super().__init__('pacman')
# surf = Surface((S//PacMan.SIZE, S//PacMan.SIZE)).convert()
# surf.fill((0, 0, 0))
# draw.circle(surf,
# (255, 255, 0),
# (S//(2*PacMan.SIZE), S//(2*PacMan.SIZE)),
# S//(2*PacMan.SIZE))
surf_1 = image.load(res('pacman_1.png')).convert() surf_1 = image.load(res('pacman_1.png')).convert()
surf_2 = image.load(res('pacman_2.png')).convert() surf_2 = image.load(res('pacman_2.png')).convert()
self.smol_surf = Surface((S//2, S//2)).convert()
self.smol_surf.fill((0, 0, 0))
draw.circle(self.smol_surf,
(255, 255, 0),
(S//4, S//4),
S//4)
self.surf = [[transform.rotate(surf_1, 90), self.surf = [[transform.rotate(surf_1, 90),
transform.rotate(surf_1, -90), transform.rotate(surf_1, -90),
transform.flip(surf_1, True, False), transform.flip(surf_1, True, False),
@ -39,18 +39,49 @@ class PacMan(Entity):
self.sprite = self.add(Sprite(self.surf[self.cur_anim][0], 2)) self.sprite = self.add(Sprite(self.surf[self.cur_anim][0], 2))
self.phys = self.add( self.smol_rect = Rect(self.x, self.y,
CollideRect(Rect(self.x, self.y, self.sprite.width//2, self.sprite.width//2)
self.sprite.width, self.sprite.width), self.rect = Rect(self.x, self.y,
static=False)) self.sprite.width, self.sprite.width)
self.phys = CollideRect(self.rect,
static=False,
cb=self.cb)
self.add(self.phys)
self.script = PacMan.update self.script = PacMan.update
self.x = x self.x = x
self.y = y self.y = y
self.smol = False
self.smol_since = None
def cb(self, c):
if not isinstance(c.parent, EnsmallmentDot):
return
if not self.smol:
self.x += S//4
self.y += S//4
PacMan.SPEED *= 2
self.smol_rect.x = self.x
self.smol_rect.y = self.y
self.phys.rect = self.smol_rect
self.smol = True
self.smol_since = Game.cur_tick
def update(self): def update(self):
p = self.phys p = self.phys
s = self.sprite s = self.sprite
# Expiration du pouvoir
if self.smol and Game.cur_tick - self.smol_since > 60*2:
self.x -= self.x % S
self.y -= self.y % S
self.rect.x = self.x
self.rect.y = self.y
self.phys.rect = self.rect
self.smol = False
PacMan.SPEED = PacMan.SPEED//2
# Avance lanimation # Avance lanimation
if Game.cur_tick % 5 == 0: if Game.cur_tick % 5 == 0:
self.cur_anim += 1 self.cur_anim += 1
@ -66,8 +97,11 @@ class PacMan(Entity):
elif p.vx > 0: elif p.vx > 0:
s.surf = self.surf[self.cur_anim][3] s.surf = self.surf[self.cur_anim][3]
if self.smol:
s.surf = self.smol_surf
inputs = key.get_pressed() inputs = key.get_pressed()
if PacMan.SIZE > 1: if self.smol:
p.vx = 0 p.vx = 0
p.vy = 0 p.vy = 0
if inputs[K_UP]: if inputs[K_UP]: