les pouVOAR!!1
This commit is contained in:
parent
9dac58f8bd
commit
4214c5819c
BIN
res/lvl0.png
BIN
res/lvl0.png
Binary file not shown.
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 20 KiB |
BIN
res/pacman_1.png
BIN
res/pacman_1.png
Binary file not shown.
Before Width: | Height: | Size: 9.6 KiB After Width: | Height: | Size: 711 B |
BIN
res/pacman_2.png
BIN
res/pacman_2.png
Binary file not shown.
Before Width: | Height: | Size: 739 B After Width: | Height: | Size: 712 B |
@ -38,7 +38,7 @@ class Ghost(Entity):
|
||||
self.direction = Direction(randint(1, 4))
|
||||
|
||||
def on_col(self, c):
|
||||
if isinstance(c.parent, PacDot):
|
||||
if not c.solid:
|
||||
return
|
||||
|
||||
if c.parent.name == 'pacman':
|
||||
|
@ -9,7 +9,7 @@ from engine.components.collide_rect import CollideRect
|
||||
from engine.components.sprite import Sprite
|
||||
|
||||
from .common import S
|
||||
from .pacdot import PacDot
|
||||
from .pacdot import PacDot, EnsmallmentDot
|
||||
|
||||
|
||||
class Level(Entity):
|
||||
@ -36,4 +36,9 @@ class Level(Entity):
|
||||
pc.y = y * S
|
||||
self.scene.add(pc)
|
||||
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))
|
||||
|
@ -5,13 +5,12 @@ 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)
|
||||
draw.circle(s, (255, 255, 0), (S//2, S//2), 2)
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(self.__repr__())
|
||||
@ -32,3 +31,24 @@ class PacDot(Entity):
|
||||
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()
|
||||
|
@ -8,24 +8,24 @@ from engine.components.collide_rect import CollideRect
|
||||
from engine.components.sprite import Sprite
|
||||
|
||||
from .common import S
|
||||
from .pacdot import EnsmallmentDot
|
||||
|
||||
|
||||
class PacMan(Entity):
|
||||
SIZE = 1
|
||||
SPEED = 2
|
||||
|
||||
def __init__(self, x, y):
|
||||
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_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),
|
||||
transform.rotate(surf_1, -90),
|
||||
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.phys = self.add(
|
||||
CollideRect(Rect(self.x, self.y,
|
||||
self.sprite.width, self.sprite.width),
|
||||
static=False))
|
||||
self.smol_rect = Rect(self.x, self.y,
|
||||
self.sprite.width//2, self.sprite.width//2)
|
||||
self.rect = Rect(self.x, self.y,
|
||||
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.x = x
|
||||
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):
|
||||
p = self.phys
|
||||
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 l’animation
|
||||
if Game.cur_tick % 5 == 0:
|
||||
self.cur_anim += 1
|
||||
@ -66,8 +97,11 @@ class PacMan(Entity):
|
||||
elif p.vx > 0:
|
||||
s.surf = self.surf[self.cur_anim][3]
|
||||
|
||||
if self.smol:
|
||||
s.surf = self.smol_surf
|
||||
|
||||
inputs = key.get_pressed()
|
||||
if PacMan.SIZE > 1:
|
||||
if self.smol:
|
||||
p.vx = 0
|
||||
p.vy = 0
|
||||
if inputs[K_UP]:
|
||||
|
Reference in New Issue
Block a user