forked from snoutmate/Sea-Defender
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpboat.cpp
More file actions
83 lines (61 loc) · 1.78 KB
/
pboat.cpp
File metadata and controls
83 lines (61 loc) · 1.78 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "pboat.h"
#include "background.h"
#include "resources.h"
#include "botinterface.h"
extern BotInterface *g_bot_interface;
const int pboat_missiles = 10;
PBoat::PBoat(vec2 pos,float scale) :
m_pos(pos),m_scale(scale),m_shift(0.0),m_missiles(pboat_missiles)
{
m_model = &g_resources.mesh_pboat;
}
void PBoat::draw(void)
{
glPushMatrix();
m_shift = Sea::sea_func(m_pos[0]+0.00) * 0.90; // pos
float rot = Sea::sea_func(m_pos[0]+0.05) * 0.9 * 333; // rotate
glTranslatef(m_pos[0],m_pos[1]+m_shift,0.0);
glScalef(m_scale,m_scale,1.0);
glRotatef(rot,0,0,1);
glDisable(GL_TEXTURE_2D);
glColor4f(0,0,0,1.0);
(*m_model)->draw();
glPopMatrix();
glPushMatrix();
StaticMesh *missile_model = g_resources.mesh_missile;
glTranslatef(m_pos[0]-0.05,m_pos[1]-0.06,0.0);
glScalef(Missile::m_scale,Missile::m_scale,1.0);
glRotatef(90,0,0,1.0);
glColor4f(0,0,0,1.0);
for(int i=0;i<10;++i) {
if (i==m_missiles)
glColor4f(1.0,1.0,1.0,0.25);
missile_model->draw();
glTranslatef(0.0,-0.3,0.0);
}
glPopMatrix();
}
vec2 PBoat::get_pos(void)
{
return vec2(m_pos[0],m_pos[1]+m_shift);
}
int PBoat::missiles_left(void)
{
return m_missiles;
}
Missile *PBoat::fire_missile(vec2 dest,float radius)
{
--m_missiles;
vec2 src = m_pos + vec2(0.0,m_shift + 0.02);
stringstream bot_param;
bot_param << "missiles_left=" << m_missiles << " destination=" << dest[0] << "," << dest[1] << " radius=" << radius;
g_bot_interface->async_send(g_timer->now(), "missile_fired", src, bot_param.str());
return new Missile(src,dest,radius);
}
void PBoat::reload_ammo(void)
{
m_missiles = pboat_missiles;
stringstream bot_param;
bot_param << "missiles_left=" << m_missiles;
g_bot_interface->async_send(g_timer->now(), "missiles_reloaded", m_pos, bot_param.str());
}