-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
392 lines (389 loc) · 8.06 KB
/
test.cpp
File metadata and controls
392 lines (389 loc) · 8.06 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
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
#include<cstring>
#include<iostream>
#include<fstream>
#include<graphics.h>
#include<Windows.h>
using namespace std;
void upute()
{
cleardevice();
bool klik1=0;
settextstyle(0,0,3);
outtextxy(20,50,"UPUTSTVA");
settextstyle(0,0,1);
outtextxy(20,100,"Bit igre je unistiti sve neprijateljske brodove");
outtextxy(20,120,"Prijateljski svemirski brod se krece strijelicama");
outtextxy(20,140,"lijevo-desno na tipkovnici te puca sa tipkom <SPACE>");
outtextxy(20,160,"Legenda neprijatelja:");
setfillstyle(1,1);
bar(60,180,80,200);
setfillstyle(1,12);
bar(100,180,120,200);
setfillstyle(1,14);
bar(140,180,160,200);
setfillstyle(1,13);
bar(180,180,200,200);
setfillstyle(1,WHITE);
bar(0,570,200,640);
outtextxy(15,600,"Natrag na main menu");
z: while(!kbhit() and klik1!=1)
{
klik1=0;
if (ismouseclick(WM_LBUTTONDOWN) and mousex()>=0 and mousey()>=570 and mousex()<=200 and mousey()<=640)
{
klik1=1;
clearmouseclick(WM_LBUTTONDOWN);
}
if(kbhit())
{
getch();
goto z;
}
}
}
void mainmenu()
{
u: cleardevice();
bool klik=0;
settextstyle(0,0,3);
setcolor(GREEN);
outtextxy(100,100,"SPACE INVADERS");
setcolor(WHITE);
setfillstyle(1,WHITE);
bar(150,200,370,250);
settextstyle(0,0,2);
outtextxy(10,600,"Zasluge: Josip Simun Kuci 2TR2");
outtextxy(165,215,"Pokreni igru");
bar(150,300,370,350);
outtextxy(165,315,"Upute igre");
v: while(!kbhit() and klik!=1)
{
klik=0;
if (ismouseclick(WM_LBUTTONDOWN) and mousex()>=150 and mousey()>=200 and mousex()<=320 and mousey()<=250)
{
klik=1;
clearmouseclick(WM_LBUTTONDOWN);
}
else if(ismouseclick(WM_LBUTTONDOWN) and mousex()>=150 and mousey()>=300 and mousex()<=320 and mousey()<=370)
{
klik=1;
clearmouseclick(WM_LBUTTONDOWN);
upute();
klik=0;
goto u;
}
if(kbhit())
{
getch();
goto v;
}
}
}
void pocetak()
{
cleardevice();
settextstyle(0,0,2);
outtextxy(200,320,"Spremni?");
delay(2000);
cleardevice();
outtextxy(200,320,"START!");
delay(2000);
}
int crtanje_broda(int x, int y)
{
setfillstyle(1,GREEN);
bar(x-15,y-10,x+15,y+5);
bar(x-3,y-20,x+3,y-10);
setfillstyle(1, WHITE);
}
int unos(int x)
{
if(GetAsyncKeyState(VK_LEFT))
{
x-=2;
}
else if(GetAsyncKeyState(VK_RIGHT))
{
x+=2;
}
if(x>520)
{
x=520;
}
if(x<0)
{
x=0;
}
return x;
}
int score(int bodovi)
{
setcolor(WHITE);
stringstream ss1;
ss1<<bodovi;
string str1=ss1.str();
char *cstr1 = new char[str1.length() + 1];
strcpy(cstr1, str1.c_str());
settextstyle(3,0,2);
outtextxy(25,20,"SCORE");
outtextxy(50,50,cstr1);
delete [] cstr1;
}
int hscore(int highscore)
{
setcolor(WHITE);
stringstream ss2;
ss2<<highscore;
string str2=ss2.str();
char *cstr2 = new char[str2.length() + 1];
strcpy(cstr2, str2.c_str());
settextstyle(3,0,2);
outtextxy(370,20,"HIGH SCORE");
outtextxy(420,50,cstr2);
delete [] cstr2;
}
int main()
{
initwindow(520,640,"Space Invaders");
setbkcolor(BLACK);
setcolor(GREEN);
cleardevice();
ifstream ulaz("highscore.txt");
fstream izlaz;
c: mainmenu();
int bod, bodovi=0, highscore;
int runda=1;
ulaz>>highscore;
ulaz.close();
int n_zivota=3, brojac=1;
bool gameover=0;
int x_hitac, y_hitac, x_hitac_zlikovac, y_hitac_zlikovac;
o: int x=getmaxx()/2;
int y=550;
float brzina_zlikovca=0.2+(runda*0.1);
bool stanje[52]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},zlikovac[52]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
int broj_unistenih_zlikovaca=0;
bool hitac=0;
int timer=1, brojac_timera=0;
bool stanje_hitca_zlikovca=0;
int zlikovci_y[52]={100,100,100,100,100,100,100,100,100,100,100,100,100,180,180,180,180,180,180,180,180,180,180,180,180,180,260,260,260,260,260,260,260,260,260,260,260,260,260,340,340,340,340,340,340,340,340,340,340,340,340,340};
float zlikovci_x[52]={20,60,100,140,180,220,260,300,340,380,420,460,500,20,60,100,140,180,220,260,300,340,380,420,460,500,20,60,100,140,180,220,260,300,340,380,420,460,500,20,60,100,140,180,220,260,300,340,380,420,460,500};
pocetak();
while(!GetAsyncKeyState('K') and gameover!=1)
{
cleardevice();
score(bodovi);
hscore(highscore);
crtanje_broda(x,y);
for(int i=0;i<52;i++)
{
if(zlikovac[i]==1)
{
if(i<13)
{
setfillstyle(1,1);
goto p;
}
else if(i<26)
{
setfillstyle(1,12);
goto p;
}
else if(i<39)
{
setfillstyle(1,14);
goto p;
}
else
{
setfillstyle(1,13);
goto p;
}
p: bar(zlikovci_x[i]-15,zlikovci_y[i]-15,zlikovci_x[i]+15,zlikovci_y[i]+15);
if(zlikovci_x[i]<=500 && stanje[i]==0)
{
zlikovci_x[i]+=brzina_zlikovca;
}
else if(stanje[i]==1)
{
zlikovci_x[i]-=brzina_zlikovca;
}
if(zlikovci_x[i]>=500 && stanje[i]==0)
{
stanje[i]=1;
zlikovci_y[i]+=40;
}
else if(zlikovci_x[i]<=20 && stanje[i]==1)
{
stanje[i]=0;
zlikovci_y[i]+=40;
}
}
}
for(int j=20;brojac<=n_zivota;j+=40)
{
setcolor(GREEN);
setfillstyle(1,GREEN);
bar(j-10,600,j+10,610);
brojac++;
setfillstyle(1,WHITE);
}
brojac=1;
if(GetAsyncKeyState(VK_SPACE) && hitac==0)
{
hitac=1;
x_hitac=x;
y_hitac=y-10;
}
if(hitac==1)
{
bar(x_hitac-2,y_hitac-5,x_hitac+2,y_hitac+5);
y_hitac-=12;
}
if(y_hitac<=0)
{
hitac=0;
for(int j=1;j<15;j++)
{
circle(x_hitac,y_hitac,j);
}
}
for(int i=0;i<52;i++)
{
if(y_hitac<=(zlikovci_y[i]+15) and x_hitac<=(zlikovci_x[i]+15) and y_hitac>=(zlikovci_y[i]-15) and x_hitac>=(zlikovci_x[i]-15) and hitac==1)
{
hitac=0;
zlikovac[i]=0;
broj_unistenih_zlikovaca++;
if(i<13)
{
bod=40;
goto k;
}
else if(i<26)
{
bod=30;
goto k;
}
else if(i<39)
{
bod=20;
goto k;
}
else
{
bod=10;
goto k;
}
k: bodovi+=bod;
if(bodovi>highscore)
{
highscore=bodovi;
izlaz.open("highscore.txt",ios::out);
izlaz<<highscore;
izlaz.close();
}
for(int j=1;j<25;j++)
{
settextstyle(0,0,1);
setcolor(YELLOW);
circle(zlikovci_x[i],zlikovci_y[i],j);
delay(7);
setcolor(WHITE);
stringstream ss;
ss<<bod;
string str=ss.str();
char *cstr = new char[str.length() + 1];
strcpy(cstr, str.c_str());
outtextxy(zlikovci_x[i]-10,zlikovci_y[i]-10,cstr);
delete [] cstr;
}
zlikovci_x[i]=1000;
zlikovci_y[i]=1000;
brzina_zlikovca+=0.07;
y_hitac=640;
x_hitac=700;
if(broj_unistenih_zlikovaca>=52)
{
runda++;
goto o;
}
}
if(zlikovci_x[i]>=(x-15) && zlikovci_y[i]>=(y-10) && zlikovci_x[i]<=(x+15) && zlikovci_y[i]<=(y+5))
{
for(int j=1;j<=30;j++)
{
delay(25);
setcolor(WHITE);
circle(x,y,j);
}
gameover=1;
}
}
if(brojac_timera==timer)
{
int random=rand()%52;
l: if(zlikovac[random]==1 && stanje_hitca_zlikovca==0)
{
x_hitac_zlikovac=zlikovci_x[random];
y_hitac_zlikovac=zlikovci_y[random];
stanje_hitca_zlikovca=1;
}
else if (stanje_hitca_zlikovca==0)
{
random++;
if(random>52)
{
random=0;
}
goto l;
}
}
if(y_hitac_zlikovac<=(y+5) and x_hitac_zlikovac<=(x+15) and y_hitac_zlikovac>=(y-10) and x_hitac_zlikovac>=(x-15) and stanje_hitca_zlikovca==1)
{
for(int j=1;j<=30;j++)
{
delay(25);
setcolor(WHITE);
circle(x,y,j);
}
delay(30);
x=getmaxx()/2;
y=550;
n_zivota--;
if(n_zivota<1)
{
gameover=1;
}
stanje_hitca_zlikovca=0;
}
if(y_hitac_zlikovac>=640)
{
stanje_hitca_zlikovca=0;
}
if(stanje_hitca_zlikovca==1)
{
bar(x_hitac_zlikovac-2,y_hitac_zlikovac-5,x_hitac_zlikovac+2,y_hitac_zlikovac+5);
y_hitac_zlikovac+=8;
}
if(brojac_timera==52)
{
brojac_timera=0;
}
x=unos(x);
brojac_timera++;
delay(15);
}
cleardevice();
while(!GetAsyncKeyState('R'))
{
setcolor(GREEN);
settextstyle(0,0,2);
outtextxy(200,320,"GAME OVER");
settextstyle(0,0,1);
outtextxy(100,340,"pritisnite gumb R za povratak u main menu");
getch();
}
goto c;
return 0;
}