-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMovingPlatform.cpp
More file actions
47 lines (41 loc) · 1.06 KB
/
MovingPlatform.cpp
File metadata and controls
47 lines (41 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "MovingPlatform.h"
#include "Mario.h"
#include "Abyss.h"
#include "Game.h"
void CMovingPlatform::Render()
{
float xx = x - 16;
float xxx = x + 16;
CSprites* s = CSprites::GetInstance();
s->Get(ID_ANI_BODY)->Draw(x, y);
s->Get(ID_ANI_HEAD)->Draw(xx, y);
s->Get(ID_ANI_LEG)->Draw(xxx, y);
//RenderBoundingBox();
}
void CMovingPlatform::GetBoundingBox(float& l, float& t, float& r, float& b)
{
l = x - BBOX_WIDTH / 2;
t = y - BBOX_HEIGHT / 2;
r = l + BBOX_WIDTH;
b = t + BBOX_HEIGHT;
}
void CMovingPlatform::Update(DWORD dt, vector<LPGAMEOBJECT>* coObjects)
{
if (!isActive) x += SPEED_X_MOVING_PLATFORM * dt;
if (isActive) {
y += newVy * dt;
newVy += GRAVITY_MOVING_PLATFORM * dt;
newVy = min(newVy, SPEED_Y_MOVING_PLATFORM);
}
CGameObject::Update(dt, coObjects);
CCollision::GetInstance()->ProcessCollision(this, dt, coObjects);
}
void CMovingPlatform::OnCollisionWith(LPCOLLISIONEVENT e)
{
if (dynamic_cast<CMario*>(e->obj) && e->ny > 0 && !isActive)
{
newVy = 0.01;
isActive = true;
}
if (dynamic_cast<CAbyss*>(e->obj)) isDeleted = true;
}