-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstructures.c
249 lines (203 loc) · 4.08 KB
/
structures.c
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#include "structures.h"
#include "map.h"
#include <stdio.h>
#include <GL/glut.h>
#include "invaders.h"
//inicijalni nizovi
static struct SNexus Nexus;
static struct STower towers[MAX_TOWERS];
static struct SWall walls[MAX_WALLS];
static struct SGuardPost posts[MAX_POSTS];
//inicijalno stanje objekata
int no_towers = 0;
int no_walls = 0;
int no_posts = 0;
//f-ja za inicijalizaciju
void initStructures(){
no_towers = 0;
no_walls = 0;
no_posts = 0;
//niz kula
int j;
for(j=0;j<MAX_TOWERS;j++){
towers[j].x = -1;
towers[j].y = -1;
towers[j].healt = 100;
towers[j].demage = 500;
}
//NEXUS
Nexus.x = 0;
Nexus.y = 0;
Nexus.healt = 200;
//WALLS
for(j=0;j<MAX_WALLS;j++){
walls[j].x = -1;
walls[j].y = -1;
walls[j].healt = 200;
}
//POSTS
for(j=0;j<MAX_POSTS;j++){
posts[j].x = -1;
posts[j].y = -1;
posts[j].healt = 100;
posts[j].demage = 500;
}
}
//F-je za rad sa zidovima
void structPutWall(int x,int y){
if(checkFieldB(x,y)!=1)
return;
if(no_walls == MAX_WALLS)
return;
walls[no_walls].x = x;
walls[no_walls].y = y;
putObject(x,y,WALL_ID);
no_walls++;
}
int getWallX(int i){
return walls[i].x;
}
int getWallY(int i){
return walls[i].y;
}
//F-je sa kulama
void structPutTower(int x,int y){
if(checkFieldB(x,y)!=1)
return;
if(no_towers == MAX_TOWERS)
return;
towers[no_towers].x = x;
towers[no_towers].y = y;
putObject(x,y,TOWER_ID);
no_towers++;
}
int getTowerX(int i){
return towers[i].x;
}
int getTowerY(int i){
return towers[i].y;
}
//F-je za rad sa "cuvarskim postovima"
void structPutPost(int x,int y){
if(checkFieldB(x,y)!=1)
return;
if(no_posts == MAX_POSTS)
return;
posts[no_posts].x = x;
posts[no_posts].y = y;
putObject(x,y,POST_ID);
no_posts++;
}
int getPostX(int i){
return posts[i].x;
}
int getPostY(int i){
return posts[i].y;
}
//pomocna funkcija za ispis u meni
int no_structures(int structId){
switch(structId){
case TOWER_ID:
return MAX_TOWERS - no_towers;
break;
case WALL_ID:
return MAX_WALLS - no_walls;
break;
case POST_ID:
return MAX_POSTS - no_posts;
break;
}
return 0;
}
/*F-je koje obradjuju napade na objekte*/
void attackOnPost(int x,int y,int demage){
int i;
for(i=0;i<MAX_POSTS;i++){
if(posts[i].x == x && posts[i].y == y){
if((posts[i].healt -= demage) <=0){
putObject(posts[i].x, posts[i].y,0);
posts[i].x = -1;
posts[i].y = -1;
}
return;
}
}
}
void attackOnWall(int x,int y,int demage){
int i;
for(i=0;i<MAX_WALLS;i++){
if(walls[i].x == x && walls[i].y == y){
if((walls[i].healt -= demage) <=0){
putObject(walls[i].x, walls[i].y,0);
walls[i].x = -1;
walls[i].y = -1;
}
return;
}
}
}
void attackOnTower(int x,int y,int demage){
int i;
for(i=0;i<MAX_TOWERS;i++){
if(towers[i].x == x && towers[i].y == y){
if((towers[i].healt -= demage) <=0){
putObject(towers[i].x, towers[i].y,0);
towers[i].x = -1;
towers[i].y = -1;
}
return;
}
}
}
void attackOnNexus(int demage){
Nexus.healt -= demage;
}
//F-je za pracenje stanja igre
char checkGame(){
if(Nexus.healt<=0){
return -1;
}
else{
char has_survivors = 0;
int i;
for(i=0;i<MAX_TROUPERS;i++){
if(tIsAlive(i) != 0){
has_survivors = 1;
break;
}
}
if(has_survivors == 0){
for(i=0;i<MAX_EAGLES;i++){
if(eIsAlive(i) != 0){
has_survivors = 1;
break;
}
}
}
return !has_survivors;
}
}
void checkRange(int struct_id,int x,int y, int demage){
int i,j;
if(struct_id == TOWER_ID){
for(i=-1;i<2;i++){
for(j=-1;j<2;j++){
if(checkFieldB(x+i,y+j) == EAGLE_ID){
attackEagle(x+i,y+j,demage);
return;
}
}
}
}
else if(struct_id == POST_ID){
for(i=-1;i<2;i++){
for(j=-1;j<2;j++){
/*if(checkFieldB(x+i,y+j) == EAGLE_ID){
attackEagle(x+i,y+j,demage);*/
if(checkFieldB(x+i,y+j) == TROUPER_ID){
attackTrouper(x+i,y+j,demage);
}
}
}
}
}