Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "MovingPlatform.h"
- #include "Brick.h"
- CMovingPlatform::CMovingPlatform()
- {
- vx = MOVING_PLATFORM_SPEED;
- }
- void CMovingPlatform::Render()
- {
- animation_set->at(0)->Render(x, y,1);
- }
- void CMovingPlatform::Update(DWORD dt, vector<LPGAMEOBJECT>* coObjects)
- {
- CGameObject::Update(dt);
- x += dx;
- vector<LPCOLLISIONEVENT> coEvents;
- vector<LPCOLLISIONEVENT> coEventsResult;
- coEvents.clear();
- CalcPotentialCollisions(coObjects, coEvents);
- if (coEvents.size() == 0)
- {
- y += dy;
- x += dx;
- }
- else
- {
- float min_tx, min_ty, nx = 0, ny;
- float rdx, rdy;
- FilterCollision(coEvents, coEventsResult, min_tx, min_ty, nx, ny, rdx, rdy);
- x += min_tx * dx;
- y += min_ty * dy;
- for (UINT i = 0; i < coEventsResult.size(); i++)
- {
- LPCOLLISIONEVENT e = coEventsResult[i];
- // Collision with brick
- if (dynamic_cast<CBrick*>(e->obj))
- {
- DebugOut(L" Redirecting Moving Platform\n");
- vx = -vx;
- }
- }
- }
- // clean up collision events
- for (int i = 0; i < coEvents.size(); i++) delete coEvents[i];
- }
- void CMovingPlatform::GetBoundingBox(float& l, float& t, float& r, float& b)
- {
- l = x;
- t = y;
- r = x + MOVING_PLATFORM_BBOX_WIDTH;
- b = y + MOVING_PLATFORM_BBOX_HEIGHT;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement