Ubuntu Tutorials  Windows Tutorials  Download  |
Add A 2D Sprite |
|
       You can get the complete example source code here.
2D Sprite Complete Example:/* File Name: GOC.h Created By: Andy Odle Date: July 27, 2009 */ #ifndef GOC_h #define GOC_h #include "./source/PlatformSpecific/inc/ErrorReport.h" #include "./source/inc/TimeGOC.h" #include "./source/inc/InputEngine.h" /* Add new include files here */ #include "./source/PlatformSpecific/inc/Sprite.h" #include "./source/inc/MathGOC.h" class GOC { public: // Initilizes the developer's game. virtual void Initilize(); // Updates the developer's game state. virtual void Update(TimeGOC *timeGOC_p, InputEngine *input_p); virtual void IndepedentUpdate(TimeGOC *timeGOC_p, InputEngine *input_p); // Ceans up the developer's game. virtual void Destroy(); // This is how you interact with the GOC. // // Output: // Returns the Game Object Creator instance // pointer. static GOC *goc_i(); // Get the window's width and height. int GetWindowWidth(); int GetWindowHeight(); // Start the setup of the Game Object Creator. #ifdef _WIN32 void LoadGOC(HINSTANCE &hinstance_p); #else void LoadGOC(); #endif // Clean up the Game Object Creator. void UnloadGOC(); ErrorReport *GetErrorReport(); private: GOC(); ~GOC(); GOC(GOC const&){}; GOC &operator=(GOC const&){}; private: /* Add private variables here. */ Sprite *ball_m; }; #endif /* Date Created: Apr 29, 2010 FileName: main.cpp First Sprite Example */ #include "./source/PlatformSpecific/inc/GOC.h" void GOC::Initilize() { /* Initilize your game scene, and game variables here. */ // Fill out the sprite's x-cor, y-cor and z-cor // structure. PointGOC ballPosition_l = {GetWindowWidth() / 2, GetWindowHeight() / 2, 0.0f}; // Create a new instance of your sprite. ball_m = new Sprite(); // Change the position of your sprite by passing // in a filled out PointGOC structrue and the // sprite's with and height. ball_m->Set2DPosition(ballPosition_l, 24, 24); // Apply a texture to your sprite. ball_m->GetTexture()->LoadTexture("./images/ball.png"); // Make your sprite visible or invisible. ball_m->SetVisible(true); } 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::Destroy() { /* Clean up after your game here. */ // Destory your sprite when you are done with it. delete ball_m; } #ifdef _WIN32 // Define the windows main funciton. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) #else // Define the ubutnu 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; } Legal Info  About GOC  Contact Us  |
|