Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // First way
- // GameEngine class with a Singleton.
- // ResourceLoader and Painter are classes that are allocated in the GameEngine. And in the GameEngine you can receive those pointers
- // The advantage of this is that I only make those pointers once in the whole application/game.
- // Image is a class that will hold all the image information
- int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
- {
- GameEngine engine = GameEngine::GetInstance();
- engine.StartUp( 640, 480, _T("Game Engine"), 60 );
- //----------------------------------------------------------------------------------------------------
- //// Receive the resourceLoader via the engine
- ResourceLoader* pResourceLoader = engine.GetResourceLoader();
- //// Receive the painter via the engine
- Painter* pPainter = engine.GetPainter();
- //// Load a Bitmap
- Image* pImage = pResourceLoader->LoadImage( "image.bmp" );
- while( engine.ProcessMessages() )
- {
- //// Draw the image
- pPainter->DrawImage( pImage, xPos, yPos );
- }
- //----------------------------------------------------------------------------------------------------
- engine.Shutdown();
- return 0;
- }
- // Second way
- // GameEngine is still the same
- // ResourceLoader and Painter are now classes independent of the GameEngine
- // So you always need to make them ( with other words, more allocated objects that will do the same )
- // Image class is still the same
- int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
- {
- GameEngine engine = GameEngine::GetInstance();
- engine.StartUp( 640, 480, _T("Game Engine"), 60 );
- //----------------------------------------------------------------------------------------------------
- //// Create the resourceLoade
- ResourceLoader* pResourceLoader = new ResourceLoader();
- //// Receive the painter via the engine
- Painter* pPainter = new Painter();
- //// Load a Bitmap
- Image* pImage = pResourceLoader->LoadImage( "image.bmp" );
- while( engine.ProcessMessages() )
- {
- //// Draw the image
- pPainter->DrawImage( pImage, xPos, yPos );
- }
- //----------------------------------------------------------------------------------------------------
- engine.Shutdown();
- return 0;
- }
- // Third way
- // GameEngine is now a bit different
- // The classes ResourceLoader and Painter are still there but..
- // I work with inheritance:
- // class GameEngine: public ResourceLoader, public Painter { }
- int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
- {
- GameEngine engine = GameEngine::GetInstance();
- engine.StartUp( 640, 480, _T("Game Engine"), 60 );
- // I still got a Painter and Recource class but I use heritance here.
- // class GameEngine: public Painter, public ResourceLoader
- //----------------------------------------------------------------------------------------------------
- //// Load the image
- engine.LoadImage( "image.bmp" );
- while( engine.ProcessMessages() )
- {
- //// Draw the image
- engine.DrawImage( pImage, xPos, yPos );
- }
- //----------------------------------------------------------------------------------------------------
- engine.Shutdown();
- return 0;
- }
- // Fourth way
- // ResourceLoader and Painter is gone
- // Now I made the Image class indepent of a painter or resource loader.
- // So he must load his own image, draw himself, etc.
- // This will have performance if the image can be rotated, scaled, etc
- int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
- {
- GameEngine engine = GameEngine::GetInstance();
- engine.StartUp( 640, 480, _T("Game Engine"), 60 );
- // I still got a Painter and Recource class but I use heritance here.
- // class GameEngine: public Painter, public ResourceLoader
- //----------------------------------------------------------------------------------------------------
- //// Load the image
- Image* pImage = new Image( "image.bmp" );
- while( engine.ProcessMessages() )
- {
- //// Draw the image
- pImage.Draw( xPos, yPos );
- }
- //----------------------------------------------------------------------------------------------------
- engine.Shutdown();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement