Save unfinished work
This commit is contained in:
parent
f18fbdccbc
commit
ba7c5122be
BIN
assets/error.mp3
BIN
assets/error.mp3
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 213 KiB |
Binary file not shown.
Before Width: | Height: | Size: 192 KiB |
Binary file not shown.
|
@ -6,7 +6,8 @@ from enum import Enum
|
||||||
from engine import Plugin, Scene
|
from engine import Plugin, Scene
|
||||||
from engine.ecs import Entity, World
|
from engine.ecs import Entity, World
|
||||||
from engine.math import Vec2
|
from engine.math import Vec2
|
||||||
from plugins import physics, render
|
from plugins import render
|
||||||
|
from plugins import physics
|
||||||
from plugins.inputs import Held
|
from plugins.inputs import Held
|
||||||
from plugins.render import (
|
from plugins.render import (
|
||||||
Origin,
|
Origin,
|
||||||
|
@ -19,6 +20,7 @@ from plugins.render import (
|
||||||
)
|
)
|
||||||
from plugins.timing import Delta, Time
|
from plugins.timing import Delta, Time
|
||||||
import random
|
import random
|
||||||
|
from plugins.physics import CollisionHandler, Solid, Velocity
|
||||||
|
|
||||||
|
|
||||||
class GameMode(Enum):
|
class GameMode(Enum):
|
||||||
|
@ -204,9 +206,9 @@ def __spawn_ellements(world: World):
|
||||||
Origin(Vec2(1, 0)),
|
Origin(Vec2(1, 0)),
|
||||||
Scale(Vec2(10, render.HEIGHT)),
|
Scale(Vec2(10, render.HEIGHT)),
|
||||||
Position(Vec2(70, 0)),
|
Position(Vec2(70, 0)),
|
||||||
physics.Solid(),
|
Solid(),
|
||||||
LeftWall(),
|
LeftWall(),
|
||||||
physics.CollisionHandler(__bounce_on_left_wall),
|
CollisionHandler(__bounce_on_left_wall),
|
||||||
)
|
)
|
||||||
|
|
||||||
# Mon mur du RN
|
# Mon mur du RN
|
||||||
|
@ -214,9 +216,9 @@ def __spawn_ellements(world: World):
|
||||||
Origin(Vec2(0, 0)),
|
Origin(Vec2(0, 0)),
|
||||||
Scale(Vec2(10, render.HEIGHT)),
|
Scale(Vec2(10, render.HEIGHT)),
|
||||||
Position(Vec2(render.WIDTH - 70, 0)),
|
Position(Vec2(render.WIDTH - 70, 0)),
|
||||||
physics.Solid(),
|
Solid(),
|
||||||
RightWall(),
|
RightWall(),
|
||||||
physics.CollisionHandler(__bounce_on_right_wall),
|
CollisionHandler(__bounce_on_right_wall),
|
||||||
)
|
)
|
||||||
|
|
||||||
# Mon mur du bas
|
# Mon mur du bas
|
||||||
|
@ -224,7 +226,7 @@ def __spawn_ellements(world: World):
|
||||||
Origin(Vec2(0, 0)),
|
Origin(Vec2(0, 0)),
|
||||||
Scale(Vec2(render.WIDTH, 10)),
|
Scale(Vec2(render.WIDTH, 10)),
|
||||||
Position(Vec2(0, render.HEIGHT)),
|
Position(Vec2(0, render.HEIGHT)),
|
||||||
physics.Solid(),
|
Solid(),
|
||||||
)
|
)
|
||||||
|
|
||||||
# Mon mur du haut
|
# Mon mur du haut
|
||||||
|
@ -232,7 +234,7 @@ def __spawn_ellements(world: World):
|
||||||
Origin(Vec2(0, 1)),
|
Origin(Vec2(0, 1)),
|
||||||
Scale(Vec2(render.WIDTH, 10)),
|
Scale(Vec2(render.WIDTH, 10)),
|
||||||
Position(Vec2(0, 0)),
|
Position(Vec2(0, 0)),
|
||||||
physics.Solid(),
|
Solid(),
|
||||||
)
|
)
|
||||||
|
|
||||||
# Joueur 1
|
# Joueur 1
|
||||||
|
@ -244,7 +246,7 @@ def __spawn_ellements(world: World):
|
||||||
Vec2(44, 250),
|
Vec2(44, 250),
|
||||||
Vec2(0.5),
|
Vec2(0.5),
|
||||||
),
|
),
|
||||||
physics.Solid(),
|
Solid(),
|
||||||
Player1(),
|
Player1(),
|
||||||
UpKey("z"),
|
UpKey("z"),
|
||||||
DownKey("s"),
|
DownKey("s"),
|
||||||
|
@ -261,7 +263,7 @@ def __spawn_ellements(world: World):
|
||||||
Vec2(44, 250),
|
Vec2(44, 250),
|
||||||
Vec2(0.5),
|
Vec2(0.5),
|
||||||
),
|
),
|
||||||
physics.Solid(),
|
Solid(),
|
||||||
Player2(),
|
Player2(),
|
||||||
(UpKey("up"), DownKey("down"), Speed(1000))
|
(UpKey("up"), DownKey("down"), Speed(1000))
|
||||||
if world[GameMode] == GameMode.TWO
|
if world[GameMode] == GameMode.TWO
|
||||||
|
@ -323,8 +325,8 @@ def __spawn_ball(world: World):
|
||||||
Vec2(0.5),
|
Vec2(0.5),
|
||||||
),
|
),
|
||||||
Ball(),
|
Ball(),
|
||||||
physics.Velocity(velocity),
|
Velocity(velocity),
|
||||||
physics.CollisionHandler(__collision_with_ball),
|
CollisionHandler(__collision_with_ball),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -367,12 +369,10 @@ def __bounce_on_player(a: Entity, b: Entity):
|
||||||
Fonction qui decrit se qui se passe lorque la ball entre en collision avec un joueur
|
Fonction qui decrit se qui se passe lorque la ball entre en collision avec un joueur
|
||||||
"""
|
"""
|
||||||
if Player1 in b or Player2 in b:
|
if Player1 in b or Player2 in b:
|
||||||
speed = a[physics.Velocity].length
|
speed = a[Velocity].length
|
||||||
a[physics.Velocity] = a[physics.Velocity].normalized
|
a[Velocity] = a[Velocity].normalized
|
||||||
a[physics.Velocity].y = (a[Position].y - b[Position].y) * 0.005
|
a[Velocity].y = (a[Position].y - b[Position].y) * 0.005
|
||||||
a[physics.Velocity] = a[physics.Velocity].normalized * min(
|
a[Velocity] = a[Velocity].normalized * min((speed * 1.1), 1000.0)
|
||||||
(speed * 1.1), 1000.0
|
|
||||||
)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -441,17 +441,17 @@ def __simulate_wall_position(entity: Entity, component_type: type):
|
||||||
simulation_entity = entity.world.new_entity()
|
simulation_entity = entity.world.new_entity()
|
||||||
|
|
||||||
def __collision_handler(a: Entity, b: Entity):
|
def __collision_handler(a: Entity, b: Entity):
|
||||||
entity[physics.CollisionHandler].callback(a, b)
|
entity[CollisionHandler].callback(a, b)
|
||||||
return component_type not in b
|
return component_type not in b
|
||||||
|
|
||||||
simulation_entity.set(
|
simulation_entity.set(
|
||||||
Position(entity[Position]),
|
Position(entity[Position]),
|
||||||
Scale(entity[Scale]),
|
Scale(entity[Scale]),
|
||||||
physics.Velocity(entity[physics.Velocity]),
|
Velocity(entity[Velocity]),
|
||||||
Origin(entity[Origin]),
|
Origin(entity[Origin]),
|
||||||
physics.CollisionHandler(__collision_handler),
|
CollisionHandler(__collision_handler),
|
||||||
)
|
)
|
||||||
physics.move_entity(simulation_entity, entity[physics.Velocity] * 500)
|
physics.move_entity(simulation_entity, entity[Velocity] * 500)
|
||||||
return simulation_entity
|
return simulation_entity
|
||||||
|
|
||||||
|
|
||||||
|
@ -460,7 +460,7 @@ def _update_bot(world: World):
|
||||||
Fonction qui update les mouvement du bot
|
Fonction qui update les mouvement du bot
|
||||||
"""
|
"""
|
||||||
# On récupère la balle la plus proche du bot
|
# On récupère la balle la plus proche du bot
|
||||||
ball_query = world.query(Position, physics.Velocity, physics.CollisionHandler)
|
ball_query = world.query(Position, Velocity, CollisionHandler)
|
||||||
if ball_query == set():
|
if ball_query == set():
|
||||||
return None
|
return None
|
||||||
ball = max(ball_query, key=lambda entity: entity[Position].y)
|
ball = max(ball_query, key=lambda entity: entity[Position].y)
|
||||||
|
@ -470,24 +470,24 @@ def _update_bot(world: World):
|
||||||
player = world.query(Player1).pop()
|
player = world.query(Player1).pop()
|
||||||
|
|
||||||
# On trouve l'endroit ou la balle va arriver sur le mur de droite
|
# On trouve l'endroit ou la balle va arriver sur le mur de droite
|
||||||
bot.remove(physics.Solid)
|
bot.remove(Solid)
|
||||||
right_wall_ball = __simulate_wall_position(ball, RightWall)
|
right_wall_ball = __simulate_wall_position(ball, RightWall)
|
||||||
right_touch_height = right_wall_ball[Position].y
|
right_touch_height = right_wall_ball[Position].y
|
||||||
right_wall_ball.destroy()
|
right_wall_ball.destroy()
|
||||||
bot.set(physics.Solid())
|
bot.set(Solid())
|
||||||
|
|
||||||
# On teste différentes possitions pour voir laquelle la plus éloigné du joueur
|
# On teste différentes possitions pour voir laquelle la plus éloigné du joueur
|
||||||
# Mais seulement si la balle vas vers la droite car sinon elle touchera le mur
|
# Mais seulement si la balle vas vers la droite car sinon elle touchera le mur
|
||||||
# de gauche sans intervention du bot
|
# de gauche sans intervention du bot
|
||||||
if ball[physics.Velocity].x > 0:
|
if ball[Velocity].x > 0:
|
||||||
bot_base_y = bot[Position].y
|
bot_base_y = bot[Position].y
|
||||||
target: float = right_touch_height
|
target: float = right_touch_height
|
||||||
better_distance = None
|
better_distance = None
|
||||||
for offset in [-100, -50, 0, 50, 100]:
|
for offset in [-100, -50, 0, 50, 100]:
|
||||||
bot[Position].y = right_touch_height + offset
|
bot[Position].y = right_touch_height + offset
|
||||||
player.remove(physics.Solid)
|
player.remove(Solid)
|
||||||
left_wall_ball = __simulate_wall_position(ball, LeftWall)
|
left_wall_ball = __simulate_wall_position(ball, LeftWall)
|
||||||
player.set(physics.Solid())
|
player.set(Solid())
|
||||||
left_touch_height = left_wall_ball[Position].y
|
left_touch_height = left_wall_ball[Position].y
|
||||||
left_wall_ball.destroy()
|
left_wall_ball.destroy()
|
||||||
if (
|
if (
|
||||||
|
@ -518,20 +518,20 @@ def __check_bonus_collision(world: World):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
for entity in world.query(Bonus):
|
for entity in world.query(Bonus):
|
||||||
entity.set(physics.Solid())
|
entity.set(Solid())
|
||||||
for entity in world.query(Ball):
|
for entity in world.query(Ball):
|
||||||
simulated_ball = world.new_entity()
|
simulated_ball = world.new_entity()
|
||||||
simulated_ball.set(
|
simulated_ball.set(
|
||||||
Position(entity[Position]),
|
Position(entity[Position]),
|
||||||
Scale(entity[Scale]),
|
Scale(entity[Scale]),
|
||||||
physics.Velocity(entity[physics.Velocity]),
|
Velocity(entity[Velocity]),
|
||||||
Origin(entity[Origin]),
|
Origin(entity[Origin]),
|
||||||
physics.CollisionHandler(__collision_handler),
|
CollisionHandler(__collision_handler),
|
||||||
)
|
)
|
||||||
physics.move_entity(simulated_ball, entity[physics.Velocity] * world[Delta])
|
physics.move_entity(simulated_ball, entity[Velocity] * world[Delta])
|
||||||
simulated_ball.destroy()
|
simulated_ball.destroy()
|
||||||
for entity in world.query(Bonus):
|
for entity in world.query(Bonus):
|
||||||
entity.remove(physics.Solid)
|
entity.remove(Solid)
|
||||||
|
|
||||||
|
|
||||||
def __update_scores(world: World, ball: Entity):
|
def __update_scores(world: World, ball: Entity):
|
||||||
|
|
Loading…
Reference in a new issue