-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathBrainBoss.cpp
218 lines (200 loc) · 5.61 KB
/
BrainBoss.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#include "BrainBoss.h"
#include "BrainCell.h"
#include "Engine.h"
BrainBoss::BrainBoss()
{
}
//================================================================================================//
/*******************
** BrainBoss spawn **
********************/
//================================================================================================//
void BrainBoss::Spawn(Vec2 pos)
{
IsActive = true;
oPos = Pos = pos;
frame = 0;
fStartLife = fLife = 500;
mBodySphere = Sphere(60,pos+Vec2(128,128));
mSphere = Sphere(20,pos+Vec2(68,128));
iTakeDamageTicks = 0;
iAttackWave = 0;
iAttackTicks = 0;
bJustSpawned = true;
fRateOfSpawn = gpEngine->mTimer.GetTime();
bIsDead = false;
iDeathTicks = 0;
}
//================================================================================================//
/*******************
** BrainBoss Clone **
********************/
//================================================================================================//
BrainBoss* BrainBoss::Clone()const
{
return new BrainBoss(*this);
}
//================================================================================================//
/********************
** BrainBoss update **
*********************/
//================================================================================================//
void BrainBoss::Update()
{
iTakeDamageTicks--;
oPos = Pos;
if(bIsDead)
{
iDeathTicks++;
if(iDeathTicks>150)
{
IsActive = false;
gpEngine->StartCompleted();
}
return;
}
iAttackTicks++;
if(bJustSpawned)
{
if(iAttackTicks>50)
{
bJustSpawned = false;
iAttackTicks = 0;
}
return;
}
if(iAttackWave==0)
{
float r = UTIL_Misc::TimeRamp(0,2*PI,0,150,(float)iAttackTicks);
Pos.x-=sin(r)*11;
Pos.y+=cos(r)*9.5f;
if(iAttackTicks>=150)
{
iAttackTicks=0;
iAttackWave=1;
fRateOfFire = gpEngine->mTimer.GetTime();
}
if(gpEngine->mTimer.GetTime()>fRateOfSpawn)
{
fRateOfSpawn = gpEngine->mTimer.GetTime()+0.25f;
BrainCell* cell = new BrainCell;
cell->Spawn(mSphere.p);
gpEngine->GiveEntityToList((Entity*)cell);
}
}
if(iAttackWave==1)
{
if(iAttackTicks>=100 && iAttackTicks<=130|| iAttackTicks<=30)
if(gpEngine->mTimer.GetTime()>fRateOfFire)
{
fRateOfFire = gpEngine->mTimer.GetTime()+0.1f;
Bullet b;
b.pSpawn = Spawn_PowerBullet;
b.pUpdate = Update_BasicBullet;
b.pRender = Render_BossPowerBullet;
b.pCollide = Collide_PowerBullet;
Vec2 p(mSphere.p);
Vec2 v = FireAtTarget(p,gpEngine->mPlayer.mSphere.p,7.5f);
(*b.pSpawn)(b,p,v);
Line l1(gpEngine->mPlayer.mSphere.p,p);
Line l2(p,Vec2(p.x,p.y+Distance(gpEngine->mPlayer.mSphere.p,p)));
if(p.x>gpEngine->mPlayer.mSphere.p.x)
b.rot = -(RAD2DEG(l1.Angle(l2))-90);
else
b.rot = (RAD2DEG(l1.Angle(l2))+90);
gpEngine->SpawnBullet(b,false);
SND_LASER4;
}
if(iAttackTicks>=200)
{
iAttackTicks=0;
iAttackWave=0;
fRateOfSpawn = gpEngine->mTimer.GetTime();
}
}
mBodySphere.p = Pos+Vec2(128,128);
}
//================================================================================================//
/******************
** BrainBoss draw **
*******************/
//================================================================================================//
void BrainBoss::Draw(const float interp)
{
if(bIsDead)
return;
if(iTakeDamageTicks>0)
{
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD);
glColor4f(1,1,0,1);
}
else
glColor4f(1,1,1,1);
Vec2 p = UTIL_Misc::Interpolate(Pos,oPos,interp);
UTIL_GL::SetBlend(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
UTIL_GL::BindTexture(GL_TEXTURE_2D,gpEngine->imgBossBrain);
UTIL_GL::GL2D::DrawTextureQuad(Pos.x,Pos.y+256,Pos.x+256,Pos.y);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
/* glDisable(GL_TEXTURE_2D);
glColor4f(1,1,0,1);
GeoDraw2D::DrawSphere(mSphere, 25);//*/
}
//================================================================================================//
/*********************************
** if it goes offscreen kill it **
**********************************/
//================================================================================================//
void BrainBoss::NeedsToBeRemoved()
{
}
//================================================================================================//
/****************
** Take damage **
*****************/
//================================================================================================//
bool BrainBoss::CheckCollided(Sphere s, float damage)
{
if(!IsActive || bIsDead)
return false;
if(Collision::SphereSphereOverlap(s,mSphere))
{
fLife -= damage;
if(fLife<=0)
{
bIsDead = true;
int RotAngle = rand()%360;
gpEngine->SpawnExplosion(gpEngine->sprExplosionSmall,mSphere.p,290,0.75f, (float)(RotAngle),false);
gpEngine->SpawnExplosion(gpEngine->sprExplosion2,mSphere.p,220,0.5f, (float)(RotAngle),true);
SND_SMALLEXPLODE;
gpEngine->mPlayer.iScore+=500;
gpEngine->mFade.StartFade(gpEngine->mTimer.GetTime(),1.5f);
gpEngine->mFade.SetSrcColor(1,0,0,1);
gpEngine->mFade.SetDstColor(1,0,0,0);
list<Entity*>::iterator i;
for(i=gpEngine->mGameEnts.begin();i!=gpEngine->mGameEnts.end();i++)
{
if((*i)==this)
continue;
(*i)->CheckCollided((*i)->mSphere,100000);//kill all ents
}
gpEngine->bWimpMode = true;
}
iTakeDamageTicks = 3;
return true;
}
if(Collision::SphereSphereOverlap(s,mBodySphere))
{
return true;
}
return false;
}
void BrainBoss::LoadFromFile(CFileIO &fIO)
{
}
void BrainBoss::WriteToFile(CFileIO &fIO)
{
}
int BrainBoss::InWater()
{
return 0;
}