Add mouse controls

This commit is contained in:
Tipragot 2023-11-05 18:36:28 +01:00
parent 647239b155
commit ed917e3044
3 changed files with 31 additions and 17 deletions

View file

@ -48,7 +48,7 @@ def __on_click_butons(world: World, _entity: Entity, name: str):
case "tricheur": case "tricheur":
world[CurrentScene] = base_game.CHEATER world[CurrentScene] = base_game.CHEATER
case "histoire": case "histoire":
world[CurrentScene] = directory_search.SCENE world[CurrentScene] = boss_fight.SCENE
case _: case _:
pass pass

View file

@ -13,7 +13,7 @@ from engine.math import Vec2
from plugins import assets, smooth from plugins import assets, smooth
from plugins import render from plugins import render
from plugins.animation import Animation from plugins.animation import Animation
from plugins.inputs import Held from plugins.inputs import Held, MousePosition
from plugins.render import Sprite from plugins.render import Sprite
from plugins.assets import Assets from plugins.assets import Assets
from plugins.coroutine import condition, wait, Coroutine from plugins.coroutine import condition, wait, Coroutine
@ -192,6 +192,24 @@ def __move(world: World):
held = world[Held] held = world[Held]
s_pos = world[ShieldPos] s_pos = world[ShieldPos]
for entity in world.query(Sprite, Velocity): for entity in world.query(Sprite, Velocity):
if "button_1" in held:
world[ShieldPos] += (
(world[MousePosition] - world[ShieldPos]).normalized
* entity[Velocity]
* world[Delta]
)
box = world[FightBox]
if world[ShieldPos].x < box.p1[0] + 37:
world[ShieldPos].x = box.p1[0] + 37
if world[ShieldPos].x > box.p2[0] - 37:
world[ShieldPos].x = box.p2[0] - 37
if world[ShieldPos].y < box.p1[1] + 45.5:
world[ShieldPos].y = box.p1[1] + 45.5
if world[ShieldPos].y > box.p2[1] - 45.5:
world[ShieldPos].y = box.p2[1] - 45.5
entity[smooth.Target] = world[ShieldPos]
continue
for key in held: for key in held:
if key in ("up", "z"): if key in ("up", "z"):
if ( if (
@ -308,12 +326,6 @@ def __defeat(world: World):
world[CurrentScene] = __new_game_scene() world[CurrentScene] = __new_game_scene()
class AWave:
"""
TODO
"""
def __wave(world: World): def __wave(world: World):
entities: list[Entity] = [] entities: list[Entity] = []
for i, actuel_wave in enumerate(world[Wave].wave_list): for i, actuel_wave in enumerate(world[Wave].wave_list):
@ -323,28 +335,26 @@ def __wave(world: World):
case "rainning": case "rainning":
entity = world.new_entity() entity = world.new_entity()
entities.append(entity) entities.append(entity)
entity.set(AWave(), Coroutine(__rainning_projectiles(world))) entity.set(Coroutine(__rainning_projectiles(world)))
case "zones": case "zones":
entity = world.new_entity() entity = world.new_entity()
entities.append(entity) entities.append(entity)
entity.set(AWave(), Coroutine(__create_zone_attack(world))) entity.set(Coroutine(__create_zone_attack(world)))
case "spikes": case "spikes":
entity = world.new_entity() entity = world.new_entity()
entities.append(entity) entities.append(entity)
entity.set(AWave(), Coroutine(__create_spike(world))) entity.set(Coroutine(__create_spike(world)))
case "horizontal_left": case "horizontal_left":
entity = world.new_entity() entity = world.new_entity()
entities.append(entity) entities.append(entity)
entity.set(AWave(), Coroutine(__horizontal_projectile(world, True))) entity.set(Coroutine(__horizontal_projectile(world, True)))
case "horizontal_right": case "horizontal_right":
entity = world.new_entity() entity = world.new_entity()
entities.append(entity) entities.append(entity)
entity.set( entity.set(Coroutine(__horizontal_projectile(world, False)))
AWave(), Coroutine(__horizontal_projectile(world, False))
)
case _: case _:
pass pass
yield wait(0.5) yield wait(0.5)
@ -602,7 +612,7 @@ def __horizontal_projectile(world: World, left: bool, number: int = 10):
entity.set( entity.set(
HorizontalProjectiles(), HorizontalProjectiles(),
Sprite( Sprite(
world[Assets].get_texture("error"), world[Assets].get_texture("projectiles_coming/0000"),
Vec2(10 if left else render.WIDTH - 10, random.randint(500, 889)), Vec2(10 if left else render.WIDTH - 10, random.randint(500, 889)),
4, 4,
), ),

View file

@ -16,6 +16,7 @@ from plugins.assets import Assets
from plugins.render import Sprite from plugins.render import Sprite
from plugins.sound import Sound from plugins.sound import Sound
from plugins.text import Text from plugins.text import Text
from scenes.story import boss_fight
LINES = 3 LINES = 3
@ -185,7 +186,10 @@ def __game_loop(world: World):
yield wait(5.0 - (i * 0.4)) yield wait(5.0 - (i * 0.4))
__spawn_search_directory(world) __spawn_search_directory(world)
yield wait(5.0) yield wait(5.0)
print("BRABO BG !")
# On passe a la scène de jeu (TEMP)
yield wait(5.0)
world[CurrentScene] = boss_fight.SCENE
def __spawn_search_alerts(world: World, nb_alerts: int): def __spawn_search_alerts(world: World, nb_alerts: int):