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/plugins/display.py b/src/plugins/display.py index cc0c1c2..220444b 100644 --- a/src/plugins/display.py +++ b/src/plugins/display.py @@ -13,7 +13,7 @@ def __initialize(_world: World): Initialise pygame et les ressources pour la gestion de la fenetre. """ pygame.init() - pygame.display.set_caption("Guess The Number") + pygame.display.set_caption("Ponguito") pygame.display.set_mode((800, 600), pygame.RESIZABLE) diff --git a/src/scenes/game.py b/src/scenes/game.py new file mode 100644 index 0000000..1f4dbff --- /dev/null +++ b/src/scenes/game.py @@ -0,0 +1,412 @@ +""" +Le jeux principale. +""" + +from enum import Enum +from engine import Plugin, Scene +from engine.ecs import Entity, World +from engine.math import Vec2 +from plugins import physics, render +from plugins.inputs import Held +from plugins.render import ( + Origin, + Position, + Scale, + SpriteBundle, + TextBundle, + Text, + TextSize, +) +from plugins.timing import Delta, Time +import random + + +class GameMode(Enum): + """ + Ressource qui definit le game mode choisi par l'utilisateur. + """ + + ONE = 0 + TWO = 1 + + +class RightWall: + """ + Composant qui marque une entité comme etant le mur de droite. + """ + + +class LeftWall: + """ + Composant qui marque une entité comme etant le mur de gauche. + """ + + +class Player1: + """ + Composant qui marque une entité comme etant le joeuur 1. + """ + + +class Player2: + """ + Composant qui marque une entité comme etant le joeuur 2. + """ + + +class Ball: + """ + Composant qui marque une entité comme etant une balle. + """ + + +class Bounce: + """ + Composant qui marque une entité qui peux faire rebondir + """ + + +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 Speed(int): + """ + Composant qui represente la vitesse de l'entité. + """ + + +class Player1Score(int): + """ + Ressource qui represente le score du joueur 1. + """ + + +class Player2Score(int): + """ + Ressource qui represente le score du joueur 2. + """ + + +class Score: + """ + Composant qui marque l'entité comme étant l'affichage du score. + """ + + +class StartAnimation(float): + """ + Composant qui represente un le moment auxquel on a lancé l'animation du compte a rebours + """ + + +def __spawn_ellements(world: World): + """ + La fonction permet de initializer les ellements de la scene. + """ + + world.new_entity().set(SpriteBundle(("background.jpg"), -5)) + + # Mon mur de gauche + world.new_entity().set( + Origin(Vec2(1, 0)), + Scale(Vec2(10, render.HEIGHT)), + Position(Vec2(70, 0)), + physics.Solid(), + LeftWall(), + physics.CollisionHandler(__bounce_on_left_wall), + ) + + # Mon mur du RN + world.new_entity().set( + Origin(Vec2(0, 0)), + Scale(Vec2(10, render.HEIGHT)), + Position(Vec2(render.WIDTH - 70, 0)), + physics.Solid(), + RightWall(), + physics.CollisionHandler(__bounce_on_right_wall), + ) + + # Mon mur du bas + world.new_entity().set( + Origin(Vec2(0, 0)), + Scale(Vec2(render.WIDTH, 10)), + Position(Vec2(0, render.HEIGHT)), + physics.Solid(), + ) + + # Mon mur du haut + world.new_entity().set( + Origin(Vec2(0, 1)), + Scale(Vec2(render.WIDTH, 10)), + Position(Vec2(0, 0)), + physics.Solid(), + ) + + # Joueur 1 + world.new_entity().set( + SpriteBundle( + "player_1.png", + 0, + Vec2(100, render.HEIGHT / 2), + Vec2(44, 250), + Vec2(0.5), + ), + physics.Solid(), + Player1(), + UpKey("z"), + DownKey("s"), + Speed(1000), + ) + + # Joueur 2 + world.new_entity().set( + SpriteBundle( + "player_2.png", + 0, + Vec2(render.WIDTH - 100, render.HEIGHT / 2), + Vec2(44, 250), + Vec2(0.5), + ), + physics.Solid(), + Player2(), + (UpKey("up"), DownKey("down"), Speed(1000)) + if world[GameMode] == GameMode.TWO + else None, + ) + + __spawn_ball(world) + + # Initialisation des scores + world.set(Player1Score(0), Player2Score(0)) + + world.new_entity().set( + TextBundle( + "0 - 0", + 10, + 50, + position=Vec2(render.WIDTH / 2, 75), + origin=Vec2(0.5), + ), + Score(), + ) + + +def __spawn_ball(world: World): + """ + Fonction qui fait apparaitre une balle avec une velocitée aleatoire + """ + # random velocité + velocity = Vec2(2 * random.randint(100, 200), random.randint(100, 200)) + + # mouvement a droite ou a gauche + if random.randint(0, 1) == 0: + velocity.x = -velocity.x + + # Balle + world.new_entity().set( + SpriteBundle( + "ball.png", + 0, + Vec2(render.WIDTH / 2, render.HEIGHT / 2), + Vec2(40, 40), + Vec2(0.5), + ), + Ball(), + # + physics.Velocity(velocity), + physics.CollisionHandler(__bounce_on_player), + ) + + +def __bounce_on_player(a: Entity, b: Entity): + """ + Fonction qui decrit se qui se passe lorque la ball entre en collision avec un joueur + """ + if Player1 in b or Player2 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 + + +def __bounce_on_player_simul(a: Entity, b: Entity): + """ + Fonction qui fait une simulation de la balle + """ + __bounce_on_player(a, b) + return RightWall not in b + + +def __bounce_on_left_wall(a: Entity, b: Entity): + """ + Fonction qui decrit se qui se passe lorque la ball entre en collision avec le mur de gauche + """ + if Ball in b: + world = a.world + world[Player2Score] += 1 + __update_scores(world, b) + return False + return True + + +def __bounce_on_right_wall(a: Entity, b: Entity): + """ + Fonction qui decrit se qui se passe lorque la ball entre en collision avec le mur de droite + """ + if Ball in b: + world = a.world + world[Player1Score] += 1 + __update_scores(world, b) + return False + return True + + +def __move_up(world: World): + """ + La fonction permet de faire bouger les entitees vers le haut. + """ + 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): + """ + La fonction permet de faire bouger les entitees vers le bas. + """ + 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 __update_move(world: World): + """ + La fontion permet de faire bouger les entitees vers le haut ou vers le bas. + """ + __move_down(world) + __move_up(world) + + +def _update_bot(world: World): + """ + Fonction qui update les mouvement du bot + """ + ball_query = world.query(Position, physics.Velocity, physics.CollisionHandler) + if ball_query == set(): + return None + + ball = max(ball_query, key=lambda entity: entity[Position].y) + for bar in world.query(Player2): + 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(__bounce_on_player_simul), + ) + physics.move_entity(entity, entity[physics.Velocity] * 500) + target = entity[Position].y + for bar in world.query(Player2): + diff = target - bar[Position].y + + if abs(diff) > 10: + bar[Position].y += (diff / abs(diff)) * 300 * world[Delta] + # bar[Position].y += diff + bar.set(physics.Solid()) + entity.destroy() + + +def __update_scores(world: World, ball: Entity): + """ + La fontion permet de mettre a jour les scores. + """ + + # met a jour le score du joueur 1 et 2 + for panel in world.query(Score): + panel[Text] = f"{world[Player1Score]} - {world[Player2Score]}" + + ball.destroy() + + if world.query(Ball) == set(): + __animation(world, 3) + + +def __animation(world: World, number: int): + world.new_entity().set( + TextBundle( + str(number), + 2, + 5000, + position=Vec2(render.WIDTH / 2, render.HEIGHT / 2), + origin=Vec2(0.5), + ), + StartAnimation(world[Time]), + ) + + +def __update_animation(world: World): + """ + Fonction qui permet de mettre a jour l'animation du compte a rebours. + """ + + for animation in world.query(StartAnimation): + time = world[Time] - animation[StartAnimation] + + if animation[TextSize] > 700: + animation[TextSize] = 5000 / (25 * time + 1) + else: + animation[TextSize] -= 1000 * world[Delta] + if animation[TextSize] < 0: + if int(animation[Text]) > 1 or "space" in world[Held]: + __animation(world, int(animation[Text]) - 1) + else: + # creation de la balle + __spawn_ball(world) + animation.destroy() + + +__SCENE = Scene( + [__spawn_ellements], + [__update_move, __update_animation], + [], +) + +ONE_PLAYER = ( + Plugin( + [lambda world: world.set(GameMode.ONE)], + [_update_bot], + [], + ) + + __SCENE +) + +TWO_PLAYER = ( + Plugin( + [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..cd7bb9b --- /dev/null +++ b/src/scenes/menu.py @@ -0,0 +1,68 @@ +""" +La scène du menu principal du jeu. + +Dans cette scène nous pouvons choisir le mode de jeu. +""" +from plugins.sound import Loop, 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": + world[CurrentScene] = game.ONE_PLAYER + case "two_player": + 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(), Loop()) + + 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], + [], + [], +)