-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnemy.cpp
79 lines (65 loc) · 1.56 KB
/
Enemy.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
#include "Enemy.h"
#include "Application.h"
#include "ModuleCollisions.h"
#include "ModuleParticles.h"
#include "ModuleAudio.h"
#include "ModuleRenderer.h"
#include "ModulePlayer.h"
#include "ModuleDebugInfo.h"
#include "ModuleWeapons.h"
#include <stdlib.h>
#include <time.h>
Enemy::Enemy(int x, int y,bool spawnRight) : position(x, y)
{
spawnPos = position;
despawnLeft = spawnRight;
}
Enemy::~Enemy()
{
if (collider != nullptr)
collider->pendingToDelete = true;
}
const Collider* Enemy::GetCollider() const
{
return collider;
}
void Enemy::Update()
{
if (currentAnim != nullptr)
currentAnim->Update();
if (collider != nullptr)
collider->SetPos(position.x, position.y);
}
void Enemy::Draw()
{
if (currentAnim != nullptr)
App->render->Blit(texture, position.x, position.y, &(currentAnim->GetCurrentFrame()));
}
void Enemy::OnCollision(Collider* collider)
{
if (health > 1) {
health--;
}
else {
App->particles->AddParticle(App->particles->enemyExplosion, position.x, position.y);
App->audio->PlayFx(destroyedFx, 0);
App->player->score += scoreGiven;
if (!App->debugInfo->maxMoney) {
App->player->money += moneyGiven;
}
powerupSpawn = rand() % 35;
if (powerupSpawn == 1) {
App->weapons->SpawnWeapon(WEAPON_TYPE::POWERUP_ORANGE, this->position.x, this->position.y);
}
else if (powerupSpawn == 2) {
App->weapons->SpawnWeapon(WEAPON_TYPE::POWERUP_BLUE, this->position.x, this->position.y);
}
this->SetToDelete();
}
}
void Enemy::SetToDelete()
{
pendingToDelete = true;
if (collider != nullptr)
collider->pendingToDelete = true;
}