Ajout des bonus #6
|
@ -3,6 +3,7 @@ Le jeux principale.
|
|||
"""
|
||||
|
||||
from enum import Enum
|
||||
from telnetlib import DO
|
||||
from engine import Plugin, Scene
|
||||
from engine.ecs import Entity, World
|
||||
from engine.math import Vec2
|
||||
|
@ -108,6 +109,26 @@ class StartAnimation(float):
|
|||
"""
|
||||
|
||||
|
||||
class Bonus(Enum):
|
||||
MULTI = 0
|
||||
BIG = 1
|
||||
FAST = 2
|
||||
REVERSE = 3
|
||||
|
||||
@staticmethod
|
||||
def aleatoire():
|
||||
type = random.randint(0, 3)
|
||||
match type:
|
||||
case 0:
|
||||
return Bonus.FAST
|
||||
case 1:
|
||||
return Bonus.FAST
|
||||
case 2:
|
||||
return Bonus.FAST
|
||||
case _:
|
||||
return Bonus.FAST
|
||||
|
||||
|
||||
def __spawn_ellements(world: World):
|
||||
"""
|
||||
La fonction permet de initializer les ellements de la scene.
|
||||
|
@ -184,6 +205,7 @@ def __spawn_ellements(world: World):
|
|||
)
|
||||
|
||||
__spawn_ball(world)
|
||||
__spawn_bonus(world)
|
||||
|
||||
# Initialisation des scores
|
||||
world.set(Player1Score(0), Player2Score(0))
|
||||
|
@ -200,6 +222,23 @@ def __spawn_ellements(world: World):
|
|||
)
|
||||
|
||||
|
||||
def __spawn_bonus(world: World):
|
||||
world.new_entity().set(
|
||||
SpriteBundle(
|
||||
"player_1.png",
|
||||
3,
|
||||
Vec2(
|
||||
random.randint(200, render.WIDTH - 200),
|
||||
random.randint(100, render.HEIGHT - 100),
|
||||
),
|
||||
Vec2(100),
|
||||
Vec2(0.5),
|
||||
),
|
||||
physics.Solid(),
|
||||
Bonus.aleatoire(),
|
||||
)
|
||||
|
||||
|
||||
def __spawn_ball(world: World):
|
||||
"""
|
||||
Fonction qui fait apparaitre une balle avec une velocitée aleatoire
|
||||
|
@ -221,12 +260,45 @@ def __spawn_ball(world: World):
|
|||
Vec2(0.5),
|
||||
),
|
||||
Ball(),
|
||||
#
|
||||
physics.Velocity(velocity),
|
||||
physics.CollisionHandler(__bounce_on_player),
|
||||
physics.CollisionHandler(__collision_with_ball),
|
||||
)
|
||||
|
||||
|
||||
def __collision_with_ball(a: Entity, b: Entity):
|
||||
if Player1 in b or Player2 in b:
|
||||
return __bounce_on_player(a, b)
|
||||
elif Bonus in b:
|
||||
return __bonus_touched(a, b)
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def __bonus_touched(ball: Entity, bonus: Entity):
|
||||
if ball[physics.Velocity].x > 0:
|
||||
player = ball.world.query(Player1).pop()
|
||||
else:
|
||||
player = ball.world.query(Player2).pop()
|
||||
match bonus[Bonus]:
|
||||
case Bonus.MULTI:
|
||||
__spawn_ball(bonus.world)
|
||||
__spawn_ball(bonus.world)
|
||||
case Bonus.BIG:
|
||||
player[Scale] *= 2
|
||||
case Bonus.FAST:
|
||||
player[Speed] *= 2
|
||||
case Bonus.REVERSE:
|
||||
if ball[physics.Velocity].x < 0:
|
||||
player = ball.world.query(Player1).pop()
|
||||
player[UpKey], player[DownKey] = player[DownKey], player[UpKey]
|
||||
else:
|
||||
player = ball.world.query(Player2).pop()
|
||||
player[UpKey], player[DownKey] = player[DownKey], player[UpKey]
|
||||
|
||||
bonus.destroy()
|
||||
return False
|
||||
|
||||
|
||||
def __bounce_on_player(a: Entity, b: Entity):
|
||||
"""
|
||||
Fonction qui decrit se qui se passe lorque la ball entre en collision avec un joueur
|
||||
|
|
Loading…
Reference in a new issue