Marche pas

This commit is contained in:
Tipragot 2023-11-05 17:13:08 +01:00
parent 57fbee1271
commit 0d0ee0dbc1

View file

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