-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlatform.cpp
More file actions
65 lines (51 loc) · 1.35 KB
/
Platform.cpp
File metadata and controls
65 lines (51 loc) · 1.35 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "Platform.h"
#include "Sprite.h"
#include "Sprites.h"
#include "Textures.h"
#include "Game.h"
void CPlatform::RenderBoundingBox()
{
D3DXVECTOR3 p(x, y, 0);
RECT rect;
LPTEXTURE bbox = CTextures::GetInstance()->Get(ID_TEX_BBOX);
float l, t, r, b;
GetBoundingBox(l, t, r, b);
rect.left = 0;
rect.top = 0;
rect.right = (int)r - (int)l;
rect.bottom = (int)b - (int)t;
float cx, cy;
CGame::GetInstance()->GetCamPos(cx, cy);
float xx = x - this->cellWidth / 2 + rect.right / 2;
CGame::GetInstance()->Draw(xx - cx, y - cy, bbox, nullptr, BBOX_ALPHA, rect.right - 1, rect.bottom - 1);
}
void CPlatform::Render()
{
if (this->length <= 0) return;
float xx = x;
CSprites * s = CSprites::GetInstance();
s->Get(this->spriteIdBegin)->Draw(xx, y);
xx += this->cellWidth;
for (int i = 1; i < this->length - 1; i++)
{
s->Get(this->spriteIdMiddle)->Draw(xx, y);
xx += this->cellWidth;
}
if (length>1)
s->Get(this->spriteIdEnd)->Draw(xx, y);
//RenderBoundingBox();
}
void CPlatform::GetBoundingBox(float& l, float& t, float& r, float& b)
{
float cellWidth_div_2 = this->cellWidth / 2;
l = x - cellWidth_div_2;
t = y - this->cellHeight / 2;
r = l + this->cellWidth * this->length;
b = t + this->cellHeight;
}
int CPlatform::IsDirectionColliable(float nx, float ny)
{
if (blocking == 0) return 0;
if (blocking == 1) return 1;
return 0;
}