Advertisement
turbello

Untitled

Dec 6th, 2011
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.23 KB | None | 0 0
  1. // First way
  2. // GameEngine class with a Singleton.
  3. // ResourceLoader and Painter are classes that are allocated in the GameEngine. And in the GameEngine you can receive those pointers
  4. // The advantage of this is that I only make those pointers once in the whole application/game.
  5. // Image is a class that will hold all the image information
  6.  
  7. int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
  8. {
  9. GameEngine engine = GameEngine::GetInstance();
  10. engine.StartUp( 640, 480, _T("Game Engine"), 60 );
  11.  
  12.  
  13. //----------------------------------------------------------------------------------------------------
  14. //// Receive the resourceLoader via the engine
  15. ResourceLoader* pResourceLoader = engine.GetResourceLoader();
  16. //// Receive the painter via the engine
  17. Painter* pPainter = engine.GetPainter();
  18.  
  19. //// Load a Bitmap
  20. Image* pImage = pResourceLoader->LoadImage( "image.bmp" );
  21.  
  22. while( engine.ProcessMessages() )
  23. {
  24. //// Draw the image
  25. pPainter->DrawImage( pImage, xPos, yPos );
  26. }
  27. //----------------------------------------------------------------------------------------------------
  28.  
  29.  
  30. engine.Shutdown();
  31. return 0;
  32. }
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. // Second way
  43. // GameEngine is still the same
  44. // ResourceLoader and Painter are now classes independent of the GameEngine
  45. // So you always need to make them ( with other words, more allocated objects that will do the same )
  46. // Image class is still the same
  47.  
  48. int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
  49. {
  50. GameEngine engine = GameEngine::GetInstance();
  51. engine.StartUp( 640, 480, _T("Game Engine"), 60 );
  52.  
  53.  
  54. //----------------------------------------------------------------------------------------------------
  55. //// Create the resourceLoade
  56. ResourceLoader* pResourceLoader = new ResourceLoader();
  57. //// Receive the painter via the engine
  58. Painter* pPainter = new Painter();
  59.  
  60. //// Load a Bitmap
  61. Image* pImage = pResourceLoader->LoadImage( "image.bmp" );
  62.  
  63. while( engine.ProcessMessages() )
  64. {
  65. //// Draw the image
  66. pPainter->DrawImage( pImage, xPos, yPos );
  67. }
  68. //----------------------------------------------------------------------------------------------------
  69.  
  70.  
  71. engine.Shutdown();
  72. return 0;
  73. }
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82. // Third way
  83. // GameEngine is now a bit different
  84. // The classes ResourceLoader and Painter are still there but..
  85. // I work with inheritance:
  86. // class GameEngine: public ResourceLoader, public Painter { }
  87.  
  88. int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
  89. {
  90. GameEngine engine = GameEngine::GetInstance();
  91. engine.StartUp( 640, 480, _T("Game Engine"), 60 );
  92.  
  93.  
  94. // I still got a Painter and Recource class but I use heritance here.
  95. // class GameEngine: public Painter, public ResourceLoader
  96.  
  97. //----------------------------------------------------------------------------------------------------
  98. //// Load the image
  99. engine.LoadImage( "image.bmp" );
  100.  
  101. while( engine.ProcessMessages() )
  102. {
  103. //// Draw the image
  104. engine.DrawImage( pImage, xPos, yPos );
  105. }
  106. //----------------------------------------------------------------------------------------------------
  107.  
  108.  
  109. engine.Shutdown();
  110. return 0;
  111. }
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121. // Fourth way
  122. // ResourceLoader and Painter is gone
  123. // Now I made the Image class indepent of a painter or resource loader.
  124. // So he must load his own image, draw himself, etc.
  125. // This will have performance if the image can be rotated, scaled, etc
  126. int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
  127. {
  128. GameEngine engine = GameEngine::GetInstance();
  129. engine.StartUp( 640, 480, _T("Game Engine"), 60 );
  130.  
  131.  
  132. // I still got a Painter and Recource class but I use heritance here.
  133. // class GameEngine: public Painter, public ResourceLoader
  134.  
  135. //----------------------------------------------------------------------------------------------------
  136. //// Load the image
  137. Image* pImage = new Image( "image.bmp" );
  138.  
  139. while( engine.ProcessMessages() )
  140. {
  141. //// Draw the image
  142. pImage.Draw( xPos, yPos );
  143. }
  144. //----------------------------------------------------------------------------------------------------
  145.  
  146.  
  147. engine.Shutdown();
  148. return 0;
  149. }
  150.  
  151.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement