-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.cpp
More file actions
221 lines (126 loc) · 3.5 KB
/
Game.cpp
File metadata and controls
221 lines (126 loc) · 3.5 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
#include "Game.h"
Game::Game(){
GAMEOVER = false;
active_enemies =3;
Hero_Ship = new Hero;
Game::buffer=create_bitmap(800,600);
Game::background= create_bitmap(800,600);
Game::temp1 = create_bitmap(800,600);
for (int a=0; a<3; a++){
Enemy_Ship[a] = new Enemy;
}
}
void Game::Level_cleared(){
temp1 = load_bitmap("images/splash/levelclear.bmp", NULL);
masked_blit(temp1,buffer,0,0,80,300,648,78);
destroy_bitmap(temp1);
}
void Game::Set_Screen(char *filename){
Game::temp1 = load_bitmap(filename,NULL);
blit(temp1,screen, 0,0,0,0,800,600);
destroy_bitmap(temp1);
}
void Game::buffer_screen(){
blit(buffer,screen,0,0,0,0,800,600);
}
void Game::Set_buffer(char *filename){
Game::buffer = load_bitmap(filename,NULL);
}
void Game::Set_background(char *filename){
Game::temp1 = load_bitmap(filename,NULL);
blit(temp1,background,0,0,0,0,800,600);
}
void Game::Put_background(){
blit (background,buffer,0,0,0,0,800,600);
}
void Game::move_hero(){
Game::Hero_Ship->Move(Game::buffer);
}
void Game::move_enemy(int move_type){
if (move_type ==0)
for (int a=0; a<active_enemies; a++){
if(Enemy_Ship[a]->isalive() )
Game::Enemy_Ship[a]->Move_horizontal(Game::buffer);
}
else if (move_type ==1)
for (int a=0; a<active_enemies; a++){
if(Enemy_Ship[a]->isalive() )
Game::Enemy_Ship[a]->Move(Game::buffer);
}
//textprintf_ex(Game::buffer, font, 0, 0, makecol(255, 0, 0),-1,"x: %d", x_ofenemy() );
//textprintf_ex(Game::buffer, font, 0, 20, makecol(255, 0, 0),-1,"y: %d", y_ofenemy() );
//textprintf_ex(Game::buffer, font, 0, 40, makecol(255, 0, 0),-1,"HEALTH: %d", Hero_Ship->life() );
}
void Game::fire_hero(){
Game::Hero_Ship->Fire(Game::buffer );
}
void Game::fire_enemy(){
for(int a=0; a<active_enemies; a++)
if(Enemy_Ship[a]->isalive() )
Game::Enemy_Ship[a]->Fire(Game::buffer);
}
int Game::x_ofenemy(){
for(int a=0; a<active_enemies; a++){
if(Enemy_Ship[a]->isalive() )
return Enemy_Ship[a]->give_x();
}
}
int Game::y_ofenemy(){
for(int a=0; a<active_enemies; a++){
if(Enemy_Ship[a]->isalive() )
return Enemy_Ship[a]->give_y();
}
}
void Game::check_firecollision(){
for(int a=0; a<active_enemies; a++)
if(Hero_Ship->x() > Enemy_Ship[a]->give_x() -20 && Hero_Ship->x() < Enemy_Ship[a]->give_x() +30 && Hero_Ship->y() > Enemy_Ship[a]->give_y() )
if(Enemy_Ship[a]->isalive())
Enemy_Ship[a]->destroy_ship();
}
void Game::check_damageintake(int amount){
for(int a=0; a<active_enemies; a++)
if(Enemy_Ship[a]->give_x()> Hero_Ship->x() -14 && Enemy_Ship[a]->give_x() < Hero_Ship->x() +14 && Enemy_Ship[a]->give_y() < Hero_Ship->y() ) {
if(amount ==0)
Hero_Ship->take_Ldamage();
else if (amount ==1)
Hero_Ship->take_Mdamage();
else if (amount ==2)
Hero_Ship->take_Hdamage();
}
}
bool Game::isGAMEOVER(){
if(!Hero_Ship->isalive()){
GAMEOVER = true;
return true;
}
for(int a=0; a<active_enemies; a++){
if(Enemy_Ship[a]->isalive() ){
GAMEOVER= false;
return GAMEOVER;
}
}
return true;
}
bool Game::isHero_alive(){
if (Hero_Ship->isalive())
return true;
else
Hero_Ship->destroy_ship();
return false;
}
void Game::change_enemyno(int ok){
active_enemies = ok;
}
void Game::Reset(int enemyno, bool speedup){
Set_Screen("images/splash/loading.bmp");
GAMEOVER= false;
for(int a=0; a<active_enemies; a++)
delete Enemy_Ship[a];
active_enemies = enemyno;
for(int a=0; a<active_enemies; a++){
Enemy_Ship[a] = new Enemy;
if(speedup)
Enemy_Ship[a]->speed_UP();
}
rest(70);
}