Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8909803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:31:35+00:00 2026-06-15T03:31:35+00:00

This is an school assignment. To create a snake game. So I have created

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:31:36+00:00Added an answer on June 15, 2026 at 3:31 am

    You might want to use a multitasking system to overcome your problem.

    procedure Snake_Game is
    
       task Run_Snake is
          entry Input_Received (S : Snake_Type; x : Integer; y : Integer);
       end Run_Snake;
    
       task body Run_Snake is
          D : constant Duration := 0.07;
          B : Buffer (1 .. 24, 1 .. 80);
       begin
          loop
             select
                accept Input_Received (S : Snake_Type; x : Integer; y : Integer) do
                   Move (S, x, y);
                end;
             or
                delay D;
                Empty (B);
                Draw_Rect (B, (1, 1), Width => 80, Height => 24);
                Draw (B, S);
                Update (B);
             end select;
          end loop;
       end Run_Snake;
    
       S : Snake_Type (1 .. 5) := ((10, 10),
                                  (10, 11),
                                  (10, 12),
                                  (11, 12),
                                  (12, 12));
    
    begin
       loop
          Do_Whatever_You_Want_To_Get (x, y)
          Run_Snake.Input_Received(S, x, y);
       end loop;
    end Snake_Game;
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have for a school assignment created a small game, it is divided into
We got this assignment from school to reproduce this example (created in Flash) into
In school, one of my professors had created a 3D game (not just an
This is an assignment question from school: Create a recursive method called toBinary that
This is a school assignment and I have most of it under control, but
What's a clear way of doing this? For a school assignment I have to
So I have an assignment for school that requires me to create a fixed
I have created a hash class for an assignment in school that implements hashing
I'm working on a school assignment and I've been completely stumped with this step.
this is for an assignment at school, where I need to determine the size

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.