Game Object Creator

First GOC Project's Details

This first GOC tutorial covers:

           A explanation of the GOC coding standards.

           Writing platform independent source code.

           Where to place variables, objects and functions.

           An explanation of a GOC's game structure.

Coding Standards

      The GOC is built around a coding standard (Located here). The reason for having a coding standard is to make the GOC library easier to understand. The coding standard provided by the GOC is just a guideline. You are not required to follow the same coding standard that the GOC uses. The coding standard is used to help developers understand how the GOC works and what it takes to develop games.

Platform-Independent Source Code

      In order to guarantee that the games that you write on one platform will work on another platform you must follow some guidelines:

           Don't include headers like “windows.h”, “Xlib.h” or "conio.h".

           Don't try to use the same CodeLite® project files on Windows® and Ubuntu® .

           Remember that directory locations on Ubuntu® are case sensitive.

           Relative and physical paths on Ubuntu require “/” and on Windows you can
            use either slash.

           Relative paths on Ubuntu® require a “.” before your first slash ie "./path/".
            Windows® doesn't care if you have a dot or not.

      If you have no other option and you need to use platform specific code. Wrap the functionality of your platform specific code in preprocessor compiler directives.

Platform Independent Examples:

                         // Platform specific header files.
                         #include "windows.h" // Don't use!
                         #include "Xlib.h" // Don't use!

                         // Case sensitive paths. 
                         // "Images" is not the same as "images".
                         sprite_m->LoadTexture("./../images/Ball.png");
                         sprite_m->LoadTexture("./../Images/Paddle.png");
                         
                         // Paths that work for both windows and ubuntu.
                         #include "./source/" // Correct!
                         #include "\source\"  // Incorrect!
                         
                         // Compile time platform specific code.
                         #ifdef _WIN32
                         
                            // Start the GOC on windows.
                            GOC::goc_i()->LoadGOC(hInstance);

                         #else
                         
                            // Start the GOC on ubuntu.
                            GOC::goc_i()->LoadGOC();

                         #endif
                     

Adding Variables and Functions

      The “GOC.h” header file is the main interface to the GOC library. The GOC header file is where you will need to add variables and objects that you want access to inside of your game functions. For example if you want to add a new sprite to your game you first have to add a sprite variable to the appropriate section of the GOC interface file.

Minimum GOC Game Structure

Every GOC Game requires:

           The inclusion of the "GOC.h" library interface file.

           A GOC::Initialize(){ } function declaration.

           A GOC::Update(){ } function declaration.

           A GOC::IndependentUpdate(){} function declaration.

           A GOC::Destroy(){ } function declaration.

           A WinMain(...) and main(...) function declarations.

      The initialize function is where a game's starting state gets setup for the first time. Initialize is called automatically only one time by the GOC library. This one time call occurs when a game is started for the first time. Memory allocation should take place inside the initialize function.

      The update function is where your game logic code will go. The update function is guaranteed to be called by the GOC library at a 30th of a second interval. The reason that the update function is run at a predictable interval is to allow game logic to run on slower hardware independently of the frame rate. The update function is responsible for handling input, moving objects around, collision detection, AI calculations and sound triggering. The update function is the heart of your games. If your game's performance starts to suffer you may need to optimize how you are handling you update function.

      The independentupdate function is used exactly as you use the update function. The difference between the two funcitons is that update is guarantee to exicute 33 times a second (every 30th of a second) but independentupdate will update as fast as your computer can handle.

      The destroy function is used to clean up after your game. If you have allocated any memory for your game objects, this is where you need to release that memory. The destroy function is only called once when your game ends.

      WinMain and main functions is where the GOC library starts executing. WinMain is the entry point to a windows application. Main is the the entry point for Ubuntu. These functions are specific to the operating system you are running on and have to be wrapped with compiler directives. The compiler directives tell the compiler to include either WinMain or main at compile time into your game.

Minimum GOC Game Complete Example:

                            /* 
                                Date Created: Apr 27, 2010
                                FileName: main.cpp

                                First GOC Example Game 
                            */
                                                
                            #include "./source/PlatformSpecific/inc/GOC.h"
                                                
                            void GOC::Initialize()
                            {
                                /* 
                                    Initialize your game scene, and game 
                                    variables here. 
                                */
                            }
                                                
                            void GOC::Update(TimeGOC *timeGOC_p, InputEngine *input_p)
                            {
                                /*
                                    Update your game scenes, check for collisions, 
                                    check for input and play sounds here.
                                */
                            }

                            void GOC::IndependentUpdate(TimeGOC *timeGOC_p, InputEngine *input_p)
                            {
                                /*
                                    Update your game scenes, check for collisions,
                                    check for input and play sounds here.
                                */
                            }

                            void GOC::Destroy()
                            {
                                /* 
                                    Clean up after your game here.
                                */
                            }
                                                
                            #ifdef _WIN32
                                                
                                // Define the windows main funciton.
                                int WINAPI WinMain(HINSTANCE hInstance, 
                                                   HINSTANCE hPrevInstance, 
                                                   LPSTR lpCmdLine, 
                                                   int nCmdShow)
                            #else

                                // Define the ubuntu main function.
                                int main(int argc, char **argv)
                                
                            #endif
                                {
                                    #ifdef _WIN32
                                        // Start the GOC on windows.
                                        GOC::goc_i()->LoadGOC(hInstance);
                                    #else
                                        // Start the GOC on ubuntu.
                                        GOC::goc_i()->LoadGOC();
                                    #endif
                                                        
                                    // Destroy and cleanup GOC.
                                    GOC::goc_i()->UnloadGOC();
                                    return 0;
                                }                                    
                        

(<- "First GOC Project" Previous | Back to "Windows® " or "Ubuntu® " Tutorials)



Legal Info  About GOC  Contact Us