/
Base.cpp
104 lines (94 loc) · 2.26 KB
/
Base.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "Base.h"
#include "Mesh.h"
#include "Global.h"
#include "Thruster.h"
#include "Launcher.h"
#include "GameType.h"
#include "Color.h"
#include "Player.h"
#include "Flag.h"
#include "SpawnPoint.h"
#include "Team.h"
Base::Base(unsigned int _i, Player* o, Vec2D location, Vec2D direction, bool collides, bool draw)
{
index = _i;
owner = o;
loc = location;
dir = direction;
collidable = collides;
dead = false;
drawMe = draw;
bb = NULL;
mesh = NULL;
}
Base::~Base(void)
{
if(mesh)
delete mesh;
if(bb)
delete bb;
}
void Base::Kill()
{
dead = true;
if(mesh != NULL)
{
if(typeid(*mesh) == typeid(Mesh))
{
Mesh* m = (Mesh*)(this->mesh);
for(unsigned int i = 0; i < m->mountNum; ++i)
{
m->actualMounts[i]->Kill();
m->actualMounts[i] = NULL;
}
}
}
}
void Base::endStep(float deltaTime)
{
}
Mesh* Base::CopyMesh(renderableType mT, const Color& c)
{
if(mT > sse || mT == none)
return NULL;
Renderable* temp = getGame()->getRenderable(mT);
if(temp == NULL)
return NULL;
if(typeid(*temp) == typeid(Mesh))
{
//copy temp to m
Mesh* m = new Mesh( *((Mesh*)(temp)) );
//mesh->polys[i].length denotes the number of vertices in the polygon
for(unsigned int i = 0; i < m->polyNum; ++i)
{
for(unsigned int index = 0; index < m->polys[i].length; ++index)
m->polys[i].vertices[index].COLOR = c.returnD3DCOLOR(); //set color
}
//load to video memory
LoadToVRAM(m);
if(m->mountNum > 0)
{
Game* g = getGame();
m->actualMounts = new Base*[m->mountNum];
for(unsigned int i = 0; i < m->mountNum; ++i)
{
if(m->mountNames[i] == "thruster")
{
Base* t = new Thruster(getGame()->getNextIndex(), owner, none, m->mountLocs[i], dir, this, false, true); //none is used because the default mesh should point to this for the Render function to be called
//this->texture is used instead to store the actual drawing
g->insertObject(t);
m->actualMounts[i] = t;
}
else
m->actualMounts[i] = NULL;
//other mounts are handled in the ship class (why?)(so I can control ROF's)
}
}
else
m->actualMounts = NULL;
//back to renderable pointer
return m;
}
else
return NULL;
}