-
Notifications
You must be signed in to change notification settings - Fork 0
/
enemy.cpp
109 lines (82 loc) · 2.23 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
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
#include "gameOptions.h"
#include "gameStructs.h"
#include "enemy.h"
Entity enemySetup(int id, int row, sf::Sprite es1, sf::Sprite es2, sf::Sprite es3, sf::Sprite projSprite)
{
Entity tempEnemy;
tempEnemy.ID = id + (row * 10);
tempEnemy.type = Enemy;
tempEnemy.pos.x = WINDOW_WIDTH - (ENEMY_STARTING_DISTANCE_X * id) - ((ENEMY_SPRITE_WIDTH * id) / 2);
tempEnemy.pos.y = (ENEMY_STARTING_DISTANCE_Y * row) - ((ENEMY_SPRITE_HEIGHT * row) / 2);
tempEnemy.size.x = PLAYER_SPRITE_WIDTH;
tempEnemy.size.y = PLAYER_SPRITE_HEIGHT;
//Check the enemy's row. Set it's difficulty depending on the row.
if (tempEnemy.ID < 40)
{
tempEnemy.sprite = es3;
tempEnemy.health = ENEMY_STRONG_MAX_HEALTH;
tempEnemy.score = ENEMY_STRONG_SCORE;
}
if (tempEnemy.ID < 30)
{
tempEnemy.sprite = es2;
tempEnemy.health = ENEMY_NORMAL_MAX_HEALTH;
tempEnemy.score = ENEMY_NORMAL_SCORE;
}
if (tempEnemy.ID < 20)
{
tempEnemy.sprite = es1;
tempEnemy.health = ENEMY_WEAK_MAX_HEALTH;
tempEnemy.score = ENEMY_WEAK_SCORE;
}
tempEnemy.proj.sprite = projSprite;
tempEnemy.projectileOut = false;
tempEnemy.proj.isFriendly = true;
tempEnemy.proj.speed = -PROJECTILE_SPEED;
tempEnemy.proj.size.x = PROJECTILE_SPRITE_WIDTH;
tempEnemy.proj.size.y = PROJECTILE_SPRITE_HEIGHT;
tempEnemy.speed = ENEMY_SPEED_X;
return tempEnemy;
}
void enemyMove(Entity entities[], bool &l)
{
if (l)
{
if (entities[10 + ENEMIES_PER_ROW].pos.x > WINDOW_X_LIMIT)
{
for (int a = 0; a < 100; ++a)
if (entities[a].type == Enemy)
entities[a].pos.x -= entities[a].speed;
}
else
{
for (int a = 0; a < 100; ++a)
if (entities[a].type == Enemy)
entities[a].pos.y += ENEMY_SPEED_Y;
l = !l;
}
}
if (!l)
{
if (entities[11].pos.x < WINDOW_WIDTH - ENEMY_SPRITE_WIDTH - WINDOW_X_LIMIT)
{
for (int a = 0; a < 100; ++a)
if (entities[a].type == Enemy)
entities[a].pos.x += entities[a].speed;
}
else
{
for (int a = 0; a < 100; ++a)
if (entities[a].type == Enemy)
entities[a].pos.y += ENEMY_SPEED_Y;
l = !l;
}
}
}
bool winCheck(Entity entities[])
{
//Check to see if all enemies are dead.
bool b = true;
for (int a = 0; a < 100; ++a) if (entities[a].health > 0 && entities[a].type == Enemy) b = false;
return b;
}