-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBarrack.cpp
61 lines (43 loc) · 1.25 KB
/
Barrack.cpp
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
#include "Barrack.h"
Barrack::Barrack()
{
}
Barrack::~Barrack()
{
}
void Barrack::Initialize()
{
barrackMesh.Initialize("models/barrack.x");
}
void Barrack::Render(D3DXVECTOR3 * pos)
{
D3DXMatrixScaling(&S, 50.0f, 50.0f, 50.0f);
D3DXMatrixTranslation(&T, pos->x, pos->y, pos->z);
W = S*T;
Device->SetTransform(D3DTS_WORLD, &W);
barrackMesh.Render();
D3DXVec3TransformCoord(&min, &barrackMesh.min, &W);
D3DXVec3TransformCoord(&max, &barrackMesh.max, &W);
D3DXVec3TransformCoord(&doorLeft, &doorLeftTemp, &W);
D3DXVec3TransformCoord(&doorRight, &doorRightTemp, &W);
}
bool Barrack::Collision(Player *player)
{
if (player->_pos.x >= min.x && player->_pos.x <= max.x) {
// if player hits the front wall
if (player->_pos.z >= min.z - 2 && player->_pos.z < max.z)
player->_pos.z = min.z - 2;
// if player hits the back wall
if (player->_pos.z <= max.z + 2 && player->_pos.z > min.z)
player->_pos.z = max.z + 2;
}
if (player->_pos.z >= min.z && player->_pos.z <= max.z) {
// if player hits the left wall
if (player->_pos.x >= min.x - 2 && player->_pos.x < max.x)
player->_pos.x = min.x - 2;
// if player hits the right wall
if (player->_pos.x <= max.x + 2 && player->_pos.x > min.x)
player->_pos.x = max.x + 2;
}
return false;
}