aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--game.adb5
-rw-r--r--game.ads8
-rw-r--r--graphics.adb60
-rw-r--r--graphics.ads33
-rw-r--r--main.adb47
-rw-r--r--snake.gpr2
6 files changed, 119 insertions, 36 deletions
diff --git a/game.adb b/game.adb
index e69de29..cd96177 100644
--- a/game.adb
+++ b/game.adb
@@ -0,0 +1,5 @@
+with Game;
+
+package body Game is
+ null
+end Game;
diff --git a/game.ads b/game.ads
index e69de29..a58a59f 100644
--- a/game.ads
+++ b/game.ads
@@ -0,0 +1,8 @@
+package Game is
+
+ type T_Game is record
+ null;
+ end record;
+
+
+end Game;
diff --git a/graphics.adb b/graphics.adb
index e69de29..2cdea69 100644
--- a/graphics.adb
+++ b/graphics.adb
@@ -0,0 +1,60 @@
+with Ada.Text_IO;
+use Ada.Text_IO;
+
+with Graphics;
+use Graphics;
+
+with SDL;
+with SDL.Timers;
+with SDL.Events;
+with SDL.Events.Events;
+with SDL.Video.Windows;
+with SDL.Video.Windows.Makers;
+with SDL.Video.Renderers;
+with SDL.Video.Renderers.Makers;
+
+package body Graphics is
+
+ procedure Init(state: out T_State) is
+ begin
+ if not SDL.Initialise then
+ Put("Error");
+ end if;
+ SDL.Video.Windows.Makers.Create(state.window, WINDOW_TITLE, WINDOW_X, WINDOW_Y,
+ WINDOW_WIDTH, WINDOW_HEIGHT);
+ SDL.Video.Renderers.Makers.Create(state.renderer, state.window);
+ state.running := true;
+ end Init;
+
+ procedure Quit(state: T_State) is
+ begin
+ SDL.Finalise;
+ end Quit;
+
+ procedure Run(state: in out T_State) is
+ begin
+ while state.running loop
+ Event_Handler(state);
+ Update(state);
+ SDL.Timers.Wait_Delay(3);
+ end loop;
+ end Run;
+
+ procedure Event_Handler(state: in out T_State) is
+ event: SDL.Events.Events.Events;
+ begin
+ while SDL.Events.Events.Poll(event) loop
+ case event.common.event_type is
+ when SDL.Events.Quit => state.running := false;
+ when others => null;
+ end case;
+ end loop;
+ null;
+ end Event_Handler;
+
+ procedure Update(state: T_State) is
+ begin
+ null;
+ end Update;
+
+end Graphics;
diff --git a/graphics.ads b/graphics.ads
index 78a4542..1450381 100644
--- a/graphics.ads
+++ b/graphics.ads
@@ -1,17 +1,38 @@
with SDL;
-with Game;
+-- with Game;
+-- use Game;
+with SDL.Video.Windows.Makers;
+use SDL.Video.Windows.Makers;
+
+with SDL.Video.Renderers.Makers;
+use SDL.Video.Renderers.Makers;
+
+with SDL.Video.Renderers;
+use SDL.Video.Renderers;
+
+with SDL.Video.Windows;
+use SDL.Video.Windows;
package Graphics is
+ WINDOW_TITLE: constant String := "Snake";
+ WINDOW_X: constant SDL.Natural_Coordinate := 10;
+ WINDOW_Y: constant SDL.Natural_Coordinate := 10;
+ WINDOW_WIDTH: constant SDL.Positive_Dimension := 400;
+ WINDOW_HEIGHT: constant SDL.Positive_Dimension := 400;
+
type T_State is record
running: Boolean;
- window: SDL.Window;
- renderer: SDL.Renderer;
- game: T_Game;
+ -- game: T_Game;
+ window: SDL.Video.Windows.Window;
+ renderer: SDL.Video.Renderers.Renderer;
end record;
- procedure EventHandler(
-
+ procedure Init(state: out T_State);
+ procedure Quit(state: T_State);
+ procedure Run(state: in out T_State);
+ procedure Event_Handler(state: in out T_State);
+ procedure Update(state: T_State);
end Graphics;
diff --git a/main.adb b/main.adb
index e1e9d78..65c37f1 100644
--- a/main.adb
+++ b/main.adb
@@ -1,36 +1,25 @@
with Ada.Text_IO;
use Ada.Text_IO;
-with SDL;
-with SDL.Error;
-with SDL.Video.Renderers;
-with SDL.Video.Windows;
-
-with SDL.Timers;
-
-with SDL.Video.Windows.Makers;
-use SDL.Video.Windows.Makers;
-
-with SDL.Video.Renderers.Makers;
-use SDL.Video.Renderers.Makers;
-
+with Graphics;
+use Graphics;
procedure Main is
- window: SDL.Video.Windows.Window;
- renderer: SDL.Video.Renderers.Renderer;
+ state: T_State;
begin
- if not SDL.Initialise then
- Put(SDL.Error.Get);
- return;
- end if;
-
- Create(window, "bonjour", 10, 10, 400, 400);
- Create(renderer, window);
-
- SDL.Timers.Wait_Delay(1000);
-
-
-
-
- SDL.Finalise;
+ -- SDL.Initialise;
+ -- Create(window, "bonjour", 10, 10, 400, 400);
+ -- Create(renderer, window);
+ -- Set_Draw_Colour(renderer, (0, 0, 0, 255));
+ -- Clear(renderer);
+ -- Set_Draw_Colour(renderer, (255, 255, 255, 255));
+ -- r := (10, 10, 100, 100);
+ -- Fill(renderer, r);
+ -- Present(renderer);
+ -- SDL.Timers.Wait_Delay(1000);
+ -- SDL.Finalise;
+ --
+ Init(state);
+ Run(state);
+ Quit(state);
end Main;
diff --git a/snake.gpr b/snake.gpr
index 59af38e..d3f1454 100644
--- a/snake.gpr
+++ b/snake.gpr
@@ -2,6 +2,6 @@ with "./vendor/sdlada/share/gpr/sdlada.gpr";
project Snake is
for Source_Dirs use ("./");
- for Source_Files use ("main.adb");
+ for Source_Files use ("main.adb", "graphics.adb", "game.adb");
for Main use ("main.adb");
end Snake;