Just a bolt bolting around in space
This commit is contained in:
commit
1b11f5ffe3
|
@ -0,0 +1,4 @@
|
|||
/obj/
|
||||
/bin/
|
||||
/alire/
|
||||
/config/
|
|
@ -0,0 +1,15 @@
|
|||
name = "ballon_bounce"
|
||||
description = "A little game like pong"
|
||||
version = "0.1.0-dev"
|
||||
|
||||
authors = ["Nicki"]
|
||||
maintainers = ["Nicki <yannick.reiss@nickr.eu>"]
|
||||
maintainers-logins = ["yannickreiss"]
|
||||
licenses = "MIT"
|
||||
website = ""
|
||||
tags = ["game"]
|
||||
|
||||
executables = ["ballon_bounce"]
|
||||
|
||||
[[depends-on]]
|
||||
asfml = "^2.6.1"
|
|
@ -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;
|
Binary file not shown.
After Width: | Height: | Size: 319 KiB |
Binary file not shown.
After Width: | Height: | Size: 287 KiB |
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
Binary file not shown.
After Width: | Height: | Size: 119 KiB |
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
|
@ -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;
|
Loading…
Reference in New Issue