-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItems.cpp
More file actions
261 lines (249 loc) · 7.7 KB
/
Items.cpp
File metadata and controls
261 lines (249 loc) · 7.7 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
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
254
255
256
257
258
259
260
261
#include "Items.h"
#include "Engine.h"
RPG_Engine* cItem::g_engine = nullptr;
cItem::cItem(std::string name, olc::Sprite* sprite, std::string desc)
{
sName = name; pSprite = sprite; sDescription = desc;
}
cItem_Health::cItem_Health() : cItem("Small Health", RPG_Assets::get().GetSprite("health"), "Restores 10 health")
{
}
bool cItem_Health::OnInteract(cDynamic* object)
{
OnUse(object);
return false; // Just absorb
}
bool cItem_Health::OnUse(cDynamic* object)
{
if (object != nullptr)
{
cDynamic_Creature* dyn = (cDynamic_Creature*)object;
dyn->nHealth = std::min(dyn->nHealth + 10, dyn->nHealthMax);
}
return true;
}
cItem_Coin::cItem_Coin() : cItem("5 gold", RPG_Assets::get().GetSprite("Coin"), "Gives 10 health")
{
}
bool cItem_Coin::OnInteract(cDynamic* object)
{
OnUse(object);
return false; // Just absorb
}
bool cItem_Coin::OnUse(cDynamic* object)
{
//olc::SOUND::PlaySample(RPG_Assets::get().GetSound("GOLD"));
g_engine->engine.PlayWaveform(RPG_Assets::get().GetSound("GOLD"));
if (object != nullptr)
{
cDynamic_Creature* dyn = (cDynamic_Creature*)object;
dyn->nGold = dyn->nGold + 5;
}
return true;
}
cItem_HealthBoost::cItem_HealthBoost() :
cItem("Health Boost", RPG_Assets::get().GetSprite("healthboost"), "Increases Max Health by 10")
{}
bool cItem_HealthBoost::OnInteract(cDynamic* object)
{
//olc::SOUND::PlaySample(RPG_Assets::get().GetSound("PotionPickup"));
g_engine->engine.PlayWaveform(RPG_Assets::get().GetSound("PotionPickup"));
return true; // Add to inventory
}
bool cItem_HealthBoost::OnUse(cDynamic* object)
{
if (object != nullptr)
{
cDynamic_Creature* dyn = (cDynamic_Creature*)object;
dyn->nHealthMax += 10;
dyn->nHealth = dyn->nHealthMax;
//olc::SOUND::PlaySample(RPG_Assets::get().GetSound("PotionPickup"));
g_engine->engine.PlayWaveform(RPG_Assets::get().GetSound("PotionPickup"));
}
return true; // Remove from inventory
}
cItem_ManaBoost::cItem_ManaBoost() : cItem("Mana Boost", RPG_Assets::get().GetSprite("Mana"), "Increases Max Mana by 10")
{}
bool cItem_ManaBoost::OnInteract(cDynamic* object)
{
//olc::SOUND::PlaySample(RPG_Assets::get().GetSound("PotionPickup"));
g_engine->engine.PlayWaveform(RPG_Assets::get().GetSound("PotionPickup"));
return true; // Add to inventory
}
bool cItem_ManaBoost::OnUse(cDynamic* object)
{
if (object != nullptr)
{
cDynamic_Creature* dyn = (cDynamic_Creature*)object;
dyn->nManaMax += 10;
dyn->nMana = dyn->nManaMax;
//olc::SOUND::PlaySample(RPG_Assets::get().GetSound("PotionPickup"));
g_engine->engine.PlayWaveform(RPG_Assets::get().GetSound("PotionPickup"));
}
return true; // Remove from inventory
}
cItem_Key::cItem_Key() : cItem("Key", RPG_Assets::get().GetSprite("healthboost"), "A 'Lost' Key")
{
bKeyItem = true;
}
bool cItem_Key::OnInteract(cDynamic* object)
{
//olc::SOUND::PlaySample(RPG_Assets::get().GetSound("Boom"));
g_engine->engine.PlayWaveform(RPG_Assets::get().GetSound("Boom"));
return true; // Add to inventory
}
bool cItem_Key::OnUse(cDynamic* object)
{
return true; // Remove from inventory
}
cItem_RedKey::cItem_RedKey() : cItem("RedKey", RPG_Assets::get().GetSprite("healthboost"), "Opens Dungeon Door")
{
bKeyItem = true;
}
bool cItem_RedKey::OnInteract(cDynamic* object)
{
//olc::SOUND::PlaySample(RPG_Assets::get().GetSound("Boom"));
g_engine->engine.PlayWaveform(RPG_Assets::get().GetSound("Boom"));
return true; // Add to inventory
}
bool cItem_RedKey::OnUse(cDynamic* object)
{
return true; // Remove from inventory
}
cWeapon::cWeapon(std::string name, olc::Sprite* sprite, std::string desc, int dmg) : cItem(name, sprite, desc)
{
nDamage = dmg;
}
bool cWeapon::OnInteract(cDynamic* object)
{
return false;
}
bool cWeapon::OnUse(cDynamic* object)
{
return false;
}
cWeapon_Sword::cWeapon_Sword() :
cWeapon("Basic Sword", RPG_Assets::get().GetSprite("Basic Sword"), "A wooden sword, 5 dmg", 5)
{
}
bool cWeapon_Sword::OnInteract(cDynamic* object)
{
;
return true; // Add to inventory
}
bool cWeapon_Sword::OnUse(cDynamic* object)
{
cDynamic_Creature* dyn = (cDynamic_Creature*)object;
dyn->pEquipedWeapon = (cWeapon*)RPG_Assets::get().GetItem("Basic Sword");
if (dyn->AttackCoolDown > 0)
{
return false;
}
dyn->AttackCoolDown = dyn->AttackCoolDown + 0.2; //ATTACK COOLDOWN
//olc::SOUND::PlaySample(RPG_Assets::get().GetSound("SwordAttack"));
g_engine->engine.PlayWaveform(RPG_Assets::get().GetSound("SwordAttack"));
// Get direction of attacker
cDynamic_Creature* aggressor = (cDynamic_Creature*)object;
// Determine attack origin
float x, y, vx, vy;
if (aggressor->GetFacingDirection() == 0) // South
{
x = aggressor->px;
y = aggressor->py + 0.8f;
vx = 0.0f; vy = 1.0f;
}
if (aggressor->GetFacingDirection() == 1) // East
{
x = aggressor->px - 0.7f;
y = aggressor->py + 0.2;
vx = -1.0f; vy = 0.0f;
}
if (aggressor->GetFacingDirection() == 2) // North
{
x = aggressor->px;
y = aggressor->py - 0.8f;
vx = 0.0f; vy = -1.0f;
}
if (aggressor->GetFacingDirection() == 3) // West
{
x = aggressor->px + 0.8f;
y = aggressor->py + 0.2;
vx = 1.0f; vy = 0.0f;
}
cDynamic_Projectile* p = new cDynamic_Projectile(x, y, aggressor->bFriendly, aggressor->vx, aggressor->vy, 0.1f, RPG_Assets::get().GetSprite("Basic Sword"), (aggressor->GetFacingDirection() + 3) % 4 + 1, 0.0f);
p->bSolidVsMap = false;
p->bSolidVsDyn = false;
p->nDamage = 5;
p->bOneHit = true;
g_engine->AddProjectile(p);
return true;//
}
cWeapon_FireSword::cWeapon_FireSword() :
cWeapon("Fire Sword", RPG_Assets::get().GetSprite("Fire Sword"), "A Dev sword, 25 dmg", 25)
{
}
bool cWeapon_FireSword::OnInteract(cDynamic* object)
{
return true;
// Equipe
}
bool cWeapon_FireSword::OnUse(cDynamic* object)
{
cDynamic_Creature* dyn = (cDynamic_Creature*)object;
dyn->pEquipedWeapon = (cWeapon*)RPG_Assets::get().GetItem("Fire Sword");
if (dyn->AttackCoolDown > 0)
{
//olc::SOUND::PlaySample(RPG_Assets::get().GetSound("Tired"));
g_engine->engine.PlayWaveform(RPG_Assets::get().GetSound("Tired"));
return false;
}
dyn->AttackCoolDown = dyn->AttackCoolDown + 0.5;
//olc::SOUND::PlaySample(RPG_Assets::get().GetSound("FireBlade"));
g_engine->engine.PlayWaveform(RPG_Assets::get().GetSound("FireBlade"));
// Get direction of attacker
cDynamic_Creature* aggressor = (cDynamic_Creature*)object;
// Determine attack origin
float x, y, vx, vy;
if (aggressor->GetFacingDirection() == 0) // South
{
x = aggressor->px;
y = aggressor->py + 1.0f;
vx = 0.0f; vy = 1.0f;
}
if (aggressor->GetFacingDirection() == 1) // East
{
x = aggressor->px - 1.0f;
y = aggressor->py;
vx = -1.0f; vy = 0.0f;
}
if (aggressor->GetFacingDirection() == 2) // North
{
x = aggressor->px;
y = aggressor->py - 1.0f;
vx = 0.0f; vy = -1.0f;
}
if (aggressor->GetFacingDirection() == 3) // West
{
x = aggressor->px + 1.0f;
y = aggressor->py;
vx = 1.0f; vy = 0.0f;
}
if (aggressor->nMana >= 2)
{
// Beam sword
aggressor->nMana -= 2;
cDynamic_Projectile* p = new cDynamic_Projectile(x, y, aggressor->bFriendly, vx * 15.0f, vy * 15.0f, 1.0f, RPG_Assets::get().GetSprite("Fire Sword"), (aggressor->GetFacingDirection() + 3) % 4 + 1, 1.0f);
p->bSolidVsMap = true;
p->bSolidVsDyn = false;
p->nDamage = 25;
p->bOneHit = true;
g_engine->AddProjectile(p);
}
cDynamic_Projectile* p = new cDynamic_Projectile(x, y, aggressor->bFriendly, aggressor->vx, aggressor->vy, 0.1f, RPG_Assets::get().GetSprite("Fire Sword"), (aggressor->GetFacingDirection() + 3) % 4 + 1, 0.0f);
p->bSolidVsMap = false;
p->bSolidVsDyn = false;
p->nDamage = 25;
p->bOneHit = true;
g_engine->AddProjectile(p);
return true;
}