Guest

Untitled

By: a guest on Jan 28th, 2012  |  syntax: None  |  size: 5.38 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. //-----------------------------------------------------------------
  2. // Game File
  3. // C++ Source - ArraysAdv1Add.cpp - version 2011 v2_08
  4. // Copyright Kevin Hoefman - kevin.hoefman@howest.be
  5. // http://www.digitalartsandentertainment.be/
  6. //-----------------------------------------------------------------
  7.  
  8. //-----------------------------------------------------------------
  9. // Include Files
  10. //-----------------------------------------------------------------
  11. #include "ArraysAdv1Add.h"                                                                                                                                                             
  12.  
  13. //-----------------------------------------------------------------
  14. // Defines
  15. //-----------------------------------------------------------------
  16. #define GAME_ENGINE (GameEngine::GetSingleton())
  17.  
  18. //-----------------------------------------------------------------
  19. // ArraysAdv1Add methods                                                                                                                                                               
  20. //-----------------------------------------------------------------
  21.  
  22. ArraysAdv1Add::ArraysAdv1Add(): m_PolyPointsIndex(0)                                                                                                                                                                           
  23. {
  24.         for(int initialize = 0; initialize < MAX_RAND; ++ initialize)
  25.         {
  26.                 m_RandCounterArr[initialize] = 0;
  27.         }
  28.  
  29.         for(int initialize = 0; initialize < MAX_POLY_POINTS; ++initialize)
  30.         {
  31.                 m_CyclicPolyPointsArr[initialize].x = 0;
  32.                 m_CyclicPolyPointsArr[initialize].y = 0;
  33.         }
  34. }
  35.  
  36. ArraysAdv1Add::~ArraysAdv1Add()                                                                                                                                                                        
  37. {
  38.         // nothing to destroy
  39. }
  40.  
  41. void ArraysAdv1Add::GameInitialize(HINSTANCE hInstance)                
  42. {
  43.         // Set the required values
  44.         AbstractGame::GameInitialize(hInstance);
  45.         GAME_ENGINE->SetTitle("ArraysAdv1Add");                                
  46.         GAME_ENGINE->RunGameLoop(true);        
  47.        
  48.         // Set the optional values
  49.         GAME_ENGINE->SetWidth(640);
  50.         GAME_ENGINE->SetHeight(480);
  51.     GAME_ENGINE->SetFrameRate(50);
  52.         //GAME_ENGINE->SetKeyList(String("QSDZ") + (TCHAR) VK_SPACE);
  53. }
  54.  
  55. void ArraysAdv1Add::GameStart()
  56. {
  57.         // Insert the code that needs to be executed at the start of the game
  58. }
  59.  
  60. void ArraysAdv1Add::GameEnd()
  61. {
  62.         // Insert the code that needs to be executed at the closing of the game
  63. }
  64.  
  65. void ArraysAdv1Add::GameActivate()
  66. {
  67.         // Insert the code that needs to be executed when the game window becomes active
  68.  
  69.         /* Example:
  70.         GAME_ENGINE->SetSleep(false);
  71.         */
  72. }
  73.  
  74. void ArraysAdv1Add::GameDeactivate()
  75. {
  76.         // Insert the code that needs to be executed when the game window becomes inactive
  77.  
  78.         /* Voorbeeld:
  79.         GAME_ENGINE->SetSleep(true);
  80.         */
  81. }
  82.  
  83. void ArraysAdv1Add::MouseButtonAction(bool isLeft, bool isDown, int x, int y, WPARAM wParam)
  84. {      
  85.         if (isLeft == true && isDown == true)
  86.         {      
  87.                 if(m_PolyPointsIndex == MAX_POLY_POINTS)
  88.                 {
  89.                         ShiftRowElementsToLeft(m_CyclicPolyPointsArr, MAX_POLY_POINTS);
  90.                         m_CyclicPolyPointsArr[m_PolyPointsIndex].x = x;
  91.                         m_CyclicPolyPointsArr[m_PolyPointsIndex].y = y;
  92.                 }
  93.                 else
  94.                 {
  95.                         m_CyclicPolyPointsArr[m_PolyPointsIndex].x = x;
  96.                         m_CyclicPolyPointsArr[m_PolyPointsIndex].y = y;
  97.                         ++m_PolyPointsIndex;
  98.                 }
  99.         }
  100. }
  101.  
  102. void ArraysAdv1Add::MouseMove(int x, int y, WPARAM wParam)
  103. {      
  104.         // Insert the code that needs to be executed when the mouse pointer moves across the game window
  105.  
  106.         /* Example:
  107.         if ( x > 261 && x < 261 + 117 ) // check if mouse position is within x coordinates of choice
  108.         {
  109.                 if ( y > 182 && y < 182 + 33 ) // check if mouse position also is within y coordinates of choice
  110.                 {
  111.                         GAME_ENGINE->MessageBox("Da mouse wuz here.");
  112.                 }
  113.         }
  114.         */
  115. }
  116.  
  117. void ArraysAdv1Add::CheckKeyboard()
  118. {      
  119.         // Here you can check if a key of choice is held down
  120.         // Is executed once per frame
  121.  
  122.         /* Example:
  123.         if (GAME_ENGINE->IsKeyDown('K')) xIcon -= xSpeed;
  124.         if (GAME_ENGINE->IsKeyDown('L')) yIcon += xSpeed;
  125.         if (GAME_ENGINE->IsKeyDown('M')) xIcon += xSpeed;
  126.         if (GAME_ENGINE->IsKeyDown('O')) yIcon -= ySpeed;
  127.         */
  128. }
  129.  
  130. void ArraysAdv1Add::KeyPressed(TCHAR cKey)
  131. {      
  132.         // DO NOT FORGET to use SetKeyList() !!
  133.  
  134.         // Insert the code that needs to be executed when a key of choice is pressed
  135.         // Is executed as soon as the key is released
  136.         // You first need to specify the keys that the game engine needs to watch by using the SetKeyList() method
  137.  
  138.         /* Example:
  139.         switch (cKey)
  140.         {
  141.         case 'K': case VK_LEFT:
  142.                 MoveBlock(DIR_LEFT);
  143.                 break;
  144.         case 'L': case VK_DOWN:
  145.                 MoveBlock(DIR_DOWN);
  146.                 break;
  147.         case 'M': case VK_RIGHT:
  148.                 MoveBlock(DIR_RIGHT);
  149.                 break;
  150.         case 'A': case VK_UP:
  151.                 RotateBlock();
  152.                 break;
  153.         case VK_ESCAPE:
  154.         }
  155.         */
  156. }
  157.  
  158. void ArraysAdv1Add::GameTick()
  159. {
  160.         int RandomNumber = rand() % MAX_RAND;
  161.         ++m_RandCounterArr[RandomNumber];
  162. }
  163.  
  164. void ArraysAdv1Add::GamePaint(RECT rect)
  165. {
  166.         GAME_ENGINE->DrawSolidBackground(RGB(255, 255, 255));
  167.  
  168.  
  169.         for(int visualize = 0; visualize < MAX_RAND; ++visualize)
  170.         {
  171.                 GAME_ENGINE->DrawString(String("Number ") + visualize + (" : ") + m_RandCounterArr[visualize] + ("x"), 20, 20 + (visualize * 20));
  172.                 GAME_ENGINE->FillRect(150, 27 + (visualize * 20), m_RandCounterArr[visualize], 10);
  173.         }
  174.  
  175.  
  176.         GAME_ENGINE->DrawPolygon(m_CyclicPolyPointsArr, m_PolyPointsIndex, true);
  177.         DrawFilledCircle(m_CyclicPolyPointsArr, m_PolyPointsIndex);
  178. }
  179.  
  180. void ArraysAdv1Add::CallAction(Caller* callerPtr)
  181. {
  182.         // Insert the code that needs to be executed when a Caller has to perform an action
  183. }
  184.  
  185. void ArraysAdv1Add::ShiftRowElementsToLeft(POINT *pointsArr, int size)
  186. {
  187.         for(int shift = 1; shift < size; ++shift)
  188.         {
  189.                 pointsArr[shift-1] = pointsArr[shift];
  190.         }
  191. }
  192.  
  193. void ArraysAdv1Add::DrawFilledCircle(POINT *pointsArr, int size)
  194. {
  195.         for(int draw = 0 ; draw < size; ++draw)
  196.         {
  197.                 GAME_ENGINE->FillOval(pointsArr[draw].x-5, pointsArr[draw].y-5, 10, 10);
  198.         }
  199. }