Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //-----------------------------------------------------------------
- // Game File
- // C++ Source - AlienEggs.cpp - version 2012 v2_10
- // Copyright Kevin Hoefman - [email protected]
- // http://www.digitalartsandentertainment.be/
- //-----------------------------------------------------------------
- //-----------------------------------------------------------------
- // Include Files
- //-----------------------------------------------------------------
- #include "AlienEggs.h"
- //-----------------------------------------------------------------
- // Defines
- //-----------------------------------------------------------------
- #define GAME_ENGINE (GameEngine::GetSingleton())
- //-----------------------------------------------------------------
- // AlienEggs methods
- //-----------------------------------------------------------------
- AlienEggs::AlienEggs():
- m_BmpLevelPtr(0)
- ,m_BmpAlienPtr(0)
- ,m_ActorPos(30,30)
- ,m_ActorVelocity(0,0)
- ,m_PosCamera(0,0)
- ,actorSpeed(0)
- ,m_Gravity(0,0)
- ,m_HitActorPtr(0)
- ,m_HitLevelPtr(0)
- {
- }
- AlienEggs::~AlienEggs()
- {
- }
- void AlienEggs::GameInitialize(HINSTANCE hInstance)
- {
- // Set the required values
- AbstractGame::GameInitialize(hInstance);
- GAME_ENGINE->SetTitle("AlienEggs - Philippe Mesotten - 1DAE5");
- GAME_ENGINE->RunGameLoop(true);
- // Set the optional values
- GAME_ENGINE->SetWidth(1000);
- GAME_ENGINE->SetHeight(800);
- GAME_ENGINE->SetFrameRate(60);
- GAME_ENGINE->SetTickPaintRatio(2);
- //GAME_ENGINE->SetKeyList(String("QSDZ") + (TCHAR) VK_SPACE);
- }
- void AlienEggs::GameStart()
- {
- m_BmpLevelPtr = new Bitmap("./Resources/texture.jpg");
- m_BmpAlienPtr = new Bitmap("./Resources/alien.png");
- m_HitLevelPtr = new HitRegion();
- m_HitActorPtr = new HitRegion();
- m_HitActorPtr->CreateFromFile("./Resources/alien.svg");
- m_HitLevelPtr->CreateFromFile("./Resources/level.svg");
- }
- void AlienEggs::GameEnd()
- {
- delete m_BmpLevelPtr;
- delete m_BmpAlienPtr;
- delete m_HitLevelPtr;
- delete m_HitActorPtr;
- }
- //
- //void AlienEggs::GameActivate()
- //{
- // // Insert the code that needs to be executed when the game window becomes active
- //
- // /* Example:
- // GAME_ENGINE->SetSleep(false);
- // */
- //}
- //
- //void AlienEggs::GameDeactivate()
- //{
- // // Insert the code that needs to be executed when the game window becomes inactive
- //
- // /* Voorbeeld:
- // GAME_ENGINE->SetSleep(true);
- // */
- //}
- //
- //void AlienEggs::MouseButtonAction(bool isLeft, bool isDown, int x, int y, WPARAM wParam)
- //{
- // // Insert the code that needs to be executed when the game registers a mouse button action
- //
- // /* Example:
- // if (isLeft == true && isDown == true) // is it a left mouse click?
- // {
- // if ( x > 261 && x < 261 + 117 ) // check if click lies within x coordinates of choice
- // {
- // if ( y > 182 && y < 182 + 33 ) // check if click also lies within y coordinates of choice
- // {
- // GAME_ENGINE->MessageBox("Clicked.");
- // }
- // }
- // }
- // */
- //}
- //
- //void AlienEggs::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 AlienEggs::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 AlienEggs::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 AlienEggs::GameTick(double deltaTime)
- {
- if(m_HitActorPtr->HitTest(m_HitLevelPtr))
- {
- GAME_ENGINE->MessageBox(String("zeh fuck."));
- }
- if(GAME_ENGINE->IsKeyDown(VK_LEFT))
- {
- m_ActorVelocity.x -= 10;
- }
- if(GAME_ENGINE->IsKeyDown(VK_RIGHT))
- {
- m_ActorVelocity.x += 10;
- }
- if(GAME_ENGINE->IsKeyDown(VK_UP))
- {
- m_ActorVelocity.y -= 10;
- }
- if(GAME_ENGINE->IsKeyDown(VK_DOWN))
- {
- m_ActorVelocity.y += 10;
- }
- //WRIJVING MAKEN!
- if(m_ActorVelocity.y > 0)
- {
- m_ActorVelocity.y -=5;
- }
- if(m_ActorVelocity.y < 0)
- {
- m_ActorVelocity.y +=5;
- }
- if(m_ActorVelocity.x > 0)
- {
- m_ActorVelocity.x -=5;
- }
- if(m_ActorVelocity.x < 0)
- {
- m_ActorVelocity.x +=5;
- }
- if(GAME_ENGINE->IsKeyDown(VK_HOME))
- {
- m_ActorPos.y = 30;
- m_ActorPos.x = 30;
- m_ActorVelocity.x = 0;
- m_ActorVelocity.y = 0;
- }
- m_ActorPos = m_ActorPos + m_ActorVelocity*deltaTime +m_Gravity* deltaTime*deltaTime/2;
- m_ActorVelocity = m_ActorVelocity + m_Gravity *deltaTime;
- m_PosCamera.x = m_ActorPos.x;
- }
- void AlienEggs::GamePaint(RECT rect)
- {
- //bepaal matCamera -> matView °°Inverse°°
- MATRIX3X2 matCamera,matCameraTranslate,matCameraScale;
- matCameraTranslate.SetAsTranslate(m_PosCamera);
- matCamera = matCameraScale*matCameraTranslate;
- //Drawbitmaps (matTranslate*matView)
- //level
- MATRIX3X2 matCenter,matScale,matRotate,matTranslate,matTransform,matView;
- matView = matCamera.Inverse();
- matTransform = matCenter*matScale*matRotate*matTranslate*matView;
- GAME_ENGINE->SetTransformMatrix(matTransform);
- GAME_ENGINE->DrawSolidBackground(0,0,0);
- GAME_ENGINE->DrawBitmap(m_BmpLevelPtr,0,0);
- //hero
- //Adapt matTranslate to position of hero
- matTranslate.SetAsTranslate(m_ActorPos);
- GAME_ENGINE->SetTransformMatrix(matTranslate*matView);
- GAME_ENGINE->DrawBitmap(m_BmpAlienPtr,0,0);
- GAME_ENGINE->FillHitRegion(m_HitActorPtr);
- //Drawhitregions (matView)
- GAME_ENGINE->SetTransformMatrix(matView);
- GAME_ENGINE->SetColor(255,0,0,0);
- GAME_ENGINE->FillHitRegion(m_HitLevelPtr);
- }
- //
- //void AlienEggs::CallAction(Caller* callerPtr)
- //{
- // // Insert the code that needs to be executed when a Caller has to perform an action
- //}
Advertisement
Add Comment
Please, Sign In to add comment