-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathModulePowerup.cpp
More file actions
148 lines (129 loc) · 2.74 KB
/
ModulePowerup.cpp
File metadata and controls
148 lines (129 loc) · 2.74 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
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
#include "Application.h"
#include "ModuleInput.h"
#include "ModuleRender.h"
#include "ModulePowerup.h"
#include "ModuleParticles.h"
#include "ModuleTextures.h"
#include "ModulePlayer.h"
#include "ModuleAudio.h"
#include "Powerup.h"
#include "Powerup_Boots.h"
#include "Powerup_Rifle.h"
#include "Powerup_Score.h"
#include "Powerup_Horse.h"
ModulePowerup::ModulePowerup()
{
for (uint i = 0; i < MAX_POWERUPS; ++i)
powerups[i] = nullptr;
}
// Destructor
ModulePowerup::~ModulePowerup()
{
}
bool ModulePowerup::Start()
{
sprites = App->textures->Load("gunsmoke/powerups.png");
audio_pickup = App->audio->LoadFx("gunsmoke/powerup.wav");
return true;
}
update_status ModulePowerup::PreUpdate()
{
// check camera position to decide what to spawn
return UPDATE_CONTINUE;
}
// Called before render is available
update_status ModulePowerup::Update()
{
for (uint i = 0; i < MAX_POWERUPS; ++i)
if (powerups[i] != nullptr)
{
SDL_Rect section = powerups[i]->Draw();
App->render->Blit(sprites, powerups[i]->position.x, powerups[i]->position.y, §ion);
switch (powerups[i]->frame)
{
case 0:
{
powerups[i]->plus = 1;
break;
}
case 3:
{
powerups[i]->plus = -1;
break;
}
default:
break;
}
powerups[i]->frame += powerups[i]->plus;
}
return UPDATE_CONTINUE;
}
update_status ModulePowerup::PostUpdate()
{
// check camera position to decide what to spawn
return UPDATE_CONTINUE;
}
// Called before quitting
bool ModulePowerup::CleanUp()
{
LOG("Freeing all enemies");
App->textures->Unload(sprites);
App->audio->UnLoadFx(audio_pickup);
for (uint i = 0; i < MAX_POWERUPS; ++i)
{
if (powerups[i] != nullptr)
{
delete powerups[i];
powerups[i] = nullptr;
}
}
return true;
}
bool ModulePowerup::AddPowerup(int x, int y, POWERUP_TYPE type)
{
bool ret = false;
uint i = 0;
for (; powerups[i] != nullptr && i < MAX_POWERUPS; ++i);
{
if (i != MAX_POWERUPS)
{
switch (type)
{
case POWERUP_TYPE::POWERUP_BOOTS:
powerups[i] = new Powerup_Boots(x, y);
ret = true;
break;
case POWERUP_TYPE::POWERUP_RIFLE:
powerups[i] = new Powerup_Rifle(x, y);
ret = true;
break;
case POWERUP_TYPE::POWERUP_SCORE:
powerups[i] = new Powerup_Score(x, y);
ret = true;
break;
case POWERUP_TYPE::POWERUP_HORSE:
powerups[i] = new Powerup_Horse(x, y);
ret = true;
break;
}
}
}
return ret;
}
void ModulePowerup::OnCollision(Collider* c1, Collider* c2)
{
for (uint i = 0; i < MAX_POWERUPS; ++i)
{
if (powerups[i] != nullptr && powerups[i]->GetCollider() == c1 )
{
if (c2->type == COLLIDER_PLAYER)
{
powerups[i]->OnCollision();
App->audio->PlayFx(audio_pickup);
delete powerups[i];
powerups[i] = nullptr;
}
break;
}
}
}