Guest User

.cpp

a guest
Apr 24th, 2012
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.63 KB | None | 0 0
  1. //-----------------------------------------------------------------
  2. // Game File
  3. // C++ Source - AlienEggs.cpp - version 2012 v2_10
  4. // Copyright Kevin Hoefman - [email protected]
  5. // http://www.digitalartsandentertainment.be/
  6. //-----------------------------------------------------------------
  7.  
  8. //-----------------------------------------------------------------
  9. // Include Files
  10. //-----------------------------------------------------------------
  11. #include "AlienEggs.h"                                                                             
  12.  
  13. //-----------------------------------------------------------------
  14. // Defines
  15. //-----------------------------------------------------------------
  16. #define GAME_ENGINE (GameEngine::GetSingleton())
  17.  
  18. //-----------------------------------------------------------------
  19. // AlienEggs methods                                                                               
  20. //-----------------------------------------------------------------
  21.  
  22. AlienEggs::AlienEggs():
  23.     m_BmpLevelPtr(0)
  24.     ,m_BmpAlienPtr(0)
  25.     ,m_ActorPos(30,30)
  26.     ,m_ActorVelocity(0,0)
  27.     ,m_PosCamera(0,0)
  28.     ,actorSpeed(0)
  29.     ,m_Gravity(0,0)
  30.     ,m_HitActorPtr(0)
  31.     ,m_HitLevelPtr(0)
  32. {
  33.    
  34. }
  35.  
  36. AlienEggs::~AlienEggs()                                                                                    
  37. {
  38.    
  39. }
  40.  
  41. void AlienEggs::GameInitialize(HINSTANCE hInstance)        
  42. {
  43.     // Set the required values
  44.     AbstractGame::GameInitialize(hInstance);
  45.     GAME_ENGINE->SetTitle("AlienEggs - Philippe Mesotten - 1DAE5");                
  46.     GAME_ENGINE->RunGameLoop(true);
  47.    
  48.     // Set the optional values
  49.     GAME_ENGINE->SetWidth(1000);
  50.     GAME_ENGINE->SetHeight(800);
  51.     GAME_ENGINE->SetFrameRate(60);
  52.     GAME_ENGINE->SetTickPaintRatio(2);
  53.     //GAME_ENGINE->SetKeyList(String("QSDZ") + (TCHAR) VK_SPACE);
  54. }
  55.  
  56. void AlienEggs::GameStart()
  57. {
  58.     m_BmpLevelPtr = new Bitmap("./Resources/texture.jpg");
  59.     m_BmpAlienPtr = new Bitmap("./Resources/alien.png");
  60.     m_HitLevelPtr = new HitRegion();
  61.     m_HitActorPtr = new HitRegion();
  62.  
  63.     m_HitActorPtr->CreateFromFile("./Resources/alien.svg");
  64.     m_HitLevelPtr->CreateFromFile("./Resources/level.svg");
  65. }
  66.  
  67. void AlienEggs::GameEnd()
  68. {
  69.     delete m_BmpLevelPtr;
  70.     delete m_BmpAlienPtr;
  71.     delete m_HitLevelPtr;
  72.     delete m_HitActorPtr;
  73. }
  74. //
  75. //void AlienEggs::GameActivate()
  76. //{
  77. //  // Insert the code that needs to be executed when the game window becomes active
  78. //
  79. //  /* Example:
  80. //  GAME_ENGINE->SetSleep(false);
  81. //  */
  82. //}
  83. //
  84. //void AlienEggs::GameDeactivate()
  85. //{
  86. //  // Insert the code that needs to be executed when the game window becomes inactive
  87. //
  88. //  /* Voorbeeld:
  89. //  GAME_ENGINE->SetSleep(true);
  90. //  */
  91. //}
  92. //
  93. //void AlienEggs::MouseButtonAction(bool isLeft, bool isDown, int x, int y, WPARAM wParam)
  94. //{
  95. //  // Insert the code that needs to be executed when the game registers a mouse button action
  96. //
  97. //  /* Example:
  98. //  if (isLeft == true && isDown == true) // is it a left mouse click?
  99. //  {  
  100. //      if ( x > 261 && x < 261 + 117 ) // check if click lies within x coordinates of choice
  101. //      {
  102. //          if ( y > 182 && y < 182 + 33 ) // check if click also lies within y coordinates of choice
  103. //          {
  104. //              GAME_ENGINE->MessageBox("Clicked.");
  105. //          }
  106. //      }
  107. //  }
  108. //  */
  109. //}
  110. //
  111. //void AlienEggs::MouseMove(int x, int y, WPARAM wParam)
  112. //{
  113. //  // Insert the code that needs to be executed when the mouse pointer moves across the game window
  114. //
  115. //  /* Example:
  116. //  if ( x > 261 && x < 261 + 117 ) // check if mouse position is within x coordinates of choice
  117. //  {
  118. //      if ( y > 182 && y < 182 + 33 ) // check if mouse position also is within y coordinates of choice
  119. //      {
  120. //          GAME_ENGINE->MessageBox("Da mouse wuz here.");
  121. //      }
  122. //  }
  123. //  */
  124. //
  125. //}
  126. //
  127. //void AlienEggs::CheckKeyboard()
  128. //{
  129. //  // Here you can check if a key of choice is held down
  130. //  // Is executed once per frame
  131. //
  132. //  /* Example:
  133. //  if (GAME_ENGINE->IsKeyDown('K')) xIcon -= xSpeed;
  134. //  if (GAME_ENGINE->IsKeyDown('L')) yIcon += xSpeed;
  135. //  if (GAME_ENGINE->IsKeyDown('M')) xIcon += xSpeed;
  136. //  if (GAME_ENGINE->IsKeyDown('O')) yIcon -= ySpeed;
  137. //  */
  138. //}
  139. //
  140. void AlienEggs::KeyPressed(TCHAR cKey)
  141. {  
  142.     // DO NOT FORGET to use SetKeyList() !!
  143.  
  144.     // Insert the code that needs to be executed when a key of choice is pressed
  145.     // Is executed as soon as the key is released
  146.     // You first need to specify the keys that the game engine needs to watch by using the SetKeyList() method
  147.  
  148.     /* Example:
  149.     switch (cKey)
  150.     {
  151.     case 'K': case VK_LEFT:
  152.         MoveBlock(DIR_LEFT);
  153.         break;
  154.     case 'L': case VK_DOWN:
  155.         MoveBlock(DIR_DOWN);
  156.         break;
  157.     case 'M': case VK_RIGHT:
  158.         MoveBlock(DIR_RIGHT);
  159.         break;
  160.     case 'A': case VK_UP:
  161.         RotateBlock();
  162.         break;
  163.     case VK_ESCAPE:
  164.     }
  165.     */
  166. }
  167.  
  168. void AlienEggs::GameTick(double deltaTime)
  169. {
  170.     if(m_HitActorPtr->HitTest(m_HitLevelPtr))
  171.     {
  172.         GAME_ENGINE->MessageBox(String("zeh fuck."));
  173.     }
  174.  
  175.     if(GAME_ENGINE->IsKeyDown(VK_LEFT))
  176.     {
  177.             m_ActorVelocity.x -= 10;
  178.     }
  179.     if(GAME_ENGINE->IsKeyDown(VK_RIGHT))
  180.     {
  181.             m_ActorVelocity.x += 10;
  182.     }
  183.     if(GAME_ENGINE->IsKeyDown(VK_UP))
  184.     {
  185.             m_ActorVelocity.y -= 10;
  186.     }
  187.     if(GAME_ENGINE->IsKeyDown(VK_DOWN))
  188.     {
  189.             m_ActorVelocity.y += 10;
  190.     }
  191.     //WRIJVING MAKEN!
  192.     if(m_ActorVelocity.y > 0)
  193.     {
  194.         m_ActorVelocity.y -=5;
  195.     }
  196.     if(m_ActorVelocity.y < 0)
  197.     {
  198.         m_ActorVelocity.y +=5;
  199.     }
  200.     if(m_ActorVelocity.x > 0)
  201.     {
  202.         m_ActorVelocity.x -=5;
  203.     }
  204.     if(m_ActorVelocity.x < 0)
  205.     {
  206.         m_ActorVelocity.x +=5;
  207.     }
  208.     if(GAME_ENGINE->IsKeyDown(VK_HOME))
  209.     {
  210.             m_ActorPos.y = 30;
  211.             m_ActorPos.x = 30;
  212.             m_ActorVelocity.x = 0;
  213.             m_ActorVelocity.y = 0;
  214.     }
  215.  
  216.     m_ActorPos = m_ActorPos + m_ActorVelocity*deltaTime +m_Gravity* deltaTime*deltaTime/2;
  217.     m_ActorVelocity = m_ActorVelocity + m_Gravity *deltaTime;
  218.     m_PosCamera.x = m_ActorPos.x;
  219. }
  220.  
  221. void AlienEggs::GamePaint(RECT rect)
  222. {
  223.     //bepaal matCamera -> matView °°Inverse°°
  224.     MATRIX3X2 matCamera,matCameraTranslate,matCameraScale;
  225.     matCameraTranslate.SetAsTranslate(m_PosCamera);
  226.     matCamera = matCameraScale*matCameraTranslate;
  227.     //Drawbitmaps (matTranslate*matView)
  228.     //level
  229.     MATRIX3X2 matCenter,matScale,matRotate,matTranslate,matTransform,matView;
  230.     matView = matCamera.Inverse();
  231.     matTransform = matCenter*matScale*matRotate*matTranslate*matView;
  232.     GAME_ENGINE->SetTransformMatrix(matTransform);
  233.     GAME_ENGINE->DrawSolidBackground(0,0,0);
  234.     GAME_ENGINE->DrawBitmap(m_BmpLevelPtr,0,0);
  235.     //hero
  236.     //Adapt matTranslate to position of hero
  237.     matTranslate.SetAsTranslate(m_ActorPos);
  238.     GAME_ENGINE->SetTransformMatrix(matTranslate*matView);
  239.     GAME_ENGINE->DrawBitmap(m_BmpAlienPtr,0,0);
  240.     GAME_ENGINE->FillHitRegion(m_HitActorPtr);
  241.     //Drawhitregions (matView)
  242.     GAME_ENGINE->SetTransformMatrix(matView);
  243.  
  244.     GAME_ENGINE->SetColor(255,0,0,0);
  245.     GAME_ENGINE->FillHitRegion(m_HitLevelPtr);
  246. }
  247. //
  248. //void AlienEggs::CallAction(Caller* callerPtr)
  249. //{
  250. //  // Insert the code that needs to be executed when a Caller has to perform an action
  251. //}
Advertisement
Add Comment
Please, Sign In to add comment