Marche pas
This commit is contained in:
parent
57fbee1271
commit
0d0ee0dbc1
|
@ -8,7 +8,7 @@ import random
|
||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
from engine import CurrentScene, Scene
|
from engine import CurrentScene, Scene
|
||||||
from engine.ecs import World
|
from engine.ecs import Entity, World
|
||||||
from engine.math import Vec2
|
from engine.math import Vec2
|
||||||
from plugins import assets, smooth
|
from plugins import assets, smooth
|
||||||
from plugins import render
|
from plugins import render
|
||||||
|
@ -16,7 +16,7 @@ from plugins.animation import Animation
|
||||||
from plugins.inputs import Held, Pressed
|
from plugins.inputs import Held, Pressed
|
||||||
from plugins.render import Sprite
|
from plugins.render import Sprite
|
||||||
from plugins.assets import Assets
|
from plugins.assets import Assets
|
||||||
from plugins.coroutine import wait, Coroutine
|
from plugins.coroutine import condition, wait, Coroutine
|
||||||
from plugins.timing import Delta, TimedEvent
|
from plugins.timing import Delta, TimedEvent
|
||||||
|
|
||||||
|
|
||||||
|
@ -117,35 +117,18 @@ class Wave:
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.wave_list = [
|
self.wave_list = [
|
||||||
["__rainning_projectiles", "__create_zone_attack"],
|
["rainning"],
|
||||||
["__rainning_projectiles", "__horizontal_projectile"],
|
["horizontal_left"],
|
||||||
[
|
["rainning", "horizontal_left"],
|
||||||
"__rainning_projectiles",
|
["rainning", "horizontal_right"],
|
||||||
"__rainning_projectiles",
|
["rainning", "horizontal_left", "horizontal_right"],
|
||||||
"__create_zone_attack",
|
["rainning", "zones"],
|
||||||
],
|
["rainning", "horizontal_left"],
|
||||||
[
|
["rainning", "spikes"],
|
||||||
"__rainning_projectiles",
|
["rainning", "horizontal", "zones"],
|
||||||
"__rainning_projectiles",
|
["rainning", "spikes", "zones"],
|
||||||
"__horizontal_projectile",
|
["rainning", "horizontal", "zones"],
|
||||||
"__create_zone_attack",
|
["rainning", "spikes", "zones"],
|
||||||
],
|
|
||||||
[
|
|
||||||
"__rainning_projectiles",
|
|
||||||
"__create_spike",
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"__rainning_projectiles",
|
|
||||||
"__rainning_projectiles",
|
|
||||||
"__create_spike",
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"__rainning_projectiles",
|
|
||||||
"__rainning_projectiles",
|
|
||||||
"__create_spike",
|
|
||||||
"__create_zone_attack",
|
|
||||||
],
|
|
||||||
[30.0], # Definit le temps de chaque vague
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -177,7 +160,7 @@ def __initialize_world(world: World):
|
||||||
Sprite(
|
Sprite(
|
||||||
world[Assets].get_texture("shield"),
|
world[Assets].get_texture("shield"),
|
||||||
Vec2(world[ShieldPos]),
|
Vec2(world[ShieldPos]),
|
||||||
1,
|
100,
|
||||||
origin=Vec2(0.5),
|
origin=Vec2(0.5),
|
||||||
),
|
),
|
||||||
smooth.Target(world[ShieldPos]),
|
smooth.Target(world[ShieldPos]),
|
||||||
|
@ -189,17 +172,17 @@ def __initialize_world(world: World):
|
||||||
Sprite(
|
Sprite(
|
||||||
world[Assets].get_texture("barre_de_vie"),
|
world[Assets].get_texture("barre_de_vie"),
|
||||||
Vec2(100, 980),
|
Vec2(100, 980),
|
||||||
5,
|
15,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
surface_carre = pygame.Surface((1240 * world[Life] / 100, 50))
|
surface_carre = pygame.Surface((1240 * world[Life] / 100, 50))
|
||||||
surface_carre.fill((42, 161, 245))
|
surface_carre.fill((42, 161, 245))
|
||||||
world.new_entity().set(Sprite(surface_carre, Vec2(100, 980), 4), LifeBar())
|
world.new_entity().set(Sprite(surface_carre, Vec2(100, 980), 14), LifeBar())
|
||||||
|
|
||||||
surface_carre = pygame.Surface((1240, 50))
|
surface_carre = pygame.Surface((1240, 50))
|
||||||
surface_carre.fill((255, 225, 225))
|
surface_carre.fill((255, 225, 225))
|
||||||
world.new_entity().set(Sprite(surface_carre, Vec2(100, 980), 3))
|
world.new_entity().set(Sprite(surface_carre, Vec2(100, 980), 13))
|
||||||
|
|
||||||
|
|
||||||
def __move(world: World):
|
def __move(world: World):
|
||||||
|
@ -300,6 +283,8 @@ def __check_hurt(world: World):
|
||||||
text = "left"
|
text = "left"
|
||||||
case Spike.RIGHT:
|
case Spike.RIGHT:
|
||||||
text = "right"
|
text = "right"
|
||||||
|
case _:
|
||||||
|
continue
|
||||||
entity.set(
|
entity.set(
|
||||||
Animation(
|
Animation(
|
||||||
"spike/spike_" + text + "_leaving",
|
"spike/spike_" + text + "_leaving",
|
||||||
|
@ -330,44 +315,51 @@ class AWave:
|
||||||
|
|
||||||
|
|
||||||
def __wave(world: World):
|
def __wave(world: World):
|
||||||
|
entities: list[Entity] = []
|
||||||
for i, actuel_wave in enumerate(world[Wave].wave_list):
|
for i, actuel_wave in enumerate(world[Wave].wave_list):
|
||||||
print("vague n°" + str(i))
|
print("vague n°" + str(i))
|
||||||
for i, fonction in enumerate(actuel_wave):
|
for i, fonction in enumerate(actuel_wave):
|
||||||
match fonction:
|
match fonction:
|
||||||
case "__rainning_projectiles":
|
case "rainning":
|
||||||
world.new_entity().set(
|
entity = world.new_entity()
|
||||||
AWave(), Coroutine(__rainning_projectiles(world))
|
entities.append(entity)
|
||||||
)
|
entity.set(AWave(), Coroutine(__rainning_projectiles(world)))
|
||||||
case "__create_zone_attack":
|
case "zones":
|
||||||
world.new_entity().set(
|
entity = world.new_entity()
|
||||||
AWave(), Coroutine(__create_zone_attack(world))
|
entities.append(entity)
|
||||||
|
entity.set(AWave(), Coroutine(__create_zone_attack(world)))
|
||||||
|
|
||||||
|
case "spikes":
|
||||||
|
entity = world.new_entity()
|
||||||
|
entities.append(entity)
|
||||||
|
entity.set(AWave(), Coroutine(__create_spike(world)))
|
||||||
|
|
||||||
|
case "horizontal_left":
|
||||||
|
entity = world.new_entity()
|
||||||
|
entities.append(entity)
|
||||||
|
entity.set(AWave(), Coroutine(__horizontal_projectile(world, True)))
|
||||||
|
|
||||||
|
case "horizontal_right":
|
||||||
|
entity = world.new_entity()
|
||||||
|
entities.append(entity)
|
||||||
|
entity.set(
|
||||||
|
AWave(), Coroutine(__horizontal_projectile(world, False))
|
||||||
)
|
)
|
||||||
|
|
||||||
case "__create_spike":
|
|
||||||
world.new_entity().set(AWave(), Coroutine(__create_spike(world)))
|
|
||||||
|
|
||||||
case "__horizontal_projectile":
|
|
||||||
world.new_entity().set(
|
|
||||||
AWave(), Coroutine(__horizontal_projectile(world))
|
|
||||||
)
|
|
||||||
case _:
|
case _:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
yield wait(float(world[Wave].wave_list[-1][0]))
|
yield condition(
|
||||||
for entity_to_destroy in world.query(AWave):
|
lambda world: all(Coroutine not in entity for entity in entities)
|
||||||
entity_to_destroy.destroy()
|
)
|
||||||
for entities in world.query(
|
|
||||||
RainProjectiles or ZoneAttack or Spike or HorizontalProjectiles
|
|
||||||
):
|
|
||||||
entities.destroy()
|
|
||||||
|
|
||||||
|
|
||||||
def __create_zone_attack(world: World):
|
def __create_zone_attack(world: World, number: int = 2):
|
||||||
for _ in range(5):
|
"""
|
||||||
|
TODO
|
||||||
|
"""
|
||||||
|
for _ in range(number):
|
||||||
yield wait(5)
|
yield wait(5)
|
||||||
"""
|
|
||||||
TODO
|
|
||||||
"""
|
|
||||||
double = random.randint(1, 10)
|
double = random.randint(1, 10)
|
||||||
locate = random.randint(0, 2)
|
locate = random.randint(0, 2)
|
||||||
if double != 10:
|
if double != 10:
|
||||||
|
@ -385,11 +377,11 @@ def __create_zone_attack(world: World):
|
||||||
yield animation.wait()
|
yield animation.wait()
|
||||||
entity.destroy()
|
entity.destroy()
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
projectiles = world.new_entity()
|
projectile = world.new_entity()
|
||||||
|
|
||||||
projectiles.set(
|
projectile.set(
|
||||||
Sprite(
|
Sprite(
|
||||||
world[Assets].get_texture("error"),
|
world[Assets].get_texture("projectiles/0000"),
|
||||||
Vec2(
|
Vec2(
|
||||||
i * 41 + world[FightBox].p1[0] + (locate * 413),
|
i * 41 + world[FightBox].p1[0] + (locate * 413),
|
||||||
world[FightBox].p1[1],
|
world[FightBox].p1[1],
|
||||||
|
@ -399,11 +391,12 @@ def __create_zone_attack(world: World):
|
||||||
Animation("projectiles", 60, True),
|
Animation("projectiles", 60, True),
|
||||||
ZoneAttackProjectiles(),
|
ZoneAttackProjectiles(),
|
||||||
Hurt(10),
|
Hurt(10),
|
||||||
TimedEvent(0.4, lambda world, entity: entity.destroy()),
|
TimedEvent(1.4, lambda world, entity: entity.destroy()),
|
||||||
)
|
smooth.Target(
|
||||||
projectiles[smooth.Target] = Vec2(
|
i * 41 + world[FightBox].p1[0] + (locate * 413),
|
||||||
i * 41 + world[FightBox].p1[0] + (locate * 413),
|
1080,
|
||||||
world[FightBox].p2[1],
|
),
|
||||||
|
smooth.Speed(4),
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -429,11 +422,11 @@ def __create_zone_attack(world: World):
|
||||||
entity.destroy()
|
entity.destroy()
|
||||||
for _z in range(2):
|
for _z in range(2):
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
projectiles = world.new_entity()
|
projectile = world.new_entity()
|
||||||
|
|
||||||
projectiles.set(
|
projectile.set(
|
||||||
Sprite(
|
Sprite(
|
||||||
world[Assets].get_texture("error"),
|
world[Assets].get_texture("projectiles/0000"),
|
||||||
Vec2(
|
Vec2(
|
||||||
i * 41 + world[FightBox].p1[0] + (locate * 413),
|
i * 41 + world[FightBox].p1[0] + (locate * 413),
|
||||||
world[FightBox].p1[1],
|
world[FightBox].p1[1],
|
||||||
|
@ -443,20 +436,21 @@ def __create_zone_attack(world: World):
|
||||||
Animation("projectiles", 60, True),
|
Animation("projectiles", 60, True),
|
||||||
ZoneAttackProjectiles(),
|
ZoneAttackProjectiles(),
|
||||||
Hurt(10),
|
Hurt(10),
|
||||||
TimedEvent(0.4, lambda world, entity: entity.destroy()),
|
TimedEvent(1.4, lambda world, entity: entity.destroy()),
|
||||||
)
|
smooth.Target(
|
||||||
projectiles[smooth.Target] = Vec2(
|
i * 41 + world[FightBox].p1[0] + (locate * 413),
|
||||||
i * 41 + world[FightBox].p1[0] + (locate * 413),
|
1080,
|
||||||
world[FightBox].p2[1],
|
),
|
||||||
|
smooth.Speed(2),
|
||||||
)
|
)
|
||||||
locate = locate2
|
locate = locate2
|
||||||
|
|
||||||
|
|
||||||
def __create_spike(world: World):
|
def __create_spike(world: World, number: int = 1):
|
||||||
"""
|
"""
|
||||||
TODO
|
TODO
|
||||||
"""
|
"""
|
||||||
for _ in range(2):
|
for _ in range(number):
|
||||||
yield wait(15.0)
|
yield wait(15.0)
|
||||||
temp_warning_spike = world.new_entity()
|
temp_warning_spike = world.new_entity()
|
||||||
temp_warning_spike.set(
|
temp_warning_spike.set(
|
||||||
|
@ -473,7 +467,7 @@ def __create_spike(world: World):
|
||||||
top_spike = world.new_entity()
|
top_spike = world.new_entity()
|
||||||
top_spike.set(
|
top_spike.set(
|
||||||
Sprite(
|
Sprite(
|
||||||
world[Assets].get_texture("error"),
|
world[Assets].get_texture("spike/spike_up_coming/0000"),
|
||||||
Vec2(world[FightBox].p1[0], world[FightBox].p1[1]),
|
Vec2(world[FightBox].p1[0], world[FightBox].p1[1]),
|
||||||
3,
|
3,
|
||||||
),
|
),
|
||||||
|
@ -492,7 +486,7 @@ def __create_spike(world: World):
|
||||||
down_spike = world.new_entity()
|
down_spike = world.new_entity()
|
||||||
down_spike.set(
|
down_spike.set(
|
||||||
Sprite(
|
Sprite(
|
||||||
world[Assets].get_texture("error"),
|
world[Assets].get_texture("spike/spike_down_coming/0000"),
|
||||||
Vec2(world[FightBox].p1[0], world[FightBox].p2[1] - 143),
|
Vec2(world[FightBox].p1[0], world[FightBox].p2[1] - 143),
|
||||||
3,
|
3,
|
||||||
),
|
),
|
||||||
|
@ -511,7 +505,7 @@ def __create_spike(world: World):
|
||||||
left_spike = world.new_entity()
|
left_spike = world.new_entity()
|
||||||
left_spike.set(
|
left_spike.set(
|
||||||
Sprite(
|
Sprite(
|
||||||
world[Assets].get_texture("error"),
|
world[Assets].get_texture("spike/spike_left_coming/0000"),
|
||||||
Vec2(world[FightBox].p1[0], world[FightBox].p1[1]),
|
Vec2(world[FightBox].p1[0], world[FightBox].p1[1]),
|
||||||
2,
|
2,
|
||||||
),
|
),
|
||||||
|
@ -530,7 +524,7 @@ def __create_spike(world: World):
|
||||||
right_spike = world.new_entity()
|
right_spike = world.new_entity()
|
||||||
right_spike.set(
|
right_spike.set(
|
||||||
Sprite(
|
Sprite(
|
||||||
world[Assets].get_texture("error"),
|
world[Assets].get_texture("spike/spike_left_coming/0000"),
|
||||||
Vec2(world[FightBox].p2[0] - 50, world[FightBox].p1[1]),
|
Vec2(world[FightBox].p2[0] - 50, world[FightBox].p1[1]),
|
||||||
2,
|
2,
|
||||||
),
|
),
|
||||||
|
@ -573,8 +567,8 @@ class RainProjectiles(Vec2):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def __rainning_projectiles(world: World):
|
def __rainning_projectiles(world: World, number: int = 20):
|
||||||
while IsRunning:
|
for _ in range(number):
|
||||||
animation = Animation(
|
animation = Animation(
|
||||||
"projectiles_coming",
|
"projectiles_coming",
|
||||||
30,
|
30,
|
||||||
|
@ -582,7 +576,7 @@ def __rainning_projectiles(world: World):
|
||||||
entity = world.new_entity()
|
entity = world.new_entity()
|
||||||
entity.set(
|
entity.set(
|
||||||
Sprite(
|
Sprite(
|
||||||
world[Assets].get_texture("error"),
|
world[Assets].get_texture("projectiles_coming/0000"),
|
||||||
Vec2(random.randint(0, 1399), 300),
|
Vec2(random.randint(0, 1399), 300),
|
||||||
4,
|
4,
|
||||||
),
|
),
|
||||||
|
@ -600,8 +594,8 @@ def __rainning_projectiles(world: World):
|
||||||
entity.destroy()
|
entity.destroy()
|
||||||
|
|
||||||
|
|
||||||
def __horizontal_projectile(world: World):
|
def __horizontal_projectile(world: World, left: bool, number: int = 10):
|
||||||
while IsRunning:
|
for _ in range(number):
|
||||||
animation = Animation(
|
animation = Animation(
|
||||||
"projectiles_coming",
|
"projectiles_coming",
|
||||||
30,
|
30,
|
||||||
|
@ -611,16 +605,20 @@ def __horizontal_projectile(world: World):
|
||||||
HorizontalProjectiles(),
|
HorizontalProjectiles(),
|
||||||
Sprite(
|
Sprite(
|
||||||
world[Assets].get_texture("error"),
|
world[Assets].get_texture("error"),
|
||||||
Vec2(10, random.randint(500, 930)),
|
Vec2(10 if left else render.WIDTH - 10, random.randint(500, 930)),
|
||||||
4,
|
4,
|
||||||
),
|
),
|
||||||
animation,
|
animation,
|
||||||
smooth.Speed(2),
|
smooth.Speed(1),
|
||||||
Hurt(10),
|
Hurt(10),
|
||||||
)
|
)
|
||||||
yield animation.wait()
|
yield animation.wait()
|
||||||
yield wait(1)
|
yield wait(1)
|
||||||
entity.set(smooth.Target(Vec2(1500, entity[Sprite].position.y)))
|
entity.set(
|
||||||
|
smooth.Target(
|
||||||
|
Vec2(1500 if left else render.WIDTH + 60, entity[Sprite].position.y)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
for entity in world.query(HorizontalProjectiles, Sprite):
|
for entity in world.query(HorizontalProjectiles, Sprite):
|
||||||
if entity[Sprite].position.x > 1440:
|
if entity[Sprite].position.x > 1440:
|
||||||
|
|
Loading…
Reference in a new issue