Programming computer games will be easier if you use the game loop that commonly used. I saw you used event-based things (FormCreate, FormActivate GridMouseUp, etc), that is okay but that will be hard to control the flow of the game. You can search the web to learn more about game loop.
For example this is my Furious Palladin's main loop (AKA game loop):
type
TAppState = (Intro1, Intro2, Playing, Paused, Lose, Win);
var
AppState: TAppState;
begin
ProcessInit;
StartAppState(Intro1);
while (GameIsRunning) do begin
ProcessUserInput;
ProcessUpdate;
ProcessDrawing;
end;
ProcessShutdown;
end.
I use application state (some call it 'game state') to further control the flow depends on the AppState. When the game first starts, it will show 2 pages: Intro1 and Intro2. When the game is running, it can has 2 states: playing and paused. Also there are 2 important states: Lose and Win.
StartAppState is the function to change the AppState. Basically it does some variable initializations needed to start a new state.
procedure AppStartState(State: TAppState);
case State of
Intro1: begin
// Start background music
end;
Intro2: begin
//
end;
Playing: begin
if (AppState = Intro2) then
begin
// Init player data
// Init enemies' data
// Start new background music
end;
if (AppState = Paused) then
begin
// Continue audio playing
end;
end;
Paused: begin
// Save background music position and stop it
end;
Lose: begin
// Play sound
end;
end;
AppState := State;
end;
The Basic flow of the states is:
Intro1 > Intro2 > Playing | Paused | Win | Lose
The things needed to put inside StartAppState are depend on how your game do. For example you can see my flow above, the 'real' playing is started after Intro2 ends, so the initialization of player's and enemies' data are being put there. It differs from ProcessInit in the main loop, which is used to initialize the hardware and it just needed to run once.
And if you examine my StartAppState, you will see there is nothing inside Intro2 and Win state. That because basically they just states to show different things for ProcessDrawing:
procedure ProcessDrawing;
begin
case AppState of
Intro1: // Draw Intro1 background
Intro2: // Draw Intro2 background
Playing, Paused, Lose, Win:
begin
// Clear screan
// Draw health bar
// Show killed information
// Draw player and enemies
// AppState related
case AppState of
Paused: // Show paused image
Lose: // Show failed image
Win: // Show win image
end;
end;
end;
al_flip_display;
end;
StartAppState is called everywhere in the code. It can be called on ProcessUserInput for pausing/resuming the game and progressing from Intro1 > Intro2 > Playing by pressing any key. It also called when player wins or dies inside ProcessUserInput. For example:
procedure ProcessUpdate;
// ...
// ...
if (EnemyKilled >= 100) then StartAppState(Win);
end;
So, what are the things I really want to say?
Don't use event based things to control the game flow but use game loop (the main loop) and game state.
You can download Furious Paladin demo here:
http://forum.lazarus.freepascal.org/index.php/topic,35313.msg253114.html#msg253114