This is an school assignment. To create a snake game.
So I have created two packages one for graphics and one for the snake.
The snake moves smoothly and everything works. But I need to control the snake with the keyboard.This is the main procedure:
with Graphics; use Graphics;
with Graphics.Snake; use Graphics.Snake;
procedure Run_Snake is
B : Buffer (1 .. 24, 1 .. 80);
S : Snake_Type (1 .. 5) := ((10, 10),
(10, 11),
(10, 12),
(11, 12),
(12, 12));
D : Duration := 0.07;
begin
loop
Empty (B);
Draw_Rect (B, (1, 1), Width => 80,
Height => 24);
Draw (B, S);
Update (B);
Move (S, 0, -1);
delay D;
end loop;
end Run_Snake;
in this line of code I controll the snakes head rotation:
Move (S, x, y);
where x is the x value it can be -1 for left, 1 for right.
where y is the y value it can be -1 for down, 1 for up;
Anyways, how can I read the input without pausing the snake from moving?
Thanks
You might want to use a multitasking system to overcome your problem.
In such a system, you have your drawing process in a separate task. At the “select” line, the task waits for a call to Input_Received(). If this entry is not called after a duration D, then the task executes all the drawing functions, and the loop begins anew.
Hope it can help.
Cheers.