diff --git a/assets/textures/big.png b/assets/textures/big.png new file mode 100644 index 0000000..c725054 Binary files /dev/null and b/assets/textures/big.png differ diff --git a/assets/textures/countdown/0000.png b/assets/textures/countdown/0000.png deleted file mode 100644 index b374577..0000000 Binary files a/assets/textures/countdown/0000.png and /dev/null differ diff --git a/assets/textures/countdown/0001.png b/assets/textures/countdown/0001.png deleted file mode 100644 index 7d03e8e..0000000 Binary files a/assets/textures/countdown/0001.png and /dev/null differ diff --git a/assets/textures/countdown/0002.png b/assets/textures/countdown/0002.png deleted file mode 100644 index 26611c1..0000000 Binary files a/assets/textures/countdown/0002.png and /dev/null differ diff --git a/assets/textures/countdown/0003.png b/assets/textures/countdown/0003.png deleted file mode 100644 index f506505..0000000 Binary files a/assets/textures/countdown/0003.png and /dev/null differ diff --git a/assets/textures/countdown/0004.png b/assets/textures/countdown/0004.png deleted file mode 100644 index de697a2..0000000 Binary files a/assets/textures/countdown/0004.png and /dev/null differ diff --git a/assets/textures/countdown/0005.png b/assets/textures/countdown/0005.png deleted file mode 100644 index 23c0b69..0000000 Binary files a/assets/textures/countdown/0005.png and /dev/null differ diff --git a/assets/textures/countdown/0006.png b/assets/textures/countdown/0006.png deleted file mode 100644 index ee76d44..0000000 Binary files a/assets/textures/countdown/0006.png and /dev/null differ diff --git a/assets/textures/countdown/0007.png b/assets/textures/countdown/0007.png deleted file mode 100644 index f12e3ee..0000000 Binary files a/assets/textures/countdown/0007.png and /dev/null differ diff --git a/assets/textures/countdown/0008.png b/assets/textures/countdown/0008.png deleted file mode 100644 index a2df483..0000000 Binary files a/assets/textures/countdown/0008.png and /dev/null differ diff --git a/assets/textures/countdown/0009.png b/assets/textures/countdown/0009.png deleted file mode 100644 index 08c1d9a..0000000 Binary files a/assets/textures/countdown/0009.png and /dev/null differ diff --git a/assets/textures/countdown/0010.png b/assets/textures/countdown/0010.png deleted file mode 100644 index ce60514..0000000 Binary files a/assets/textures/countdown/0010.png and /dev/null differ diff --git a/assets/textures/countdown/0011.png b/assets/textures/countdown/0011.png deleted file mode 100644 index 34fdb5f..0000000 Binary files a/assets/textures/countdown/0011.png and /dev/null differ diff --git a/assets/textures/countdown/0012.png b/assets/textures/countdown/0012.png deleted file mode 100644 index 318f585..0000000 Binary files a/assets/textures/countdown/0012.png and /dev/null differ diff --git a/assets/textures/countdown/0013.png b/assets/textures/countdown/0013.png deleted file mode 100644 index 576e8f0..0000000 Binary files a/assets/textures/countdown/0013.png and /dev/null differ diff --git a/assets/textures/countdown/0014.png b/assets/textures/countdown/0014.png deleted file mode 100644 index aac16a0..0000000 Binary files a/assets/textures/countdown/0014.png and /dev/null differ diff --git a/assets/textures/countdown/0015.png b/assets/textures/countdown/0015.png deleted file mode 100644 index d8e328a..0000000 Binary files a/assets/textures/countdown/0015.png and /dev/null differ diff --git a/assets/textures/countdown/0016.png b/assets/textures/countdown/0016.png deleted file mode 100644 index 400d741..0000000 Binary files a/assets/textures/countdown/0016.png and /dev/null differ diff --git a/assets/textures/countdown/0017.png b/assets/textures/countdown/0017.png deleted file mode 100644 index ea854c2..0000000 Binary files a/assets/textures/countdown/0017.png and /dev/null differ diff --git a/assets/textures/countdown/0018.png b/assets/textures/countdown/0018.png deleted file mode 100644 index 21f5679..0000000 Binary files a/assets/textures/countdown/0018.png and /dev/null differ diff --git a/assets/textures/countdown/0019.png b/assets/textures/countdown/0019.png deleted file mode 100644 index d0d5592..0000000 Binary files a/assets/textures/countdown/0019.png and /dev/null differ diff --git a/assets/textures/countdown/0020.png b/assets/textures/countdown/0020.png deleted file mode 100644 index 46835fb..0000000 Binary files a/assets/textures/countdown/0020.png and /dev/null differ diff --git a/assets/textures/countdown/0021.png b/assets/textures/countdown/0021.png deleted file mode 100644 index 664e21b..0000000 Binary files a/assets/textures/countdown/0021.png and /dev/null differ diff --git a/assets/textures/countdown/0022.png b/assets/textures/countdown/0022.png deleted file mode 100644 index 1a50fa9..0000000 Binary files a/assets/textures/countdown/0022.png and /dev/null differ diff --git a/assets/textures/countdown/0023.png b/assets/textures/countdown/0023.png deleted file mode 100644 index 2f37edc..0000000 Binary files a/assets/textures/countdown/0023.png and /dev/null differ diff --git a/assets/textures/countdown/0024.png b/assets/textures/countdown/0024.png deleted file mode 100644 index e469427..0000000 Binary files a/assets/textures/countdown/0024.png and /dev/null differ diff --git a/assets/textures/countdown/0025.png b/assets/textures/countdown/0025.png deleted file mode 100644 index 91e478d..0000000 Binary files a/assets/textures/countdown/0025.png and /dev/null differ diff --git a/assets/textures/countdown/0026.png b/assets/textures/countdown/0026.png deleted file mode 100644 index 0b422c8..0000000 Binary files a/assets/textures/countdown/0026.png and /dev/null differ diff --git a/assets/textures/countdown/0027.png b/assets/textures/countdown/0027.png deleted file mode 100644 index c48e4b6..0000000 Binary files a/assets/textures/countdown/0027.png and /dev/null differ diff --git a/assets/textures/countdown/0028.png b/assets/textures/countdown/0028.png deleted file mode 100644 index b475963..0000000 Binary files a/assets/textures/countdown/0028.png and /dev/null differ diff --git a/assets/textures/countdown/0029.png b/assets/textures/countdown/0029.png deleted file mode 100644 index 11403da..0000000 Binary files a/assets/textures/countdown/0029.png and /dev/null differ diff --git a/assets/textures/countdown/0030.png b/assets/textures/countdown/0030.png deleted file mode 100644 index 24e100e..0000000 Binary files a/assets/textures/countdown/0030.png and /dev/null differ diff --git a/assets/textures/countdown/0031.png b/assets/textures/countdown/0031.png deleted file mode 100644 index 0ac880f..0000000 Binary files a/assets/textures/countdown/0031.png and /dev/null differ diff --git a/assets/textures/countdown/0032.png b/assets/textures/countdown/0032.png deleted file mode 100644 index 21dff67..0000000 Binary files a/assets/textures/countdown/0032.png and /dev/null differ diff --git a/assets/textures/countdown/0033.png b/assets/textures/countdown/0033.png deleted file mode 100644 index 38b6279..0000000 Binary files a/assets/textures/countdown/0033.png and /dev/null differ diff --git a/assets/textures/countdown/0034.png b/assets/textures/countdown/0034.png deleted file mode 100644 index fad49b5..0000000 Binary files a/assets/textures/countdown/0034.png and /dev/null differ diff --git a/assets/textures/countdown/0035.png b/assets/textures/countdown/0035.png deleted file mode 100644 index 138eeb7..0000000 Binary files a/assets/textures/countdown/0035.png and /dev/null differ diff --git a/assets/textures/countdown/0036.png b/assets/textures/countdown/0036.png deleted file mode 100644 index 7f5f6e4..0000000 Binary files a/assets/textures/countdown/0036.png and /dev/null differ diff --git a/assets/textures/countdown/0037.png b/assets/textures/countdown/0037.png deleted file mode 100644 index 4bcc7dc..0000000 Binary files a/assets/textures/countdown/0037.png and /dev/null differ diff --git a/assets/textures/countdown/0038.png b/assets/textures/countdown/0038.png deleted file mode 100644 index c293853..0000000 Binary files a/assets/textures/countdown/0038.png and /dev/null differ diff --git a/assets/textures/countdown/0039.png b/assets/textures/countdown/0039.png deleted file mode 100644 index aa3c042..0000000 Binary files a/assets/textures/countdown/0039.png and /dev/null differ diff --git a/assets/textures/countdown/0040.png b/assets/textures/countdown/0040.png deleted file mode 100644 index 930d512..0000000 Binary files a/assets/textures/countdown/0040.png and /dev/null differ diff --git a/assets/textures/countdown/0041.png b/assets/textures/countdown/0041.png deleted file mode 100644 index ee895f8..0000000 Binary files a/assets/textures/countdown/0041.png and /dev/null differ diff --git a/assets/textures/countdown/0042.png b/assets/textures/countdown/0042.png deleted file mode 100644 index 618bbba..0000000 Binary files a/assets/textures/countdown/0042.png and /dev/null differ diff --git a/assets/textures/countdown/0043.png b/assets/textures/countdown/0043.png deleted file mode 100644 index e41df04..0000000 Binary files a/assets/textures/countdown/0043.png and /dev/null differ diff --git a/assets/textures/countdown/0044.png b/assets/textures/countdown/0044.png deleted file mode 100644 index e6eda8b..0000000 Binary files a/assets/textures/countdown/0044.png and /dev/null differ diff --git a/assets/textures/countdown/0045.png b/assets/textures/countdown/0045.png deleted file mode 100644 index ac230c0..0000000 Binary files a/assets/textures/countdown/0045.png and /dev/null differ diff --git a/assets/textures/countdown/0046.png b/assets/textures/countdown/0046.png deleted file mode 100644 index ab1877b..0000000 Binary files a/assets/textures/countdown/0046.png and /dev/null differ diff --git a/assets/textures/countdown/0047.png b/assets/textures/countdown/0047.png deleted file mode 100644 index 507ad25..0000000 Binary files a/assets/textures/countdown/0047.png and /dev/null differ diff --git a/assets/textures/countdown/0048.png b/assets/textures/countdown/0048.png deleted file mode 100644 index f4da5fa..0000000 Binary files a/assets/textures/countdown/0048.png and /dev/null differ diff --git a/assets/textures/countdown/0049.png b/assets/textures/countdown/0049.png deleted file mode 100644 index e8810b6..0000000 Binary files a/assets/textures/countdown/0049.png and /dev/null differ diff --git a/assets/textures/countdown/0050.png b/assets/textures/countdown/0050.png deleted file mode 100644 index c0f25b0..0000000 Binary files a/assets/textures/countdown/0050.png and /dev/null differ diff --git a/assets/textures/countdown/0051.png b/assets/textures/countdown/0051.png deleted file mode 100644 index 0927806..0000000 Binary files a/assets/textures/countdown/0051.png and /dev/null differ diff --git a/assets/textures/countdown/0052.png b/assets/textures/countdown/0052.png deleted file mode 100644 index dc3ab5e..0000000 Binary files a/assets/textures/countdown/0052.png and /dev/null differ diff --git a/assets/textures/countdown/0053.png b/assets/textures/countdown/0053.png deleted file mode 100644 index 17ad460..0000000 Binary files a/assets/textures/countdown/0053.png and /dev/null differ diff --git a/assets/textures/countdown/0054.png b/assets/textures/countdown/0054.png deleted file mode 100644 index 1cd4289..0000000 Binary files a/assets/textures/countdown/0054.png and /dev/null differ diff --git a/assets/textures/countdown/0055.png b/assets/textures/countdown/0055.png deleted file mode 100644 index c6d4bd6..0000000 Binary files a/assets/textures/countdown/0055.png and /dev/null differ diff --git a/assets/textures/countdown/0056.png b/assets/textures/countdown/0056.png deleted file mode 100644 index 811ee03..0000000 Binary files a/assets/textures/countdown/0056.png and /dev/null differ diff --git a/assets/textures/countdown/0057.png b/assets/textures/countdown/0057.png deleted file mode 100644 index 6158595..0000000 Binary files a/assets/textures/countdown/0057.png and /dev/null differ diff --git a/assets/textures/countdown/0058.png b/assets/textures/countdown/0058.png deleted file mode 100644 index cd2be49..0000000 Binary files a/assets/textures/countdown/0058.png and /dev/null differ diff --git a/assets/textures/countdown/0059.png b/assets/textures/countdown/0059.png deleted file mode 100644 index c1351e1..0000000 Binary files a/assets/textures/countdown/0059.png and /dev/null differ diff --git a/assets/textures/countdown/0060.png b/assets/textures/countdown/0060.png deleted file mode 100644 index fe28d30..0000000 Binary files a/assets/textures/countdown/0060.png and /dev/null differ diff --git a/assets/textures/countdown/0061.png b/assets/textures/countdown/0061.png deleted file mode 100644 index 3222e20..0000000 Binary files a/assets/textures/countdown/0061.png and /dev/null differ diff --git a/assets/textures/countdown/0062.png b/assets/textures/countdown/0062.png deleted file mode 100644 index 2fec69c..0000000 Binary files a/assets/textures/countdown/0062.png and /dev/null differ diff --git a/assets/textures/countdown/0063.png b/assets/textures/countdown/0063.png deleted file mode 100644 index 24491f8..0000000 Binary files a/assets/textures/countdown/0063.png and /dev/null differ diff --git a/assets/textures/countdown/0064.png b/assets/textures/countdown/0064.png deleted file mode 100644 index 1c2a3b8..0000000 Binary files a/assets/textures/countdown/0064.png and /dev/null differ diff --git a/assets/textures/countdown/0065.png b/assets/textures/countdown/0065.png deleted file mode 100644 index 97b802b..0000000 Binary files a/assets/textures/countdown/0065.png and /dev/null differ diff --git a/assets/textures/countdown/0066.png b/assets/textures/countdown/0066.png deleted file mode 100644 index 96d4ccc..0000000 Binary files a/assets/textures/countdown/0066.png and /dev/null differ diff --git a/assets/textures/countdown/0067.png b/assets/textures/countdown/0067.png deleted file mode 100644 index 13b074c..0000000 Binary files a/assets/textures/countdown/0067.png and /dev/null differ diff --git a/assets/textures/countdown/0068.png b/assets/textures/countdown/0068.png deleted file mode 100644 index cec4db5..0000000 Binary files a/assets/textures/countdown/0068.png and /dev/null differ diff --git a/assets/textures/countdown/0069.png b/assets/textures/countdown/0069.png deleted file mode 100644 index b09ff79..0000000 Binary files a/assets/textures/countdown/0069.png and /dev/null differ diff --git a/assets/textures/countdown/0070.png b/assets/textures/countdown/0070.png deleted file mode 100644 index bd5e741..0000000 Binary files a/assets/textures/countdown/0070.png and /dev/null differ diff --git a/assets/textures/countdown/0071.png b/assets/textures/countdown/0071.png deleted file mode 100644 index 50a5258..0000000 Binary files a/assets/textures/countdown/0071.png and /dev/null differ diff --git a/assets/textures/countdown/0072.png b/assets/textures/countdown/0072.png deleted file mode 100644 index 98cf67e..0000000 Binary files a/assets/textures/countdown/0072.png and /dev/null differ diff --git a/assets/textures/countdown/0073.png b/assets/textures/countdown/0073.png deleted file mode 100644 index c0d356d..0000000 Binary files a/assets/textures/countdown/0073.png and /dev/null differ diff --git a/assets/textures/countdown/0074.png b/assets/textures/countdown/0074.png deleted file mode 100644 index c9033c2..0000000 Binary files a/assets/textures/countdown/0074.png and /dev/null differ diff --git a/assets/textures/countdown/0075.png b/assets/textures/countdown/0075.png deleted file mode 100644 index b07cd93..0000000 Binary files a/assets/textures/countdown/0075.png and /dev/null differ diff --git a/assets/textures/countdown/0076.png b/assets/textures/countdown/0076.png deleted file mode 100644 index 953d887..0000000 Binary files a/assets/textures/countdown/0076.png and /dev/null differ diff --git a/assets/textures/countdown/0077.png b/assets/textures/countdown/0077.png deleted file mode 100644 index e1ccb51..0000000 Binary files a/assets/textures/countdown/0077.png and /dev/null differ diff --git a/assets/textures/countdown/0078.png b/assets/textures/countdown/0078.png deleted file mode 100644 index 7b24257..0000000 Binary files a/assets/textures/countdown/0078.png and /dev/null differ diff --git a/assets/textures/countdown/0079.png b/assets/textures/countdown/0079.png deleted file mode 100644 index d8e3074..0000000 Binary files a/assets/textures/countdown/0079.png and /dev/null differ diff --git a/assets/textures/countdown/0080.png b/assets/textures/countdown/0080.png deleted file mode 100644 index a5f3857..0000000 Binary files a/assets/textures/countdown/0080.png and /dev/null differ diff --git a/assets/textures/countdown/0081.png b/assets/textures/countdown/0081.png deleted file mode 100644 index 3b089b8..0000000 Binary files a/assets/textures/countdown/0081.png and /dev/null differ diff --git a/assets/textures/countdown/0082.png b/assets/textures/countdown/0082.png deleted file mode 100644 index ecf7761..0000000 Binary files a/assets/textures/countdown/0082.png and /dev/null differ diff --git a/assets/textures/countdown/0083.png b/assets/textures/countdown/0083.png deleted file mode 100644 index 288177c..0000000 Binary files a/assets/textures/countdown/0083.png and /dev/null differ diff --git a/assets/textures/fast.png b/assets/textures/fast.png new file mode 100644 index 0000000..705f2f2 Binary files /dev/null and b/assets/textures/fast.png differ diff --git a/assets/textures/multi.png b/assets/textures/multi.png new file mode 100644 index 0000000..377c212 Binary files /dev/null and b/assets/textures/multi.png differ diff --git a/assets/textures/reverse.png b/assets/textures/reverse.png new file mode 100644 index 0000000..f87a7d0 Binary files /dev/null and b/assets/textures/reverse.png differ diff --git a/src/scenes/game.py b/src/scenes/game.py index 6772dca..b31033c 100644 --- a/src/scenes/game.py +++ b/src/scenes/game.py @@ -108,6 +108,86 @@ class StartAnimation(float): """ +class TimeUntilBonus: + """ + ressource qui represente le temps restant avant d'avoir le bonus + """ + + def __init__(self, time: float, world: World): + self.time = time + self.started_time = int(world[Time]) + + def is_ended(self, world: World): + return world[Time] - self.started_time >= self.time + + def start(self, world: World): + self.started_time = world[Time] + + +class LastPlayerTurn: + """ + un composant qui represente le dernier joueur qui a joué. + """ + + +class HasBonus: + """ + un composant qui represente si l'entité a un bonus + """ + + def __init__(self, bonus: "Bonus", time: float, world: World): + self.bonus = bonus + self.time = time + + self.start_time = world[Time] + + def is_ended(self, world: World): + return world[Time] - self.start_time >= self.time + + def suppr_bonus_from_entity(self, entity: Entity): + match self.bonus: + case Bonus.MULTI: + pass + case Bonus.BIG: + entity[Scale] /= 2 + case Bonus.FAST: + entity[Speed] /= 1.5 + case Bonus.REVERSE: + entity[UpKey], entity[DownKey] = entity[DownKey], entity[UpKey] + + +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.MULTI + case 1: + return Bonus.BIG + case 2: + return Bonus.FAST + case _: + return Bonus.REVERSE + + @staticmethod + def get_texture(bonus: "Bonus"): + match bonus: + case Bonus.MULTI: + return "multi.png" + case Bonus.BIG: + return "big.png" + case Bonus.FAST: + return "fast.png" + case _: + return "reverse.png" + + def __spawn_ellements(world: World): """ La fonction permet de initializer les ellements de la scene. @@ -115,6 +195,10 @@ def __spawn_ellements(world: World): world.new_entity().set(SpriteBundle(("background.jpg"), -5)) + world.set( + TimeUntilBonus(5, world), + ) + # Mon mur de gauche world.new_entity().set( Origin(Vec2(1, 0)), @@ -165,6 +249,7 @@ def __spawn_ellements(world: World): UpKey("z"), DownKey("s"), Speed(1000), + LastPlayerTurn(), ) # Joueur 2 @@ -180,7 +265,7 @@ def __spawn_ellements(world: World): Player2(), (UpKey("up"), DownKey("down"), Speed(1000)) if world[GameMode] == GameMode.TWO - else None, + else Speed(300), ) __spawn_ball(world) @@ -200,6 +285,23 @@ def __spawn_ellements(world: World): ) +def __spawn_bonus(world: World): + bonus = Bonus.aleatoire() + world.new_entity().set( + SpriteBundle( + Bonus.get_texture(bonus), + 3, + Vec2( + random.randint(200, render.WIDTH - 200), + random.randint(100, render.HEIGHT - 100), + ), + Vec2(70), + Vec2(0.5), + ), + bonus, + ) + + def __spawn_ball(world: World): """ Fonction qui fait apparaitre une balle avec une velocitée aleatoire @@ -221,12 +323,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: + for player in a.world.query(LastPlayerTurn): + del player[LastPlayerTurn] + b.set(LastPlayerTurn()) + return __bounce_on_player(a, b) + return True + + +def __bonus_touched(ball: Entity, bonus: Entity): + player = ball.world.query(LastPlayerTurn).pop() + match bonus[Bonus]: + case Bonus.MULTI: + __spawn_ball(bonus.world) + __spawn_ball(bonus.world) + ball.world[TimeUntilBonus].start(ball.world) + case Bonus.BIG: + player[Scale] *= 2 + player.set(HasBonus(Bonus.BIG, 10, bonus.world)) + case Bonus.FAST: + player[Speed] *= 1.5 + player.set(HasBonus(Bonus.FAST, 10, bonus.world)) + case Bonus.REVERSE: + for entity in ball.world.query(UpKey): + if LastPlayerTurn in entity: + continue + entity[UpKey], entity[DownKey] = entity[DownKey], entity[UpKey] + + entity.set(HasBonus(Bonus.REVERSE, 10, bonus.world)) + + 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 @@ -368,7 +503,35 @@ def _update_bot(world: World): # On se déplace vers la meilleure option diff = target - bot[Position].y if abs(diff) > 10: - bot[Position].y += (diff / abs(diff)) * 300 * world[Delta] + bot[Position].y += (diff / abs(diff)) * bot[Speed] * world[Delta] + + +def __check_bonus_collision(world: World): + """ + Fonction qui permet de voir si un bonus est entrée en collision avec une entité. + """ + + def __collision_handler(a: Entity, b: Entity): + if Bonus in b: + __bonus_touched(a, b) + return False + return True + + for entity in world.query(Bonus): + entity.set(physics.Solid()) + for entity in world.query(Ball): + simulated_ball = world.new_entity() + simulated_ball.set( + Position(entity[Position]), + Scale(entity[Scale]), + physics.Velocity(entity[physics.Velocity]), + Origin(entity[Origin]), + physics.CollisionHandler(__collision_handler), + ) + physics.move_entity(simulated_ball, entity[physics.Velocity] * world[Delta]) + simulated_ball.destroy() + for entity in world.query(Bonus): + entity.remove(physics.Solid) def __update_scores(world: World, ball: Entity): @@ -420,9 +583,25 @@ def __update_animation(world: World): animation.destroy() +def __update_bonus_time(world: World): + """ + Fonction qui permet de mettre à jour les bonus. + """ + for player in world.query(HasBonus): + if not player[HasBonus].is_ended(world): + return None + player[HasBonus].suppr_bonus_from_entity(player) + del player[HasBonus] + world[TimeUntilBonus].start(world) + + if world.query(Bonus) == set() and world.query(HasBonus) == set(): + if world[TimeUntilBonus].is_ended(world): + __spawn_bonus(world) + + __SCENE = Scene( [__spawn_ellements], - [__update_move, __update_animation], + [__update_move, __check_bonus_collision, __update_animation, __update_bonus_time], [], )