TUTORIAL THREE The Program Skeleton The skeleton of the program is the first thing you will be thinking about after the design stage. Most game skeletons are very similar and include the following. A setup stage to load and prepare your objects. A main loop to run your game logic and a cleanup stage where all the loaded media is released.

In Dark Basic Professional you only have to concern yourself with the first two in most cases. All media loaded is released automatically when you leave a Dark Basic Professional program. The first and second stages are very easy to visualise and can be coded in the following two steps. You must first create your setup stage:
    rem TUT3A
    rem Initial settings
    sync on : sync rate 100
    backdrop off : hide mouse

    rem Load all media for game
    gosub _load_game

    rem Setup all objects for game
    gosub _setup_game
You then create the main loop and any calls you will make over and over again to control the elements within your game:
    rem TUT3B
    rem Game loop
    do

     rem Control game elements
     gosub _control_player
     gosub _control_gunandbullet
     gosub _control_enemies

     rem Update screen
     sync

    rem End loop
    loop
The last step is to create all the subroutines that the first two stages call. Subroutines are blocks of code you can jump to in order to execute instructions that achieve a subtask. A subtask could be something like loading the player, controlling the player, deleting the player and so on. It is easier to understand what a subroutine does when given a useful name:
    rem TUT3C
    _control_player:
    return

    _control_gunandbullet:
    return

    _control_enemies:
    return

    _control_stats:
    return

    _setup_game:
    return

    _load_game:
    return
As you can see, each subroutine has a name that describes what it does. At the moment they are all empty and contain no code. Later on in the tutorial we shall fill these subroutines with commands. CLICK HERE TO GO TO THE MAIN MENU