-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProjectileMine.cpp
253 lines (220 loc) · 7.87 KB
/
ProjectileMine.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
// ProjectileMine.cpp
// Implements IProjectileWeapon interface
// Author(s): Eagan Rackley
#include "SFSHeaders.h"
#include "IAudio.h"
#include "LevelInfo.h"
#include "IProjectileWeapon.h"
#include "LevelMethods.h"
#include "ProjectileMine.h"
#include "ProjectileMethods.h"
// Defines how many possible projectiles will be allowed in this class
#define MAXIMUM_PROJECTILES 4
#define MAX_EXPERIENCE 400
#define TOTAL_LEVELS 4
///<summary>
/// Constructor...duh
///</summary>
ProjectileMine::ProjectileMine(IModel *model, IAudio *upgradeSound, IAudio *downGradeSound, IAudio *shootingSound)
{
ProjectileMethodsInit(model, upgradeSound, downGradeSound, shootingSound, myWeaponInfo, TOTAL_LEVELS, MAX_EXPERIENCE, MAXIMUM_PROJECTILES);
}
///<summary>
/// Destru... oh come now, you must know this...
///</summary>
ProjectileMine::~ProjectileMine()
{
// Deallocate our bullet sprites
myWeaponInfo.Projectiles.clear();
}
///<summary>
/// Get Projectile Model
///</summary>
IModel* ProjectileMine::getProjectileModel()
{
ASSERT(myWeaponInfo.ProjectileModel != NULL);
return myWeaponInfo.ProjectileModel;
}
///<summary>
/// Gets a string describing the name of the weapon...
///</summary>
std::string ProjectileMine::getProjectileName()
{
return "Mine";
}
///<summary>
/// Sets the experience level of the weapon
///</summary>
void ProjectileMine::setWeaponExperience(int experiencePoints)
{
myWeaponInfo.WeaponExperiencePoints = (float)experiencePoints;
}
///<summary>
/// Gets the experience points for the weapon
///</summary>
int ProjectileMine::getWeaponExperience()
{
return (int)myWeaponInfo.WeaponExperiencePoints;
}
///<summary>
/// Gets the maximum experience points for the weapon
///</summary>
float ProjectileMine::getMaxWeaponExperience()
{
return myWeaponInfo.MaxWeaponExperiencePoints;
}
///<summary>
/// Sets the experience level of the weapon
///</summary>
void ProjectileMine::modifyWeaponExperienceBy(int experiencePoints)
{
ProjectileMethodsModifyExperienceBy(myWeaponInfo, experiencePoints, MAX_EXPERIENCE);
}
///<summary>
/// Gets the level number of the weapon (based on exp pts)
///</summary>
int ProjectileMine::getWeaponLevelNumber()
{
return myWeaponInfo.WeaponLevelNumber;
}
///<summary>
/// Gets the percentage of experience gained toward the next level
///</summary>
float ProjectileMine::getPercentWeaponExperience()
{
return myWeaponInfo.PercentageComplete;
}
///<summary>
/// Handles projection collisions with other sprites...
///</summary>
void ProjectileMine::handleSpriteCollisions(LevelInfo *levelInfo, ISprite &sprite, IAudio *soundToPlay, float projectileDamage)
{
LevelMethodCollisionSet collisionSet;
std::vector<SpriteBullet>::iterator spriteIterator = myWeaponInfo.Projectiles.begin();
for(int idx = 0; idx < myWeaponInfo.CurrentMaxProjectiles; idx++)
{
// Handle all the controls and inputs for our baddie sprites!
if(spriteIterator->isDead() == false)
{
if(spriteIterator->getLocation().z >= (spriteIterator->getWaterLevel()))
{
collisionSet = LevelMethodsCheckCollisionSet(myWeaponInfo.Projectiles.at(idx), sprite);
if((collisionSet.collisionABIntersects == true) || (collisionSet.collisionACIntersects == true) || (collisionSet.collisionBCIntersects == true))
{
if ((sprite.getCurrentAnimation() != DEATH_FALLBACKSLOW) && (sprite.getCurrentAnimation() != DEATH_FALLBACK)
&& (sprite.getCurrentAnimation() != DEATH_FALLFORWARD))
{
LevelMethodsHandleSparkEffects(levelInfo, &myWeaponInfo.Projectiles.at(idx), 30);
// If the sprite isn't dying, collide with the sucka...
// If it's not in pain, play the hurty sound, and modify their health...
// If we hit both A and B handle a front collision (change movement by 180 degrees)
if(collisionSet.collisionABIntersects == true)
{
sprite.handleCollision(FRONT_ATTACK, (5.0f * myWeaponInfo.WeaponLevelNumber));
sprite.handleJump(-12.0f);
}
// If we hit both A and C handle a rear left collision (change movement by 45 degrees)
if(collisionSet.collisionACIntersects == true)
{
sprite.handleCollision(LEFT_SIDE_ATTACK, (5.0f * myWeaponInfo.WeaponLevelNumber));
sprite.handleJump(-12.0f);
}
// If we hit both B and C handle a rear right collision (change movement by 315 degrees)
if(collisionSet.collisionBCIntersects == true)
{
sprite.handleCollision(RIGHT_SIDE_ATTACK, (5.0f * myWeaponInfo.WeaponLevelNumber));
sprite.handleJump(-12.0f);
}
if((sprite.getCurrentAnimation() != PAIN_A) && (sprite.getCurrentAnimation() != PAIN_B)
&& (sprite.getCurrentAnimation() != PAIN_C))
{
soundToPlay->playOnce();
}
sprite.modifyHealthBy(-(projectileDamage * myWeaponInfo.WeaponLevelNumber));
// Setup a death animation on the mine that will kill the sprite as well...
if(spriteIterator->getLevel() < 4)
{
spriteIterator->setLevel(4);
}
}
ProjectileMethodsHandleIfSpriteDead(sprite, myWeaponInfo);
}
}
}
spriteIterator++;
}
}
///<summary>
/// Updates projectiles and handles interaction with elements of level...
/// Returns level state of weapon (e.g. if an upgrade or downgrade occurred)
///</summary>
PROJECTILE_LEVEL_STATE ProjectileMine::updateWeaponAndProjectiles(LevelInfo *levelInfo)
{
ProjectileMethodsUpdateProjectiles(levelInfo, myWeaponInfo);
return ProjectileMethodsUpdateExperience(myWeaponInfo, TOTAL_LEVELS, MAXIMUM_PROJECTILES);
}
///<summary>
/// Renders the weapon projectiles on the screen ...
///</summary>
void ProjectileMine::renderProjectiles(IGraphics *graphics)
{
ProjectileMethodsRender(graphics, myWeaponInfo);
}
/// <summary>
/// Activates an available bullet sprite so that it can shoot off into the wild blue yonder :D
/// </summary>
static void activateProjectile(int weaponLevel, float angleOffset, ISprite *projectile, ISprite *triggeredBySprite, Vector &spriteOffset, IAudio *soundToPlay)
{
// Determine the level of the bullet we're going to activate then activate and Minet moving our bullet sprite
if(weaponLevel == 1)
{
projectile->setLevel(1);
projectile->setHealth(2.7f);
}
else if(weaponLevel == 2)
{
projectile->setLevel(1);
projectile->setHealth(2.6f);
}
else if(weaponLevel == 3)
{
projectile->setLevel(2);
projectile->setHealth(2.5f);
}
else
{
projectile->setLevel(3);
projectile->setHealth(2.4f);
}
ProjectileMethodsActivate( weaponLevel, 1.5, angleOffset, projectile, triggeredBySprite, spriteOffset, soundToPlay);
projectile->setVelocities(1.0f, 0.0f, 0.001f);
projectile->handleJump(-10.0f);
projectile->setControlMagnitude(2.0f);
projectile->increaseAcceleration();
}
///<summary>
/// Handles a change in the trigger state of the weapon...
/// state == pressed/released
/// triggeredBySprite -> The sprite who triggers the projectile to be fired
/// spriteOffset -> The offset created by the tilemap location for the projectile sprite
///</summary>
bool ProjectileMine::handleTriggerState(PROJECTILE_TRIGGER_STATE state, ISprite *triggeredBySprite, Vector &spriteOffset)
{
bool returnValue = ProjectileMethodsIsWeaponReady(state, triggeredBySprite, myWeaponInfo);
if(returnValue == true)
{
// For this projectile, we want to shoot one for every level...
for (int idx = 0; idx < myWeaponInfo.WeaponLevelNumber; idx++)
{
if (myWeaponInfo.Projectiles.at(myWeaponInfo.CurrentProjectileIndex).isDead() == true)
{
triggeredBySprite->setAnimation(CROUCH_ATTACK);
activateProjectile(myWeaponInfo.WeaponLevelNumber, 180, &myWeaponInfo.Projectiles.at(myWeaponInfo.CurrentProjectileIndex), triggeredBySprite,
spriteOffset, myWeaponInfo.ShootingSound);
ProjectileMethodsIncrementProjectile(myWeaponInfo, MAXIMUM_PROJECTILES);
}
}
}
myWeaponInfo.WeaponState = state;
return returnValue;
}