diff --git a/assets/sounds/error.mp3 b/assets/error.mp3 similarity index 100% rename from assets/sounds/error.mp3 rename to assets/error.mp3 diff --git a/assets/font.ttf b/assets/font.ttf index 35d9c02..0e2990c 100644 Binary files a/assets/font.ttf and b/assets/font.ttf differ diff --git a/assets/global/base_game/click.wav b/assets/global/base_game/click.wav deleted file mode 100644 index a92759a..0000000 Binary files a/assets/global/base_game/click.wav and /dev/null differ diff --git a/assets/global/click/1.wav b/assets/global/click/1.wav deleted file mode 100644 index e4b267e..0000000 Binary files a/assets/global/click/1.wav and /dev/null differ diff --git a/assets/global/click/2.wav b/assets/global/click/2.wav deleted file mode 100644 index 5881f78..0000000 Binary files a/assets/global/click/2.wav and /dev/null differ diff --git a/assets/loaded.png b/assets/loaded.png new file mode 100644 index 0000000..6fcb6f3 Binary files /dev/null and b/assets/loaded.png differ diff --git a/assets/sounds/bound.mp3 b/assets/sounds/bound.mp3 new file mode 100644 index 0000000..d47f477 Binary files /dev/null and b/assets/sounds/bound.mp3 differ diff --git a/assets/global/click/0.wav b/assets/sounds/click.wav similarity index 100% rename from assets/global/click/0.wav rename to assets/sounds/click.wav diff --git a/assets/sounds/music.mp3 b/assets/sounds/music.mp3 new file mode 100644 index 0000000..361f33b Binary files /dev/null and b/assets/sounds/music.mp3 differ diff --git a/assets/textures/background.jpg b/assets/textures/background.jpg new file mode 100644 index 0000000..38beb7b Binary files /dev/null and b/assets/textures/background.jpg differ diff --git a/assets/textures/background.png b/assets/textures/background.png deleted file mode 100644 index 01be4e0..0000000 Binary files a/assets/textures/background.png and /dev/null differ diff --git a/assets/textures/background_menu.png b/assets/textures/background_menu.png new file mode 100644 index 0000000..40d422e Binary files /dev/null and b/assets/textures/background_menu.png differ diff --git a/assets/textures/ball.png b/assets/textures/ball.png new file mode 100644 index 0000000..9d033b5 Binary files /dev/null and b/assets/textures/ball.png differ diff --git a/assets/textures/button_one_player.png b/assets/textures/button_one_player.png new file mode 100644 index 0000000..1251414 Binary files /dev/null and b/assets/textures/button_one_player.png differ diff --git a/assets/textures/button_one_player_hover.png b/assets/textures/button_one_player_hover.png new file mode 100644 index 0000000..7bddfd5 Binary files /dev/null and b/assets/textures/button_one_player_hover.png differ diff --git a/assets/textures/button_two_player.png b/assets/textures/button_two_player.png new file mode 100644 index 0000000..08c7a63 Binary files /dev/null and b/assets/textures/button_two_player.png differ diff --git a/assets/textures/button_two_player_hover.png b/assets/textures/button_two_player_hover.png new file mode 100644 index 0000000..f9700ec Binary files /dev/null and b/assets/textures/button_two_player_hover.png differ diff --git a/assets/textures/countdown/0000.png b/assets/textures/countdown/0000.png new file mode 100644 index 0000000..b374577 Binary files /dev/null and b/assets/textures/countdown/0000.png differ diff --git a/assets/textures/countdown/0001.png b/assets/textures/countdown/0001.png new file mode 100644 index 0000000..7d03e8e Binary files /dev/null and b/assets/textures/countdown/0001.png differ diff --git a/assets/textures/countdown/0002.png b/assets/textures/countdown/0002.png new file mode 100644 index 0000000..26611c1 Binary files /dev/null and b/assets/textures/countdown/0002.png differ diff --git a/assets/textures/countdown/0003.png b/assets/textures/countdown/0003.png new file mode 100644 index 0000000..f506505 Binary files /dev/null and b/assets/textures/countdown/0003.png differ diff --git a/assets/textures/countdown/0004.png b/assets/textures/countdown/0004.png new file mode 100644 index 0000000..de697a2 Binary files /dev/null and b/assets/textures/countdown/0004.png differ diff --git a/assets/textures/countdown/0005.png b/assets/textures/countdown/0005.png new file mode 100644 index 0000000..23c0b69 Binary files /dev/null and b/assets/textures/countdown/0005.png differ diff --git a/assets/textures/countdown/0006.png b/assets/textures/countdown/0006.png new file mode 100644 index 0000000..ee76d44 Binary files /dev/null and b/assets/textures/countdown/0006.png differ diff --git a/assets/textures/countdown/0007.png b/assets/textures/countdown/0007.png new file mode 100644 index 0000000..f12e3ee Binary files /dev/null and b/assets/textures/countdown/0007.png differ diff --git a/assets/textures/countdown/0008.png b/assets/textures/countdown/0008.png new file mode 100644 index 0000000..a2df483 Binary files /dev/null and b/assets/textures/countdown/0008.png differ diff --git a/assets/textures/countdown/0009.png b/assets/textures/countdown/0009.png new file mode 100644 index 0000000..08c1d9a Binary files /dev/null and b/assets/textures/countdown/0009.png differ diff --git a/assets/textures/countdown/0010.png b/assets/textures/countdown/0010.png new file mode 100644 index 0000000..ce60514 Binary files /dev/null and b/assets/textures/countdown/0010.png differ diff --git a/assets/textures/countdown/0011.png b/assets/textures/countdown/0011.png new file mode 100644 index 0000000..34fdb5f Binary files /dev/null and b/assets/textures/countdown/0011.png differ diff --git a/assets/textures/countdown/0012.png b/assets/textures/countdown/0012.png new file mode 100644 index 0000000..318f585 Binary files /dev/null and b/assets/textures/countdown/0012.png differ diff --git a/assets/textures/countdown/0013.png b/assets/textures/countdown/0013.png new file mode 100644 index 0000000..576e8f0 Binary files /dev/null and b/assets/textures/countdown/0013.png differ diff --git a/assets/textures/countdown/0014.png b/assets/textures/countdown/0014.png new file mode 100644 index 0000000..aac16a0 Binary files /dev/null and b/assets/textures/countdown/0014.png differ diff --git a/assets/textures/countdown/0015.png b/assets/textures/countdown/0015.png new file mode 100644 index 0000000..d8e328a Binary files /dev/null and b/assets/textures/countdown/0015.png differ diff --git a/assets/textures/countdown/0016.png b/assets/textures/countdown/0016.png new file mode 100644 index 0000000..400d741 Binary files /dev/null and b/assets/textures/countdown/0016.png differ diff --git a/assets/textures/countdown/0017.png b/assets/textures/countdown/0017.png new file mode 100644 index 0000000..ea854c2 Binary files /dev/null and b/assets/textures/countdown/0017.png differ diff --git a/assets/textures/countdown/0018.png b/assets/textures/countdown/0018.png new file mode 100644 index 0000000..21f5679 Binary files /dev/null and b/assets/textures/countdown/0018.png differ diff --git a/assets/textures/countdown/0019.png b/assets/textures/countdown/0019.png new file mode 100644 index 0000000..d0d5592 Binary files /dev/null and b/assets/textures/countdown/0019.png differ diff --git a/assets/textures/countdown/0020.png b/assets/textures/countdown/0020.png new file mode 100644 index 0000000..46835fb Binary files /dev/null and b/assets/textures/countdown/0020.png differ diff --git a/assets/textures/countdown/0021.png b/assets/textures/countdown/0021.png new file mode 100644 index 0000000..664e21b Binary files /dev/null and b/assets/textures/countdown/0021.png differ diff --git a/assets/textures/countdown/0022.png b/assets/textures/countdown/0022.png new file mode 100644 index 0000000..1a50fa9 Binary files /dev/null and b/assets/textures/countdown/0022.png differ diff --git a/assets/textures/countdown/0023.png b/assets/textures/countdown/0023.png new file mode 100644 index 0000000..2f37edc Binary files /dev/null and b/assets/textures/countdown/0023.png differ diff --git a/assets/textures/countdown/0024.png b/assets/textures/countdown/0024.png new file mode 100644 index 0000000..e469427 Binary files /dev/null and b/assets/textures/countdown/0024.png differ diff --git a/assets/textures/countdown/0025.png b/assets/textures/countdown/0025.png new file mode 100644 index 0000000..91e478d Binary files /dev/null and b/assets/textures/countdown/0025.png differ diff --git a/assets/textures/countdown/0026.png b/assets/textures/countdown/0026.png new file mode 100644 index 0000000..0b422c8 Binary files /dev/null and b/assets/textures/countdown/0026.png differ diff --git a/assets/textures/countdown/0027.png b/assets/textures/countdown/0027.png new file mode 100644 index 0000000..c48e4b6 Binary files /dev/null and b/assets/textures/countdown/0027.png differ diff --git a/assets/textures/countdown/0028.png b/assets/textures/countdown/0028.png new file mode 100644 index 0000000..b475963 Binary files /dev/null and b/assets/textures/countdown/0028.png differ diff --git a/assets/textures/countdown/0029.png b/assets/textures/countdown/0029.png new file mode 100644 index 0000000..11403da Binary files /dev/null and b/assets/textures/countdown/0029.png differ diff --git a/assets/textures/countdown/0030.png b/assets/textures/countdown/0030.png new file mode 100644 index 0000000..24e100e Binary files /dev/null and b/assets/textures/countdown/0030.png differ diff --git a/assets/textures/countdown/0031.png b/assets/textures/countdown/0031.png new file mode 100644 index 0000000..0ac880f Binary files /dev/null and b/assets/textures/countdown/0031.png differ diff --git a/assets/textures/countdown/0032.png b/assets/textures/countdown/0032.png new file mode 100644 index 0000000..21dff67 Binary files /dev/null and b/assets/textures/countdown/0032.png differ diff --git a/assets/textures/countdown/0033.png b/assets/textures/countdown/0033.png new file mode 100644 index 0000000..38b6279 Binary files /dev/null and b/assets/textures/countdown/0033.png differ diff --git a/assets/textures/countdown/0034.png b/assets/textures/countdown/0034.png new file mode 100644 index 0000000..fad49b5 Binary files /dev/null and b/assets/textures/countdown/0034.png differ diff --git a/assets/textures/countdown/0035.png b/assets/textures/countdown/0035.png new file mode 100644 index 0000000..138eeb7 Binary files /dev/null and b/assets/textures/countdown/0035.png differ diff --git a/assets/textures/countdown/0036.png b/assets/textures/countdown/0036.png new file mode 100644 index 0000000..7f5f6e4 Binary files /dev/null and b/assets/textures/countdown/0036.png differ diff --git a/assets/textures/countdown/0037.png b/assets/textures/countdown/0037.png new file mode 100644 index 0000000..4bcc7dc Binary files /dev/null and b/assets/textures/countdown/0037.png differ diff --git a/assets/textures/countdown/0038.png b/assets/textures/countdown/0038.png new file mode 100644 index 0000000..c293853 Binary files /dev/null and b/assets/textures/countdown/0038.png differ diff --git a/assets/textures/countdown/0039.png b/assets/textures/countdown/0039.png new file mode 100644 index 0000000..aa3c042 Binary files /dev/null and b/assets/textures/countdown/0039.png differ diff --git a/assets/textures/countdown/0040.png b/assets/textures/countdown/0040.png new file mode 100644 index 0000000..930d512 Binary files /dev/null and b/assets/textures/countdown/0040.png differ diff --git a/assets/textures/countdown/0041.png b/assets/textures/countdown/0041.png new file mode 100644 index 0000000..ee895f8 Binary files /dev/null and b/assets/textures/countdown/0041.png differ diff --git a/assets/textures/countdown/0042.png b/assets/textures/countdown/0042.png new file mode 100644 index 0000000..618bbba Binary files /dev/null and b/assets/textures/countdown/0042.png differ diff --git a/assets/textures/countdown/0043.png b/assets/textures/countdown/0043.png new file mode 100644 index 0000000..e41df04 Binary files /dev/null and b/assets/textures/countdown/0043.png differ diff --git a/assets/textures/countdown/0044.png b/assets/textures/countdown/0044.png new file mode 100644 index 0000000..e6eda8b Binary files /dev/null and b/assets/textures/countdown/0044.png differ diff --git a/assets/textures/countdown/0045.png b/assets/textures/countdown/0045.png new file mode 100644 index 0000000..ac230c0 Binary files /dev/null and b/assets/textures/countdown/0045.png differ diff --git a/assets/textures/countdown/0046.png b/assets/textures/countdown/0046.png new file mode 100644 index 0000000..ab1877b Binary files /dev/null and b/assets/textures/countdown/0046.png differ diff --git a/assets/textures/countdown/0047.png b/assets/textures/countdown/0047.png new file mode 100644 index 0000000..507ad25 Binary files /dev/null and b/assets/textures/countdown/0047.png differ diff --git a/assets/textures/countdown/0048.png b/assets/textures/countdown/0048.png new file mode 100644 index 0000000..f4da5fa Binary files /dev/null and b/assets/textures/countdown/0048.png differ diff --git a/assets/textures/countdown/0049.png b/assets/textures/countdown/0049.png new file mode 100644 index 0000000..e8810b6 Binary files /dev/null and b/assets/textures/countdown/0049.png differ diff --git a/assets/textures/countdown/0050.png b/assets/textures/countdown/0050.png new file mode 100644 index 0000000..c0f25b0 Binary files /dev/null and b/assets/textures/countdown/0050.png differ diff --git a/assets/textures/countdown/0051.png b/assets/textures/countdown/0051.png new file mode 100644 index 0000000..0927806 Binary files /dev/null and b/assets/textures/countdown/0051.png differ diff --git a/assets/textures/countdown/0052.png b/assets/textures/countdown/0052.png new file mode 100644 index 0000000..dc3ab5e Binary files /dev/null and b/assets/textures/countdown/0052.png differ diff --git a/assets/textures/countdown/0053.png b/assets/textures/countdown/0053.png new file mode 100644 index 0000000..17ad460 Binary files /dev/null and b/assets/textures/countdown/0053.png differ diff --git a/assets/textures/countdown/0054.png b/assets/textures/countdown/0054.png new file mode 100644 index 0000000..1cd4289 Binary files /dev/null and b/assets/textures/countdown/0054.png differ diff --git a/assets/textures/countdown/0055.png b/assets/textures/countdown/0055.png new file mode 100644 index 0000000..c6d4bd6 Binary files /dev/null and b/assets/textures/countdown/0055.png differ diff --git a/assets/textures/countdown/0056.png b/assets/textures/countdown/0056.png new file mode 100644 index 0000000..811ee03 Binary files /dev/null and b/assets/textures/countdown/0056.png differ diff --git a/assets/textures/countdown/0057.png b/assets/textures/countdown/0057.png new file mode 100644 index 0000000..6158595 Binary files /dev/null and b/assets/textures/countdown/0057.png differ diff --git a/assets/textures/countdown/0058.png b/assets/textures/countdown/0058.png new file mode 100644 index 0000000..cd2be49 Binary files /dev/null and b/assets/textures/countdown/0058.png differ diff --git a/assets/textures/countdown/0059.png b/assets/textures/countdown/0059.png new file mode 100644 index 0000000..c1351e1 Binary files /dev/null and b/assets/textures/countdown/0059.png differ diff --git a/assets/textures/countdown/0060.png b/assets/textures/countdown/0060.png new file mode 100644 index 0000000..fe28d30 Binary files /dev/null and b/assets/textures/countdown/0060.png differ diff --git a/assets/textures/countdown/0061.png b/assets/textures/countdown/0061.png new file mode 100644 index 0000000..3222e20 Binary files /dev/null and b/assets/textures/countdown/0061.png differ diff --git a/assets/textures/countdown/0062.png b/assets/textures/countdown/0062.png new file mode 100644 index 0000000..2fec69c Binary files /dev/null and b/assets/textures/countdown/0062.png differ diff --git a/assets/textures/countdown/0063.png b/assets/textures/countdown/0063.png new file mode 100644 index 0000000..24491f8 Binary files /dev/null and b/assets/textures/countdown/0063.png differ diff --git a/assets/textures/countdown/0064.png b/assets/textures/countdown/0064.png new file mode 100644 index 0000000..1c2a3b8 Binary files /dev/null and b/assets/textures/countdown/0064.png differ diff --git a/assets/textures/countdown/0065.png b/assets/textures/countdown/0065.png new file mode 100644 index 0000000..97b802b Binary files /dev/null and b/assets/textures/countdown/0065.png differ diff --git a/assets/textures/countdown/0066.png b/assets/textures/countdown/0066.png new file mode 100644 index 0000000..96d4ccc Binary files /dev/null and b/assets/textures/countdown/0066.png differ diff --git a/assets/textures/countdown/0067.png b/assets/textures/countdown/0067.png new file mode 100644 index 0000000..13b074c Binary files /dev/null and b/assets/textures/countdown/0067.png differ diff --git a/assets/textures/countdown/0068.png b/assets/textures/countdown/0068.png new file mode 100644 index 0000000..cec4db5 Binary files /dev/null and b/assets/textures/countdown/0068.png differ diff --git a/assets/textures/countdown/0069.png b/assets/textures/countdown/0069.png new file mode 100644 index 0000000..b09ff79 Binary files /dev/null and b/assets/textures/countdown/0069.png differ diff --git a/assets/textures/countdown/0070.png b/assets/textures/countdown/0070.png new file mode 100644 index 0000000..bd5e741 Binary files /dev/null and b/assets/textures/countdown/0070.png differ diff --git a/assets/textures/countdown/0071.png b/assets/textures/countdown/0071.png new file mode 100644 index 0000000..50a5258 Binary files /dev/null and b/assets/textures/countdown/0071.png differ diff --git a/assets/textures/countdown/0072.png b/assets/textures/countdown/0072.png new file mode 100644 index 0000000..98cf67e Binary files /dev/null and b/assets/textures/countdown/0072.png differ diff --git a/assets/textures/countdown/0073.png b/assets/textures/countdown/0073.png new file mode 100644 index 0000000..c0d356d Binary files /dev/null and b/assets/textures/countdown/0073.png differ diff --git a/assets/textures/countdown/0074.png b/assets/textures/countdown/0074.png new file mode 100644 index 0000000..c9033c2 Binary files /dev/null and b/assets/textures/countdown/0074.png differ diff --git a/assets/textures/countdown/0075.png b/assets/textures/countdown/0075.png new file mode 100644 index 0000000..b07cd93 Binary files /dev/null and b/assets/textures/countdown/0075.png differ diff --git a/assets/textures/countdown/0076.png b/assets/textures/countdown/0076.png new file mode 100644 index 0000000..953d887 Binary files /dev/null and b/assets/textures/countdown/0076.png differ diff --git a/assets/textures/countdown/0077.png b/assets/textures/countdown/0077.png new file mode 100644 index 0000000..e1ccb51 Binary files /dev/null and b/assets/textures/countdown/0077.png differ diff --git a/assets/textures/countdown/0078.png b/assets/textures/countdown/0078.png new file mode 100644 index 0000000..7b24257 Binary files /dev/null and b/assets/textures/countdown/0078.png differ diff --git a/assets/textures/countdown/0079.png b/assets/textures/countdown/0079.png new file mode 100644 index 0000000..d8e3074 Binary files /dev/null and b/assets/textures/countdown/0079.png differ diff --git a/assets/textures/countdown/0080.png b/assets/textures/countdown/0080.png new file mode 100644 index 0000000..a5f3857 Binary files /dev/null and b/assets/textures/countdown/0080.png differ diff --git a/assets/textures/countdown/0081.png b/assets/textures/countdown/0081.png new file mode 100644 index 0000000..3b089b8 Binary files /dev/null and b/assets/textures/countdown/0081.png differ diff --git a/assets/textures/countdown/0082.png b/assets/textures/countdown/0082.png new file mode 100644 index 0000000..ecf7761 Binary files /dev/null and b/assets/textures/countdown/0082.png differ diff --git a/assets/textures/countdown/0083.png b/assets/textures/countdown/0083.png new file mode 100644 index 0000000..288177c Binary files /dev/null and b/assets/textures/countdown/0083.png differ diff --git a/assets/textures/dada.png b/assets/textures/dada.png deleted file mode 100644 index 773c20d..0000000 Binary files a/assets/textures/dada.png and /dev/null differ diff --git a/assets/textures/dodo.png b/assets/textures/dodo.png deleted file mode 100644 index 88f011c..0000000 Binary files a/assets/textures/dodo.png and /dev/null differ diff --git a/assets/textures/player_1.png b/assets/textures/player_1.png new file mode 100644 index 0000000..96c0be0 Binary files /dev/null and b/assets/textures/player_1.png differ diff --git a/assets/textures/player_2.png b/assets/textures/player_2.png new file mode 100644 index 0000000..4031917 Binary files /dev/null and b/assets/textures/player_2.png differ diff --git a/assets/unloaded.png b/assets/unloaded.png new file mode 100644 index 0000000..9072760 Binary files /dev/null and b/assets/unloaded.png differ diff --git a/assets/waiting.mp3 b/assets/waiting.mp3 new file mode 100644 index 0000000..f80c643 Binary files /dev/null and b/assets/waiting.mp3 differ diff --git a/src/main.py b/src/main.py index 3e3c67c..0189e8a 100644 --- a/src/main.py +++ b/src/main.py @@ -2,239 +2,9 @@ Module d'exemple de l'utilisation du moteur de jeu. """ -from engine import Scene, start_game -from engine.ecs import Entity, World -from engine.math import Vec2 -from plugins import defaults, physics -from plugins import render -from plugins.inputs import Held -from plugins.render import ( - Origin, - Position, - Scale, - SpriteBundle, -) -from plugins.timing import Delta +from engine import start_game +from plugins import defaults +from scenes import menu -def lol(a: Entity, b: Entity, simul: bool = False): - if Bounce in b: - speed = a[physics.Velocity].length - a[physics.Velocity] = a[physics.Velocity].normalized - a[physics.Velocity].y = (a[Position].y - b[Position].y) * 0.005 - a[physics.Velocity] = a[physics.Velocity].normalized * min( - (speed * 1.1), 1000.0 - ) - return True - - -class Bounce: - pass - - -def lol_simul(a: Entity, b: Entity): - lol(a, b, True) - return RightWall not in b - - -class Simulated: - pass - - -class Bar: - pass - - -class RightWall: - pass - - -class BallFollow(int): - pass - - -class Mine: - pass - - -def __initialize(world: World): - """ - Initialise les ressources pour le moteur de jeu. - """ - world.new_entity().set( - SpriteBundle( - "background.png", - -1, - scale=Vec2(render.WIDTH, render.HEIGHT), - ), - ) - # world.new_entity().set( - # SpriteBundle( - # "dodo.png", - # 0, - # position=Vec2(800, 500), - # origin=Vec2(0.5, 0.5), - # scale=Vec2(400, 300), - # ), - # physics.Solid(), - # ) - - world.new_entity().set( - SpriteBundle( - "dodo.png", - 0, - position=Vec2(100, 100), - origin=Vec2(0, 0), - scale=Vec2(render.WIDTH - 200, 10), - ), - physics.Solid(), - ) - - world.new_entity().set( - SpriteBundle( - "dodo.png", - 0, - position=Vec2(100, render.HEIGHT - 100), - origin=Vec2(0, 1), - scale=Vec2(render.WIDTH - 200, 10), - ), - physics.Solid(), - ) - - world.new_entity().set( - SpriteBundle( - "dodo.png", - 0, - position=Vec2(render.WIDTH - 100, 100), - origin=Vec2(1, 0), - scale=Vec2(10, render.HEIGHT - 200), - ), - physics.Solid(), - RightWall(), - ) - world.new_entity().set( - SpriteBundle( - "dodo.png", - 0, - position=Vec2(100, 100), - origin=Vec2(0, 0), - scale=Vec2(10, render.HEIGHT - 200), - ), - physics.Solid(), - ) - - world.new_entity().set( - SpriteBundle( - "dodo.png", - 0, - position=Vec2(render.WIDTH - 130, render.HEIGHT / 2), - origin=Vec2(0.5, 0.5), - scale=Vec2(10, 200), - ), - physics.Solid(), - Bar(), - Bounce(), - ) - - world.new_entity().set( - SpriteBundle( - "dodo.png", - 0, - position=Vec2(130, render.HEIGHT / 2), - origin=Vec2(0.5, 0.5), - scale=Vec2(10, 200), - ), - physics.Solid(), - Mine(), - Bounce(), - ) - - world.new_entity().set( - SpriteBundle( - "dada.png", - 1, - scale=Vec2(10), - position=Vec2(500, 500), - origin=Vec2(0.5, 0.5), - ), - physics.Velocity(Vec2(200, 100)), - physics.CollisionHandler(lol), - ) - - for i in range(20): - world.new_entity().set( - SpriteBundle( - "dodo.png", - 10, - scale=Vec2(10), - ), - physics.CollisionHandler(lol), - BallFollow(i + 1), - # physics.CollisionHandler(lol_simul), - ) - - -def __update(world: World): - """ - Test. - """ - for entity in world.query(Mine, Position): - if "z" in world[Held]: - entity[Position].y -= 300 * world[Delta] - if "s" in world[Held]: - entity[Position].y += 300 * world[Delta] - - ball = max( - world.query(Position, physics.Velocity, physics.CollisionHandler), - key=lambda e: e[Position].x, - ) - for bar in world.query(Bar): - bar.remove(physics.Solid) - entity = world.new_entity() - entity.set( - Position(ball[Position]), - Scale(ball[Scale]), - physics.Velocity(ball[physics.Velocity]), - Origin(ball[Origin]), - physics.CollisionHandler(lol_simul), - ) - physics.move_entity(entity, entity[physics.Velocity] * 500) - target = entity[Position].y - for bar in world.query(Bar): - diff = target - bar[Position].y - # bar[Position].y += (diff / abs(diff)) * 300 * world[Delta] - bar[Position].y += diff - bar.set(physics.Solid()) - entity.destroy() - - # for bar in world.query(Bar): - # bar.remove(physics.Solid) - for entity in world.query(BallFollow): - entity[Position] = Vec2(ball[Position]) - entity[physics.Velocity] = Vec2(ball[physics.Velocity]) - physics.move_entity(entity, entity[physics.Velocity] * entity[BallFollow] * 0.5) - del entity[physics.Velocity] - # for bar in world.query(Bar): - # bar.set(physics.Solid()) - - # ball.set(Simulated()) - # for entity in world.query(Bar): - # entity.remove(physics.Solid) - # last_position = Vec2(ball[Position]) - # last_velocity = Vec2(ball[physics.Velocity]) - # physics.move_entity(ball, ball[physics.Velocity] * 5000) - # ball[Position] = last_position - # ball[physics.Velocity] = last_velocity - # for entity in world.query(Bar): - # entity.set(physics.Solid()) - # ball.remove(Simulated) - - -MENU = Scene( - [__initialize], - [__update], - [], -) - - -start_game(defaults.PLUGIN, MENU) +start_game(defaults.PLUGIN, menu.MENU) diff --git a/src/save_main.py b/src/save_main.py new file mode 100644 index 0000000..3e3c67c --- /dev/null +++ b/src/save_main.py @@ -0,0 +1,240 @@ +""" +Module d'exemple de l'utilisation du moteur de jeu. +""" + +from engine import Scene, start_game +from engine.ecs import Entity, World +from engine.math import Vec2 +from plugins import defaults, physics +from plugins import render +from plugins.inputs import Held +from plugins.render import ( + Origin, + Position, + Scale, + SpriteBundle, +) +from plugins.timing import Delta + + +def lol(a: Entity, b: Entity, simul: bool = False): + if Bounce in b: + speed = a[physics.Velocity].length + a[physics.Velocity] = a[physics.Velocity].normalized + a[physics.Velocity].y = (a[Position].y - b[Position].y) * 0.005 + a[physics.Velocity] = a[physics.Velocity].normalized * min( + (speed * 1.1), 1000.0 + ) + return True + + +class Bounce: + pass + + +def lol_simul(a: Entity, b: Entity): + lol(a, b, True) + return RightWall not in b + + +class Simulated: + pass + + +class Bar: + pass + + +class RightWall: + pass + + +class BallFollow(int): + pass + + +class Mine: + pass + + +def __initialize(world: World): + """ + Initialise les ressources pour le moteur de jeu. + """ + world.new_entity().set( + SpriteBundle( + "background.png", + -1, + scale=Vec2(render.WIDTH, render.HEIGHT), + ), + ) + # world.new_entity().set( + # SpriteBundle( + # "dodo.png", + # 0, + # position=Vec2(800, 500), + # origin=Vec2(0.5, 0.5), + # scale=Vec2(400, 300), + # ), + # physics.Solid(), + # ) + + world.new_entity().set( + SpriteBundle( + "dodo.png", + 0, + position=Vec2(100, 100), + origin=Vec2(0, 0), + scale=Vec2(render.WIDTH - 200, 10), + ), + physics.Solid(), + ) + + world.new_entity().set( + SpriteBundle( + "dodo.png", + 0, + position=Vec2(100, render.HEIGHT - 100), + origin=Vec2(0, 1), + scale=Vec2(render.WIDTH - 200, 10), + ), + physics.Solid(), + ) + + world.new_entity().set( + SpriteBundle( + "dodo.png", + 0, + position=Vec2(render.WIDTH - 100, 100), + origin=Vec2(1, 0), + scale=Vec2(10, render.HEIGHT - 200), + ), + physics.Solid(), + RightWall(), + ) + world.new_entity().set( + SpriteBundle( + "dodo.png", + 0, + position=Vec2(100, 100), + origin=Vec2(0, 0), + scale=Vec2(10, render.HEIGHT - 200), + ), + physics.Solid(), + ) + + world.new_entity().set( + SpriteBundle( + "dodo.png", + 0, + position=Vec2(render.WIDTH - 130, render.HEIGHT / 2), + origin=Vec2(0.5, 0.5), + scale=Vec2(10, 200), + ), + physics.Solid(), + Bar(), + Bounce(), + ) + + world.new_entity().set( + SpriteBundle( + "dodo.png", + 0, + position=Vec2(130, render.HEIGHT / 2), + origin=Vec2(0.5, 0.5), + scale=Vec2(10, 200), + ), + physics.Solid(), + Mine(), + Bounce(), + ) + + world.new_entity().set( + SpriteBundle( + "dada.png", + 1, + scale=Vec2(10), + position=Vec2(500, 500), + origin=Vec2(0.5, 0.5), + ), + physics.Velocity(Vec2(200, 100)), + physics.CollisionHandler(lol), + ) + + for i in range(20): + world.new_entity().set( + SpriteBundle( + "dodo.png", + 10, + scale=Vec2(10), + ), + physics.CollisionHandler(lol), + BallFollow(i + 1), + # physics.CollisionHandler(lol_simul), + ) + + +def __update(world: World): + """ + Test. + """ + for entity in world.query(Mine, Position): + if "z" in world[Held]: + entity[Position].y -= 300 * world[Delta] + if "s" in world[Held]: + entity[Position].y += 300 * world[Delta] + + ball = max( + world.query(Position, physics.Velocity, physics.CollisionHandler), + key=lambda e: e[Position].x, + ) + for bar in world.query(Bar): + bar.remove(physics.Solid) + entity = world.new_entity() + entity.set( + Position(ball[Position]), + Scale(ball[Scale]), + physics.Velocity(ball[physics.Velocity]), + Origin(ball[Origin]), + physics.CollisionHandler(lol_simul), + ) + physics.move_entity(entity, entity[physics.Velocity] * 500) + target = entity[Position].y + for bar in world.query(Bar): + diff = target - bar[Position].y + # bar[Position].y += (diff / abs(diff)) * 300 * world[Delta] + bar[Position].y += diff + bar.set(physics.Solid()) + entity.destroy() + + # for bar in world.query(Bar): + # bar.remove(physics.Solid) + for entity in world.query(BallFollow): + entity[Position] = Vec2(ball[Position]) + entity[physics.Velocity] = Vec2(ball[physics.Velocity]) + physics.move_entity(entity, entity[physics.Velocity] * entity[BallFollow] * 0.5) + del entity[physics.Velocity] + # for bar in world.query(Bar): + # bar.set(physics.Solid()) + + # ball.set(Simulated()) + # for entity in world.query(Bar): + # entity.remove(physics.Solid) + # last_position = Vec2(ball[Position]) + # last_velocity = Vec2(ball[physics.Velocity]) + # physics.move_entity(ball, ball[physics.Velocity] * 5000) + # ball[Position] = last_position + # ball[physics.Velocity] = last_velocity + # for entity in world.query(Bar): + # entity.set(physics.Solid()) + # ball.remove(Simulated) + + +MENU = Scene( + [__initialize], + [__update], + [], +) + + +start_game(defaults.PLUGIN, MENU) diff --git a/src/scenes/game.py b/src/scenes/game.py new file mode 100644 index 0000000..81f7596 --- /dev/null +++ b/src/scenes/game.py @@ -0,0 +1,347 @@ +from enum import Enum +from engine import Plugin, Scene +from engine.ecs import Entity, World +from engine.math import Vec2 +from plugins import render +from plugins.inputs import Held +from plugins.timing import Delta +from plugins.sound import Sound +from plugins.render import Origin, Position, Scale, SpriteBundle, Text, TextBundle + + +class GameMode(Enum): + """ + Definit un ressource represantant le mode de jeu actuel. + """ + + ONE = 0 + TWO = 1 + + +class Player: + """ + Composant qui represente les joueurs. + """ + + +class Bot: + """ + Composant qui represente le bot. + """ + + +class UpKey(str): + """ + Composant qui indique la touche pour faire monter le joueur + """ + + +class DownKey(str): + """ + Composant qui indique la touche pour faire descender le joueur + """ + + +class Ball: + """ + Composant qui represente la balle. + """ + + +class Speed(int): + """ + Composant qui represente la vitesse de l'entité. + """ + + +class Boxed: + """ + Composant qui definit si l'entitée doit rebondir + """ + + +class Velocity(Vec2): + """ + Composant qui definit le vecteur vitesse d'une entité + """ + + +class Blocked: + """ + Composant qui indique si l'entité est blockée par quelque chose dans son mouvement + """ + + +class ScorePlayer1(int): + """ + Ressource qui represente le score du joueur 1 + """ + + +class ScorePlayer2(int): + """ + Ressource qui represente le score du joueur 2 + """ + + +def __spawn_elements(world: World): + """ + Ajoute les éléments du menu dans le monde. + """ + + world.set(ScorePlayer1(0), ScorePlayer2(0)) + + world.new_entity().set(SpriteBundle("background.jpg", -5)) + world.new_entity().set( + SpriteBundle(("player_1.png"), 0, Vec2(100, 200), Vec2(44, 250), Vec2(0.5)), + Player(), + UpKey("z"), + DownKey("s"), + Speed(1000), + Boxed(), + ) + + if world[GameMode] == GameMode.TWO: + world.new_entity().set( + SpriteBundle( + ("player_2.png"), 0, Vec2(1340, 200), Vec2(44, 250), Vec2(0.5) + ), + Player(), + UpKey("up"), + DownKey("down"), + Speed(1000), + Boxed(), + ) + + else: + world.new_entity().set( + SpriteBundle( + ("player_2.png"), 0, Vec2(1340, 200), Vec2(44, 250), Vec2(0.5) + ), + Bot(), + smooth.Target(Vec2(1340, 200)), + Player(), + smooth.Speed(3), + Boxed(), + ) + + world.new_entity().set( + TextBundle( + f"{world[ScorePlayer1]} - {world[ScorePlayer2]}", + position=Vec2(render.WIDTH / 2, 100), + order=5, + origin=Vec2(0.5), + ), + ) + + __spawn_animation(world) + __spawn_ball(world) + + +def __spawn_ball(world: World): + world.new_entity().set( + SpriteBundle( + ("ball.png"), + 2, + Vec2(render.WIDTH / 2, render.HEIGHT / 2), + origin=Vec2(0.5), + ), + Ball(), + Velocity(Vec2(200, 30)), + Boxed(), + ) + + +def __after_anim(world: World, entity: Entity): + entity.destroy() + __spawn_ball(world) + + +def __move_up(world: World): + """ + TODO + """ + held = world[Held] + for entity in world.query(UpKey): + if entity[UpKey] in held: + entity[Position] = Vec2( + entity[Position].x, + (entity[Position].y - entity[Speed] * world[Delta]), + ) + + +def __move_down(world: World): + """ + TODO + """ + held = world[Held] + for entity in world.query(DownKey): + if entity[DownKey] in held: + entity[Position] = Vec2( + entity[Position].x, + (entity[Position].y + entity[Speed] * world[Delta]), + ) + + +def __box(world: World): + """ + + bah box y vérifie si la prochaine j'ai oublié la suite ... si le Y balh position executé haut bah ruien pour + NIQUEZ VOUS + """ + gap = 50 + for entity in world.query(Boxed): + diff_up = gap - entity[Position].y + diff_down = entity[Position].y - (render.HEIGHT - gap) + + # Top + if entity[Position].y - (entity[Scale].y * entity[Origin].y) < gap: + entity[Position].y += entity[Scale].y * entity[Origin].y + diff_up + entity.set(Blocked()) + + # Bottom + elif entity[Position].y + (entity[Scale].y * entity[Origin].y) > ( + render.HEIGHT - gap + ): + entity[Position].y -= entity[Scale].y * entity[Origin].y + diff_down + entity.set(Blocked()) + else: + if Blocked in entity: + entity.remove(Blocked) + + +def __ball_movement(world: World): + for ball in world.query(Ball, Velocity): + if Blocked in ball: + ball[Velocity].y = -ball[Velocity].y + ball.remove(Blocked) + world.new_entity().set(Sound(("bound.mp3"))) + + for player in world.query(Player): + if __collision(ball, player): + if (render.WIDTH / 2 - ball[Position].x) * ball[Velocity].x < 0: + speed = ball[Velocity].length + ball[Velocity].x = -ball[Velocity].x + ball[Velocity].y = ball[Position].y - player[Position].y + ball[Velocity] = ball[Velocity].normalized * min( + (speed + 100), 2000 + ) + world.new_entity().set(Sound(("bound.mp3"))) + + ball[Position] += ball[Velocity] * world[Delta] + + +def __collision(ent1: Entity, ent2: Entity) -> bool: + origin1 = ent1[Origin] + position1 = ent1[Position] + largeur1 = ent1[Scale].x + hauteur1 = ent1[Scale].y + + origin2 = ent2[Origin] + position2 = ent2[Position] + largeur2 = ent2[Scale].x + hauteur2 = ent2[Scale].y + + left1, top1, right1, bottom1 = ( + position1.x - largeur1 * origin1.x, + position1.y - hauteur1 * origin1.y, + position1.x + largeur1 * origin1.x, + position1.y + hauteur1 * origin1.y, + ) + + left2, top2, right2, bottom2 = ( + position2.x - largeur2 * origin2.x, + position2.y - hauteur2 * origin2.y, + position2.x + largeur2 * origin2.x, + position2.y + hauteur2 * origin2.y, + ) + + return left1 < right2 and right1 > left2 and top1 < bottom2 and bottom1 > top2 + + +def __goal(world: World): + for ball in world.query(Ball): + if ball[Position].x - (ball[Scale].x * ball[Origin].x) < 0: + ball.destroy() + world[ScorePlayer2] += 1 + if len(world.query(Ball)) == 0: + __spawn_animation(world) + + elif ball[Position].x + (ball[Scale].x * ball[Origin].x) > render.WIDTH: + ball.destroy() + world[ScorePlayer1] += 1 + if len(world.query(Ball)) == 0: + __spawn_animation(world) + + +def __update_score(world: World): + for text in world.query(TextBundle): + text[Text] = f"{world[ScorePlayer1]} - {world[ScorePlayer2]}" + + +def __spawn_animation(world: World): + world.new_entity().set(Animation("countdown", 40, callback=__after_anim)) + + +def __update_bot_move(world: World): + bot = world.query(Bot).pop() + balls = world.query(Ball) + if balls == set(): + return + ball = balls.pop() + pos: Vec2 = Vec2(ball[Position]) + velocity = Vec2(ball[Velocity]) + + # calcul de la position de la balle avec la velocité + if velocity.x > 0: + while pos.x < bot[Position].x: + pos += velocity * 0.01 + + # rebond + gap = 50 + if pos.y - (ball[Scale].y * ball[Origin].y) < gap: + velocity.y = -velocity.y + + elif pos.y + (ball[Scale].y * ball[Origin].y) > (render.HEIGHT - gap): + velocity.y = -velocity.y + target = pos.y + + bot[smooth.Target].y = target + + +__SCENE = Scene( + [__spawn_elements], + [ + __goal, + __move_up, + __move_down, + __box, + __ball_movement, + __update_score, + ], + [], +) + + +ONE_PLAYER = ( + Plugin( + # Modifie le GameMode en ONE a l'initialisation de la scene + [lambda world: world.set(GameMode.ONE)], + [ + __update_bot_move, + ], + [], + ) + + __SCENE +) + + +TWO_PLAYER = ( + Plugin( + # Modifie le GameMode en TWO a l'initialisation de la scene + [lambda world: world.set(GameMode.TWO)], + [], + [], + ) + + __SCENE +) diff --git a/src/scenes/menu.py b/src/scenes/menu.py new file mode 100644 index 0000000..3d588a5 --- /dev/null +++ b/src/scenes/menu.py @@ -0,0 +1,70 @@ +""" +La scène du menu principal du jeu. + +Dans cette scène nous pouvons choisir le mode de jeu. +""" +from plugins.sound import Sound +from engine import CurrentScene, KeepAlive, Scene +from engine.ecs import Entity, World +from engine.math import Vec2 +from plugins import render +from plugins.click import Clickable +from plugins.hover import HoveredTexture +from plugins.render import SpriteBundle +from scenes import game + + +def __create_button(world: World, i: int, name: str): + """ + Ajoute un bouton au monde. + """ + world.new_entity().set( + SpriteBundle( + f"button_{name}.png", + position=Vec2(450 + 540 * i, render.HEIGHT / 2), + order=1, + origin=Vec2(0.5), + ), + HoveredTexture( + f"button_{name}.png", + f"button_{name}_hover.png", + ), + Clickable(lambda world, entity: __on_click_butons(world, entity, name)), + ) + + +def __on_click_butons(world: World, _entity: Entity, name: str): + """ + Fonction qui s'execute quand on clique sur un bouton. + """ + match name: + case "one_player": + # TODO + world[CurrentScene] = game.ONE_PLAYER + case "two_player": + # TODO + world[CurrentScene] = game.TWO_PLAYER + case _: + pass + world.new_entity().set(KeepAlive(), Sound("click.wav")) + + +def __spawn_elements(world: World): + """ + Ajoute les éléments du menu dans le monde. + """ + + world.new_entity().set(Sound("music.mp3"), KeepAlive()) + + world.new_entity().set(SpriteBundle("background_menu.png", -5)) + + scenes_name = ["one_player", "two_player"] + for i, name in enumerate(scenes_name): + __create_button(world, i, name) + + +MENU = Scene( + [__spawn_elements], + [], + [], +)