-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.cpp
More file actions
executable file
·49 lines (45 loc) · 930 Bytes
/
game.cpp
File metadata and controls
executable file
·49 lines (45 loc) · 930 Bytes
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
#include "game.h"
actor::actor(Model *carmdl)
{
mdl = carmdl;
mincb = getmincollbox();
maxcb = getmaxcollbox();
}
v3df actor::getmincollbox()
{
v3df result;
result = mdl->vert(0);
for (int i=1; i<mdl->nverts(); i++)
{
v3df vert = mdl->vert(i);
if (result.x < vert.x)
result.x = vert.x;
if (result.z < vert.z)
result.z = vert.z;
}
return result;
}
v3df actor::getmaxcollbox()
{
v3df result;
result = mdl->vert(0);
for (int i=1; i<mdl->nverts(); i++)
{
v3df vert = mdl->vert(i);
if (result.x > vert.x)
result.x = vert.x;
if (result.z > vert.z)
result.z = vert.z;
}
return result;
}
bool actor::collisioncheck(actor *rival)
{
v3df distance = v3df(fabs(pos.x-rival->pos.x), 0, fabs(pos.z-rival->pos.z));
if (distance.x < mincb.x-maxcb.x && distance.z < mincb.z-maxcb.z)
{
std::cout<<"Collision!\n";
return true;
}
return false;
}