The first things that you need to know when it comes to games programming in pascal is how to program in pascal... A good place to start is here.
Most games run from a main loop that continuely looks for user input, while redrawing the screen as necessary. The way they work is they initialise everything and then get into the main loop, taking in input as necessary and so on. Then when the program sends the message to quit - based on input or something - it UnInitialises.
In code, what I have said so far would look like this:
Var Quit : Boolean;
Begin
Initialise;
Repeat
GetInput;
DrawAsNecessary;
...
Until Quit = True;
UnInitialise {In case of changing back to text mode or Freeing Pointers}
End;
So far so good. Now, to get input, you need to wait for a key to be pressed and then see what key it is. In order to do that, we need to include the crt library. We also need to get the key irrespective of its case. We therefore make our Char Variable = to the uppercase of whatever key was pressed. If we do it that way, we need to make sure that in our case statemnt, we only address uppercase keys. In code it looks like:
{Before the main loop}
Var Ch : Char;
{In the loop or in the procedure getinput which is called by the main loop}
If KeyPressed Then {We only want the program to stop if there was a
key pressed}
Begin
Ch := UpCase(ReadKey);
Case Ch of
'Q' : Quit := True; {Notice, 'Q' not 'q'}
End;
End;
Let's say we have a game with a creature that continuely moves in a previously ordained direction and only based input changes its direction. If we leave this main loop as it is, the player will not get a chance to control the creature because it will move too fast. What we need to use is the Delay procedure (in the crt unit). If we put our delay in the main loop, it will slow down the game allowing the player to determine the creatures new direction. As an example, a game of snake where the snake keeps moving in the direction that it originally was directed and based on user input changes its direction. If given no time to respond, the user will not be able to press a key to change its direction and the snake will definately crash. Therefore, we need to add a delay to the main loop for that kind of game in order to give the user time to respond.
The one thing that needs to be kept in mind, that all games - no matter whether old or recent, follows these basic concepts. If you look at my next 2 articles, you will notice how similar they are. This just enphasises what I just said. The main way that games have changed is (Based on the method I stated at the beginning - init, loop, check input, if quit = true then exit, UnInit.) the way their drawing procedures work.
There are now two ways to continue with this series - Using Text Mode or Using normal Graphics. Continue with whichever article you want.