Advertisement
viettiennguyen029

Moving Platform .cpp

May 30th, 2020
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include "MovingPlatform.h"
  2. #include "Brick.h"
  3. CMovingPlatform::CMovingPlatform()
  4. {
  5.     vx = MOVING_PLATFORM_SPEED;
  6. }
  7.  
  8. void CMovingPlatform::Render()
  9. {
  10.     animation_set->at(0)->Render(x, y,1);
  11. }
  12.  
  13. void CMovingPlatform::Update(DWORD dt, vector<LPGAMEOBJECT>* coObjects)
  14. {
  15.     CGameObject::Update(dt);
  16.     x += dx;
  17.  
  18.     vector<LPCOLLISIONEVENT> coEvents;
  19.     vector<LPCOLLISIONEVENT> coEventsResult;
  20.  
  21.     coEvents.clear();
  22.     CalcPotentialCollisions(coObjects, coEvents);
  23.  
  24.     if (coEvents.size() == 0)
  25.     {
  26.         y += dy;
  27.         x += dx;
  28.     }
  29.     else
  30.     {
  31.         float min_tx, min_ty, nx = 0, ny;
  32.         float rdx, rdy;
  33.         FilterCollision(coEvents, coEventsResult, min_tx, min_ty, nx, ny, rdx, rdy);
  34.  
  35.         x += min_tx * dx;
  36.         y += min_ty * dy;
  37.  
  38.         for (UINT i = 0; i < coEventsResult.size(); i++)
  39.         {
  40.             LPCOLLISIONEVENT e = coEventsResult[i];
  41.             // Collision with brick
  42.             if (dynamic_cast<CBrick*>(e->obj))
  43.             {
  44.                 DebugOut(L" Redirecting Moving Platform\n");
  45.                 vx = -vx;
  46.  
  47.             }
  48.         }
  49.     }
  50.  
  51.     // clean up collision events
  52.     for (int i = 0; i < coEvents.size(); i++) delete coEvents[i];
  53. }
  54.  
  55. void CMovingPlatform::GetBoundingBox(float& l, float& t, float& r, float& b)
  56. {
  57.     l = x;
  58.     t = y;
  59.     r = x + MOVING_PLATFORM_BBOX_WIDTH;
  60.     b = y + MOVING_PLATFORM_BBOX_HEIGHT;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement