-
Notifications
You must be signed in to change notification settings - Fork 0
/
enemy.cpp
74 lines (57 loc) · 1.53 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
#include "enemy.h"
#include "game.h"
void generate_enemy(){
static uint8_t type = 1;
if(array_enemies_length == array_enemies_allocated){
array_enemies_allocated += 2;
game.enemies_array = (Enemy *)realloc(game.enemies_array, sizeof(Enemy) * array_enemies_allocated);
}
if(--counters_array[BOSS_COUNTER] == 1){
type = TYPE4_ENEMY;
counters_array[BOSS_COUNTER] = BOSS_BASE_COUNTER;
} else{
type = rand() % 3;
}
Enemy enemy;
enemy.pos.x = RIGHT_BORDER;
enemy.pos.y = rand() % (6 - enemies_stats_array[type][SIZE] );
if(type){
enemy.type = type;
type = 0;
} else {
enemy.type = type;
type = 1;
}
enemy.hitpoints_left = enemies_stats_array[type][HP_TOTAL];
game.enemies_array[array_enemies_length++] = enemy;
}
void move_enemies(uint8_t type){
for(uint8_t i = 0; i < array_enemies_length; i++){
if(game.enemies_array[i].type == type){
if(game.enemies_array[i].pos.x == 0){
game.enemies_array[i].pos.x = LEFT_BORDER;
} else {
game.enemies_array[i].pos.x -= 1;
}
}
}
general_collision_detection();
for(uint8_t i = 0; i< array_enemies_length; i++){
if(game.enemies_array[i].pos.x == LEFT_BORDER){
player_dead();
}
}
}
void clean_enemies_array(){
for(uint8_t i = 0; i< array_enemies_length; i++){
while(game.enemies_array[i].pos.x == LEFT_BORDER){
if(i + 1 == array_enemies_length){
array_enemies_length -= 1;
break;
} else {
//else place last bullet on current bullet (to overwrite)
game.enemies_array[i] = game.enemies_array[--array_enemies_length];
}
}
}
}