diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-12-07 16:59:17 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-12-07 16:59:17 +0100 |
| commit | acfbdcefdbc60e97a9e3447afed204b3e40d991e (patch) | |
| tree | 8bd7db838cb47a39f985fd6a5be163fbe65a7a48 | |
| parent | 9b47ade2394becce870d195f198c235b3275ed34 (diff) | |
| download | snake-acfbdcefdbc60e97a9e3447afed204b3e40d991e.tar.gz snake-acfbdcefdbc60e97a9e3447afed204b3e40d991e.tar.bz2 snake-acfbdcefdbc60e97a9e3447afed204b3e40d991e.zip | |
Basic Graphics package
| -rw-r--r-- | game.adb | 5 | ||||
| -rw-r--r-- | game.ads | 8 | ||||
| -rw-r--r-- | graphics.adb | 60 | ||||
| -rw-r--r-- | graphics.ads | 33 | ||||
| -rw-r--r-- | main.adb | 47 | ||||
| -rw-r--r-- | snake.gpr | 2 |
6 files changed, 119 insertions, 36 deletions
@@ -0,0 +1,5 @@ +with Game; + +package body Game is + null +end Game; @@ -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; @@ -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; @@ -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; |
