-
Notifications
You must be signed in to change notification settings - Fork 0
/
enemy.cpp
149 lines (127 loc) · 3.75 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
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 "enermy.h"
#include <iostream>
using namespace std;
Enemy::Enemy(int x, int y, const char *path){
damage = 0;
this->path = path;
this->x = x; this->y = y; img_enemy = al_load_bitmap(path); up =false;
if(!img_enemy){
cout<<"asdfnv";
}
al_draw_bitmap(img_enemy,x,y,0);
}
int Enemy::get_x(){
return x;
}
int Enemy::get_y(){
return y;
}
void Enemy::update_hit(){
if(++damage ==3){
//delete(); ************************************************************
}
}
poni_arcoiris::poni_arcoiris(int x, int y, const char *path): Enemy(x,y,path){}
bool poni_arcoiris::move_enemy(const int &x1, const int &y1){
if(up){
y+=5;
up=false;
}else{
y-=5;
up=true;
}
x-=2;
al_destroy_bitmap(img_enemy);
img_enemy = al_load_bitmap(path);
al_draw_bitmap(img_enemy,x,y,0);
return false;
}
poni_rudo_weapon::poni_rudo_weapon(int x, int y, const char * path):Weapon(x,y,path){}
poni_rudo::poni_rudo(int x, int y, const char *path):Enemy(x,y, path){srand (time(NULL));}
bool poni_rudo_weapon::move_weapon(){
al_destroy_bitmap(img);
img = al_load_bitmap(path);
x-=10;
if(x<=0){
return false;
}
al_draw_bitmap(img,x,y,0);
return true;
}
bool poni_rudo::move_enemy(const int &x1, const int &y1){
for(int i = 0; i<nubes.size(); i++ ){
nubes[i]->move_weapon();
if(nubes[i]->get_x()>=x1-30 && nubes[i]->get_x()<=x1+30 && nubes[i]->get_y()>=y1-60 && nubes[i]->get_y()<=y1+60){
delete nubes[i];
nubes.erase(nubes.begin()+i);
return true;
}
}
if(up){
y+=5;
up=false;
if(rand() %14==7){
if(nubes.size()<2){
nubes.push_back(new poni_rudo_weapon(x,y,"img/weapon_enemy.png"));
}
}
}else{
y-=5;
up=true;
}
x-=2;
al_destroy_bitmap(img_enemy);
img_enemy = al_load_bitmap(path);
al_draw_bitmap(img_enemy,x,y,0);
return false;
}
vector_enemigos::vector_enemigos(const bool &is_arcoriris, const ALLEGRO_MONITOR_INFO &info){
int i = 3; int space= 20;
while(i--){
if(is_arcoriris){
popoponies.push_back(new poni_arcoiris(info.x2-200, space, "img/enemigo.png"));
}else{
popoponies.push_back(new poni_rudo(info.x2, space, "img/enemigo2.png"));
}
space+=200;
}
}
bool vector_enemigos::move_enemies(const int &x1, const int &y1){
for(int i = 0; i<popoponies.size();i++){
if(popoponies[i]->move_enemy(x1,y1))return true;
if(popoponies[i]->get_x() ==0){
Enemy * temp = popoponies[i];
popoponies.erase(popoponies.begin()+i);
delete temp;
return true;
}
}
return false;
}
bool vector_enemigos::check_collision(const unsigned int &x, const unsigned int &y,int &puntos,Coins &mon){
Coins incremento(0.75);
for(int i = 0; i<popoponies.size();i++){
if(x >= popoponies[i]->get_x() && (y >= popoponies[i]->get_y() && y<= popoponies[i]->get_y()+90)){
Enemy * temp = popoponies[i];
popoponies.erase(popoponies.begin()+i);
delete temp;
puntos+=10;
mon = mon +incremento;
return true;
}
}return false;
}
bool vector_enemigos::is_empty_(){
return popoponies.size()==0;
}
void vector_enemigos::refill(const bool &is_poni_arcoiris, const ALLEGRO_MONITOR_INFO &info){
int i = 3; int space= 20;
while(i--){
if(is_poni_arcoiris){
popoponies.push_back(new poni_arcoiris(info.x2-200, space, "img/enemigo.png"));
}else{
popoponies.push_back(new poni_rudo(info.x2-200, space, "img/enemigo2.png"));
}
space+=200;
}
}