aboutsummaryrefslogtreecommitdiff
path: root/graphics.adb
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-12-08 10:09:30 +0100
committerCharles <sircharlesaze@gmail.com>2019-12-08 10:09:30 +0100
commit22e73779f55b051d34fc0490fbb55045f3f321d9 (patch)
tree7ae37872135c135d3716a209cea4c8351691863c /graphics.adb
parentc06bc6767163f0215d0c12e04d5a0a54d7d8a167 (diff)
downloadsnake-22e73779f55b051d34fc0490fbb55045f3f321d9.tar.gz
snake-22e73779f55b051d34fc0490fbb55045f3f321d9.tar.bz2
snake-22e73779f55b051d34fc0490fbb55045f3f321d9.zip
Snake Drawing
Diffstat (limited to 'graphics.adb')
-rw-r--r--graphics.adb39
1 files changed, 32 insertions, 7 deletions
diff --git a/graphics.adb b/graphics.adb
index 2cdea69..e9e4b71 100644
--- a/graphics.adb
+++ b/graphics.adb
@@ -1,29 +1,37 @@
with Ada.Text_IO;
use Ada.Text_IO;
-with Graphics;
-use Graphics;
-
with SDL;
with SDL.Timers;
+with SDL.Video.Rectangles;
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;
+use SDL.Video;
+
+with Graphics, Game;
+use Graphics, Game;
+
+with Interfaces.C;
+use Interfaces.C;
package body Graphics is
+ use P_Position_Queue;
+
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,
+ Windows.Makers.Create(state.window, WINDOW_TITLE, WINDOW_X, WINDOW_Y,
WINDOW_WIDTH, WINDOW_HEIGHT);
- SDL.Video.Renderers.Makers.Create(state.renderer, state.window);
+ Renderers.Makers.Create(state.renderer, state.window);
state.running := true;
+ Init(state.game, 10, 10);
end Init;
procedure Quit(state: T_State) is
@@ -52,9 +60,26 @@ package body Graphics is
null;
end Event_Handler;
- procedure Update(state: T_State) is
+ procedure Update(state: in out T_State) is
+ cursor: T_List := state.game.snake.front;
begin
- null;
+ Renderers.Set_Draw_Colour(state.renderer, COLOR_BLACK);
+ Renderers.Clear(state.renderer);
+
+ Renderers.Set_Draw_Colour(state.renderer, COLOR_WHITE);
+ while cursor /= null loop
+ Draw_Square(state, cursor.all.data);
+ cursor := cursor.all.next;
+ end loop;
+ Renderers.Present(state.renderer);
end Update;
+ procedure Draw_Square(state: in out T_State;
+ pos: T_Position) is
+ rect: Rectangles.Rectangle;
+ begin
+ rect := ((C.int(pos.y) - 1) * 20, (C.int(pos.x) - 1) * 20, 20, 20);
+ Renderers.Fill(state.renderer, rect);
+ end Draw_Square;
+
end Graphics;