commit 1b11f5ffe30daca3597ff951308fccfc91183efc Author: yannickreiss Date: Sat Aug 24 18:04:47 2024 +0200 Just a bolt bolting around in space diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5866d7b --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/obj/ +/bin/ +/alire/ +/config/ diff --git a/alire.toml b/alire.toml new file mode 100644 index 0000000..fcc0c94 --- /dev/null +++ b/alire.toml @@ -0,0 +1,15 @@ +name = "ballon_bounce" +description = "A little game like pong" +version = "0.1.0-dev" + +authors = ["Nicki"] +maintainers = ["Nicki "] +maintainers-logins = ["yannickreiss"] +licenses = "MIT" +website = "" +tags = ["game"] + +executables = ["ballon_bounce"] + +[[depends-on]] +asfml = "^2.6.1" diff --git a/ballon_bounce.gpr b/ballon_bounce.gpr new file mode 100644 index 0000000..c9c4b86 --- /dev/null +++ b/ballon_bounce.gpr @@ -0,0 +1,22 @@ +with "config/ballon_bounce_config.gpr"; +project Ballon_Bounce is + + for Source_Dirs use ("src/", "config/"); + for Object_Dir use "obj/" & Ballon_Bounce_Config.Build_Profile; + for Create_Missing_Dirs use "True"; + for Exec_Dir use "bin"; + for Main use ("ballon_bounce.adb"); + + package Compiler is + for Default_Switches ("Ada") use Ballon_Bounce_Config.Ada_Compiler_Switches; + end Compiler; + + package Binder is + for Switches ("Ada") use ("-Es"); -- Symbolic traceback + end Binder; + + package Install is + for Artifacts (".") use ("share"); + end Install; + +end Ballon_Bounce; diff --git a/img/background.jpg b/img/background.jpg new file mode 100644 index 0000000..0b105a5 Binary files /dev/null and b/img/background.jpg differ diff --git a/img/background_big.jpg b/img/background_big.jpg new file mode 100644 index 0000000..5d0683d Binary files /dev/null and b/img/background_big.jpg differ diff --git a/img/ball.png b/img/ball.png new file mode 100644 index 0000000..4e59c36 Binary files /dev/null and b/img/ball.png differ diff --git a/img/ball_big.png b/img/ball_big.png new file mode 100644 index 0000000..3df25ac Binary files /dev/null and b/img/ball_big.png differ diff --git a/img/pipe.png b/img/pipe.png new file mode 100644 index 0000000..d91989c Binary files /dev/null and b/img/pipe.png differ diff --git a/src/ballon_bounce.adb b/src/ballon_bounce.adb new file mode 100644 index 0000000..9c8c560 --- /dev/null +++ b/src/ballon_bounce.adb @@ -0,0 +1,136 @@ +with Sf; +with Sf.Graphics.RenderWindow; use Sf.Graphics.RenderWindow; +with Sf.Graphics.Color; use Sf.Graphics.Color; +with Sf.Graphics.Texture; use Sf.Graphics.Texture; +with Sf.Graphics.Sprite; use Sf.Graphics.Sprite; + +with Sf.Window.Event; use Sf.Window.Event; +with Sf.Window.Keyboard; use Sf.Window.Keyboard; + +with Sf.System.Vector2; use Sf.System.Vector2; +with Sf.System.Clock; use Sf.System.Clock; +with Sf.System.Time; use Sf.System.Time; + +use Sf.Graphics; +use Sf.Window; +use Sf.System; +use Sf; + +with Ada.Text_IO; use Ada.Text_IO; + +procedure Ballon_Bounce is + + -- Window structure + Width : sfUint32 := 1_000; + Height : sfUint32 := 750; + Width_Float : Float := 1_000.0; + Height_Float : Float := 750.0; + Main_Window : sfRenderWindow_Ptr := + RenderWindow.create ((Width, Height, 32), "Balloon Bouncer!"); + Event_Hook : Event.sfEvent; + + -- Setup the background + Background_Texture : sfTexture_Ptr := + Texture.createFromFile ("img/background.jpg"); + Background : sfSprite_Ptr := Sprite.create; + + -- Set platform + Platform_Texture : sfTexture_Ptr := + Texture.createFromFile ("img/pipe.png"); + Platform : sfSprite_Ptr := Sprite.create; + Platform_Width : Float := 250.0; + Platform_Height : Float := 50.0; + + -- Set Ball + type Vector2 is record + X : Float; + Y : Float; + end record; + Ball_Texture : sfTexture_Ptr := Texture.createFromFile ("img/ball.png"); + Ball : sfSprite_Ptr := Sprite.create; + Ball_Size : Float := 93.0; + + -- Game Coordinates + -- subtype Platform_X_Position is + -- Float range 0.0 .. (Width_Float - Platform_Width); + Platform_X : Float := 0.0; + Platform_Y : Float := Height_Float - Platform_Height; + Platform_Speed : Float := 8.0; + Ball_X : Float := Width_Float / 2.0; + Ball_Y : Float := Height_Float / 2.0; + Ball_Direction : Vector2 := (1.0, -1.0); + Ball_Speed : Float := 5.0; + +begin + RenderWindow.setFramerateLimit (Main_Window, 30); + + -- Background initialization + Sprite.setTexture (Background, Background_Texture); + Sprite.setPosition (Background, (Float (0), Float (0))); + + -- Platform and Ball texture binding + Sprite.setTexture (Platform, Platform_Texture); + Sprite.setTexture (Ball, Ball_Texture); + + while RenderWindow.isOpen (Main_Window) = sfTrue loop + while RenderWindow.PollEvent (Main_Window, event => Event_Hook) = + sfTrue + loop + case Event_Hook.eventType is + when Event.sfEvtClosed => + RenderWindow.Close (Main_Window); + when Event.sfEvtKeyPressed => + case Event_Hook.key.code is + when Keyboard.sfKeyEscape => + RenderWindow.Close (Main_Window); + when Keyboard.sfKeyA => + if Platform_X >= 0.0 then + Platform_X := Platform_X - Platform_Speed; + end if; + when Keyboard.sfKeyD => + if Platform_X <= (Width_Float - Platform_Width) + then + Platform_X := Platform_X + Platform_Speed; + end if; + when others => + null; + end case; + when others => + null; + end case; + end loop; + + -- BEGIN: Computing area + Ball_X := Ball_X + (Ball_Direction.X * Ball_Speed); + Ball_Y := Ball_Y + (Ball_Direction.Y * Ball_Speed); + + if (Ball_X <= 0.0) or ((Ball_X + Ball_Size) >= Width_Float) then + Ball_Direction.X := Ball_Direction.X * (-1.0); + end if; + + if (Ball_Y <= 0.0) or ((Ball_Y + Ball_Size) >= Height_Float) then + Ball_Direction.Y := Ball_Direction.Y * (-1.0); + end if; + + -- END: Computing area + + -- BEGIN: Update states + Sprite.setPosition (Platform, (Platform_X, Platform_Y)); + Sprite.setPosition (Ball, (Ball_X, Ball_y)); + + -- END: Update states + + RenderWindow.clear (Main_Window, Color.sfWhite); + + -- BEGIN: Draw area + RenderWindow.drawSprite (Main_Window, Background); + RenderWindow.drawSprite (Main_Window, Platform); + RenderWindow.drawSprite (Main_Window, Ball); + + -- END: Draw area + + RenderWindow.display (Main_Window); + + end loop; + +end Ballon_Bounce;