lesajout du system de degat

This commit is contained in:
CoCo_Sol 2023-11-04 03:01:33 +01:00
parent 6eb223c9b2
commit 5baa8bf2af

View file

@ -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",
)