From 5baa8bf2af31981666ac6a7a180fa1b81076a284 Mon Sep 17 00:00:00 2001 From: CoCo_Sol Date: Sat, 4 Nov 2023 03:01:33 +0100 Subject: [PATCH] lesajout du system de degat --- src/scenes/story/boss_fight.py | 75 ++++++++++++++++++++++++++++++---- 1 file changed, 67 insertions(+), 8 deletions(-) diff --git a/src/scenes/story/boss_fight.py b/src/scenes/story/boss_fight.py index 7571770..2d2eb47 100644 --- a/src/scenes/story/boss_fight.py +++ b/src/scenes/story/boss_fight.py @@ -2,11 +2,13 @@ Scene de Combat final contre edmond, inspiré du combat d'omega flowey dans undertale """ +from enum import Enum import random -from engine import Plugin + +from engine import Scene from engine.ecs import World from engine.math import Vec2 -from plugins import assets +from plugins import assets, smooth from plugins import render from plugins.animation import Animation from plugins.inputs import Held, Pressed @@ -45,15 +47,37 @@ class ZoneAttack: """ -class Life: +class Life(int): """ Ressource qui correspond a la vie du joueur """ +class Hurt: + """ + Definit le composant marquant les entitées pouvant infligé des degats + + *Parametres -> Degats + """ + + def __init__(self, damage: float) -> None: + self.damage = damage + + +class Hurtable(Enum): + """ + Definit une ressource qui nous dit si l'on peut se faire toucher + """ + + TRUE = 0 + FALSE = 1 + + def __initialize_world(world: World): world.set(ShieldPos(Vec2(render.WIDTH / 2, 750))) world.set(FightBox()) + world.set(Life(100)) + world.set(Hurtable.TRUE) world.new_entity().set(Sprite(world[Assets].get_texture("background"))) @@ -64,7 +88,8 @@ def __initialize_world(world: World): 1, origin=Vec2(0.5), ), - Velocity(4), + smooth.Target(world[ShieldPos]), + Velocity(10), ) @@ -86,11 +111,42 @@ def __move(world: World): if s_pos.x + 37 + entity[Velocity] < world[FightBox].p2[0]: s_pos.x += entity[Velocity] + entity.set(smooth.Target(s_pos)) + + +def __set_hurtable_hurt(world: World): + world.set(Hurtable.FALSE) + yield wait(2) + world.set(Hurtable.TRUE) + + +def __check_hurt(world: World): + if world[Hurtable] == Hurtable.TRUE: + for entity in world.query(Hurt, Sprite): + position = entity.get(Sprite).position + width, height = entity.get(Sprite).texture.get_size() + + for shield in world.query(Velocity, Sprite): + shield_position = shield.get(Sprite).position + shield_width, shield_height = shield.get(Sprite).texture.get_size() + + is_collision = not ( + shield_position.y < position.y + or shield_position.y + shield_height > position.y + height + or shield_position.x < position.x + or shield_position.x + shield_width > position.x + width + ) + if is_collision: + world.set(Life(world.get(Life) - entity.get(Hurt).damage)) + print(world.get(Life)) + entity.remove(Hurt) + entity.destroy() + world.new_entity().set(Coroutine(__set_hurtable_hurt(world))) + def __create_zone_attack(world: World): double = random.randint(1, 10) locate = random.randint(0, 2) - print(locate, double) if double != 10: world.new_entity().set( Sprite( @@ -98,6 +154,7 @@ def __create_zone_attack(world: World): Vec2((locate * 413) + world[FightBox].p1[0], world[FightBox].p1[1]), 1, ), + Hurt(10), Animation("zone_attack", 60), ZoneAttack(), ) @@ -116,6 +173,7 @@ def __create_zone_attack(world: World): ), 1, ), + Hurt(10), Animation("zone_attack", 60), ZoneAttack(), ) @@ -134,10 +192,11 @@ def __check_key_pressed(world: World): SCENE = assets.loading_scene( - Plugin( + Scene( [__initialize_world], - [__move, __check_key_pressed], + [__move, __check_key_pressed, __check_hurt], [], - ), + ) + + smooth.PLUGIN, "story/boss_fight", )