- //-----------------------------------------------------------------
- // Game File
- // C++ Source - ArraysAdv1Add.cpp - version 2011 v2_08
- // Copyright Kevin Hoefman - kevin.hoefman@howest.be
- // http://www.digitalartsandentertainment.be/
- //-----------------------------------------------------------------
- //-----------------------------------------------------------------
- // Include Files
- //-----------------------------------------------------------------
- #include "ArraysAdv1Add.h"
- //-----------------------------------------------------------------
- // Defines
- //-----------------------------------------------------------------
- #define GAME_ENGINE (GameEngine::GetSingleton())
- //-----------------------------------------------------------------
- // ArraysAdv1Add methods
- //-----------------------------------------------------------------
- ArraysAdv1Add::ArraysAdv1Add(): m_PolyPointsIndex(0)
- {
- for(int initialize = 0; initialize < MAX_RAND; ++ initialize)
- {
- m_RandCounterArr[initialize] = 0;
- }
- for(int initialize = 0; initialize < MAX_POLY_POINTS; ++initialize)
- {
- m_CyclicPolyPointsArr[initialize].x = 0;
- m_CyclicPolyPointsArr[initialize].y = 0;
- }
- }
- ArraysAdv1Add::~ArraysAdv1Add()
- {
- // nothing to destroy
- }
- void ArraysAdv1Add::GameInitialize(HINSTANCE hInstance)
- {
- // Set the required values
- AbstractGame::GameInitialize(hInstance);
- GAME_ENGINE->SetTitle("ArraysAdv1Add");
- GAME_ENGINE->RunGameLoop(true);
- // Set the optional values
- GAME_ENGINE->SetWidth(640);
- GAME_ENGINE->SetHeight(480);
- GAME_ENGINE->SetFrameRate(50);
- //GAME_ENGINE->SetKeyList(String("QSDZ") + (TCHAR) VK_SPACE);
- }
- void ArraysAdv1Add::GameStart()
- {
- // Insert the code that needs to be executed at the start of the game
- }
- void ArraysAdv1Add::GameEnd()
- {
- // Insert the code that needs to be executed at the closing of the game
- }
- void ArraysAdv1Add::GameActivate()
- {
- // Insert the code that needs to be executed when the game window becomes active
- /* Example:
- GAME_ENGINE->SetSleep(false);
- */
- }
- void ArraysAdv1Add::GameDeactivate()
- {
- // Insert the code that needs to be executed when the game window becomes inactive
- /* Voorbeeld:
- GAME_ENGINE->SetSleep(true);
- */
- }
- void ArraysAdv1Add::MouseButtonAction(bool isLeft, bool isDown, int x, int y, WPARAM wParam)
- {
- if (isLeft == true && isDown == true)
- {
- if(m_PolyPointsIndex == MAX_POLY_POINTS)
- {
- ShiftRowElementsToLeft(m_CyclicPolyPointsArr, MAX_POLY_POINTS);
- m_CyclicPolyPointsArr[m_PolyPointsIndex].x = x;
- m_CyclicPolyPointsArr[m_PolyPointsIndex].y = y;
- }
- else
- {
- m_CyclicPolyPointsArr[m_PolyPointsIndex].x = x;
- m_CyclicPolyPointsArr[m_PolyPointsIndex].y = y;
- ++m_PolyPointsIndex;
- }
- }
- }
- void ArraysAdv1Add::MouseMove(int x, int y, WPARAM wParam)
- {
- // Insert the code that needs to be executed when the mouse pointer moves across the game window
- /* Example:
- if ( x > 261 && x < 261 + 117 ) // check if mouse position is within x coordinates of choice
- {
- if ( y > 182 && y < 182 + 33 ) // check if mouse position also is within y coordinates of choice
- {
- GAME_ENGINE->MessageBox("Da mouse wuz here.");
- }
- }
- */
- }
- void ArraysAdv1Add::CheckKeyboard()
- {
- // Here you can check if a key of choice is held down
- // Is executed once per frame
- /* Example:
- if (GAME_ENGINE->IsKeyDown('K')) xIcon -= xSpeed;
- if (GAME_ENGINE->IsKeyDown('L')) yIcon += xSpeed;
- if (GAME_ENGINE->IsKeyDown('M')) xIcon += xSpeed;
- if (GAME_ENGINE->IsKeyDown('O')) yIcon -= ySpeed;
- */
- }
- void ArraysAdv1Add::KeyPressed(TCHAR cKey)
- {
- // DO NOT FORGET to use SetKeyList() !!
- // Insert the code that needs to be executed when a key of choice is pressed
- // Is executed as soon as the key is released
- // You first need to specify the keys that the game engine needs to watch by using the SetKeyList() method
- /* Example:
- switch (cKey)
- {
- case 'K': case VK_LEFT:
- MoveBlock(DIR_LEFT);
- break;
- case 'L': case VK_DOWN:
- MoveBlock(DIR_DOWN);
- break;
- case 'M': case VK_RIGHT:
- MoveBlock(DIR_RIGHT);
- break;
- case 'A': case VK_UP:
- RotateBlock();
- break;
- case VK_ESCAPE:
- }
- */
- }
- void ArraysAdv1Add::GameTick()
- {
- int RandomNumber = rand() % MAX_RAND;
- ++m_RandCounterArr[RandomNumber];
- }
- void ArraysAdv1Add::GamePaint(RECT rect)
- {
- GAME_ENGINE->DrawSolidBackground(RGB(255, 255, 255));
- for(int visualize = 0; visualize < MAX_RAND; ++visualize)
- {
- GAME_ENGINE->DrawString(String("Number ") + visualize + (" : ") + m_RandCounterArr[visualize] + ("x"), 20, 20 + (visualize * 20));
- GAME_ENGINE->FillRect(150, 27 + (visualize * 20), m_RandCounterArr[visualize], 10);
- }
- GAME_ENGINE->DrawPolygon(m_CyclicPolyPointsArr, m_PolyPointsIndex, true);
- DrawFilledCircle(m_CyclicPolyPointsArr, m_PolyPointsIndex);
- }
- void ArraysAdv1Add::CallAction(Caller* callerPtr)
- {
- // Insert the code that needs to be executed when a Caller has to perform an action
- }
- void ArraysAdv1Add::ShiftRowElementsToLeft(POINT *pointsArr, int size)
- {
- for(int shift = 1; shift < size; ++shift)
- {
- pointsArr[shift-1] = pointsArr[shift];
- }
- }
- void ArraysAdv1Add::DrawFilledCircle(POINT *pointsArr, int size)
- {
- for(int draw = 0 ; draw < size; ++draw)
- {
- GAME_ENGINE->FillOval(pointsArr[draw].x-5, pointsArr[draw].y-5, 10, 10);
- }
- }