-
Notifications
You must be signed in to change notification settings - Fork 0
/
level5.c
467 lines (405 loc) · 13 KB
/
level5.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
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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
#include<stdio.h>
#include<stdlib.h>
#include<eggx.h>
#include<string.h>
int win, i, a=1;
int type, code;
int time=100;//0.1秒分
int dy=10,dx=5;// 速度変化
int dh=5, dw=5, dr=5;// 大きさ変化
int count=0;// 時間
int kosu=2;//最初の個数
int p=0;//時間の初期値
char k[3];//時間を表記するための文字列
double s, t;// NULL
double x=200.0;//棒人間のx座標の初期値
double x_sq[8],y_sq[8],w_sq[8],h_sq[8];// 四角の座標、縦幅、横幅
double x_circ[8], y_circ[8], r_circ[8];// 円の座標、半径
double harf_y=650;//レベル4で出る画面半分の大きさの円のy座標
double harf_x;//↑の円が右側か左側か
double defence_x, defence_y=570, defence_w=40.0;//防護壁
double defence_h1, defence_h2, defence_h3; //防護壁
double all_x=200.0, all_y=900;//レベル5で出る画面全体の大きさの円のx,y座標
double explo_x, explo_y1=250.0, explo_y2=250.0;//爆発後っぽく見せる線
//プロトタイプ宣言
void game(void);//ゲーム内容
void STA(void);//スタート画面
void input(void);//入力待ち
void syoki_buttai(void);//物体の初期設定
void human(void);//棒人間
void atari(void);//当たり判定
void bougoheki(void);//防護壁
void level(void);//レベル表記
void timecount(void);//タイムの表記
void lastline(void);//最後の線
void LEVEL2(void);//レベル2以上の動作
void LEVEL4(void);//レベル4の動作
void LEVEL5(void);//レベル5の動作
//--------------------------------メイン--------------------------------------
int main(void){
int seed;
//ランダム関数設定
printf("適当に何か入力してreturnを押してください >> ");
scanf("%d", &seed);
srand(seed);
//落ちてくる物体の初期値設定
syoki_buttai();
//画面表示
win=gopen(400, 500);
winname(win, "DODGE GAME");
STA();//スタート画面
if(ggetevent(&type, &code, &s, &t)==win){//入力待ち
if(code==0x073){// sキーを入力した場合
game();
}
else if(code == 0x075){// fキーを押した場合
return 0;
}
}
return 0;
}
//---------------------------サブルーチン-------------------------
void game(void){//ゲーム内容
int j;
gsetnonblock(ENABLE);//ノンブロッキングモードに
while(1){
gclr(win);//画面消去
//防護壁のx座標設定(レベル5になるまで値変化)
defence_x=rand()%400;
if(defence_x > 320){//x座標が340を超えたら340以下の数を減らす
defence_x -= rand()%320;
}
LEVEL5();//レベル5の動作
newpen(win, 1);
level();// レベルの表記
timecount();//時間の表記
human();// 棒人間
input();//入力待ち
for(i=0; i<kosu; i++){
j = rand() % 16;// 色はランダム
if(j < 3) j = j + rand() % 10 + 3;//色は3〜15のどれか
if(a > 2){ //レベル3、4でときどき黒になって消えて見える
if(rand()%5 == 0) j = 0;
}
newpen(win, j);
fillrect(win, x_sq[i], y_sq[i], w_sq[i], h_sq[i]);//四角
fillcirc(win, x_circ[i], y_circ[i], r_circ[i], r_circ[i]);//円
LEVEL4();//レベル4のみ出る円(半分を埋め尽くす円)
//落下速度dx,dy
y_sq[i] -= dy;
y_circ[i] -= dy;
LEVEL2();//レベル2以上で変化させる
}
atari();//当たり判定
msleep(time);// 0.1秒止める
count++;
if(count/10 == 20*a){// カウント10回=約1秒とする
dy += rand()%2+1;//速度変化は毎回変わる
dx += rand()%2;//揺れる大きさ
a++;//レベル
kosu+=rand()%2+1;//増やす個数は毎回変わる
dh+=3;//通常四角の縦幅変化量
dw+=3;//通常四角の横幅変化量
dr+=3;//通常円の半径の変化量
}
}
}
void STA(void){// スタート画面
drawstr(win, 170, 300, 24, 0.0, "SATRT");
drawstr(win, 130, 200, 24, 0.0, "start s-key");
drawstr(win, 130, 100, 24, 0.0, "finish f-key");
}
void input(void){//入力
if(ggetevent(&type, &code, &s, &t) == win){//キー入力待ち
if(code == 0x01c){// 右キー
x += 8.0;
}
else if(code == 0x01d){// 左キー
x -= 8.0;
}
if(x < 5.0 || x > 395.0){// 端に行くと真ん中に強制的に戻る
x = 200.0;
}
}
}
void syoki_buttai(void){//初期値設定
for(i=0; i<8; i++){
x_sq[i] = rand() % 400;
y_sq[i] = rand() % 100+500;
w_sq[i] = rand() % 20+dw;
h_sq[i] = rand() % 20+dh;
x_circ[i] = rand() % 400;
y_circ[i] = rand() % 150 + 500;
r_circ[i] = rand() % 20+dr;
}
//防護壁の設定
defence_h1=defence_h3=80.0;
defence_h2=20.0;
//半分を埋め尽くす円の位置の設定
if(rand()%2==0){
harf_x=0;
}
else if(rand()%2==1){
harf_x=400;
}
}
void human(void){// 棒人間
newpen(win, 1);
fillarc(win,x, 25.0, 5.0, 5.0, 0.0, 360.0, 1);
line(win, x, 5.0, PENUP);
line(win, x, 20.0, PENDOWN);
line(win, x, 5.0, PENUP);
line(win, x-5.0, 0.0, PENDOWN);
line(win, x, 5.0, PENUP);
line(win, x+5.0, 0.0, PENDOWN);
line(win, x, 13.0, PENUP);
line(win, x-5.0, 17.0, PENDOWN);
line(win, x, 13.0, PENUP);
line(win, x+5.0, 17.0, PENDOWN);
}
void atari(void){//当たり判定
//----------------四角の当たり判定-------------------
for(i=0; i<kosu; i++){//通常の四角
if(
( (x > x_sq[i] && x < x_sq[i]+w_sq[i]) &&
(25 > y_sq[i]-5 && 25 < y_sq[i]+h_sq[i]+5) ) ||
( (x_sq[i]-5 < x && x < x_sq[i]+w_sq[i]+5) &&
(y_sq[i] < 25 && 25 < y_sq[i]+h_sq[i]) ) ||
( (x_sq[i]-x)*(x_sq[i]-x)+
(y_sq[i]+w_sq[i]-25)*(y_sq[i]+w_sq[i]-25) < 25) ||
( (x_sq[i]+w_sq[i]-x)*(x_sq[i]+w_sq[i]-x)+
(y_sq[i]+h_sq[i]-25)*(y_sq[i]+h_sq[i]-25) < 25 )
){
gclr(win);
newpen(win, 1);
drawstr(win, 150, 250, 24, 0.0, "GAMEOVER");
msleep(time*30);
exit(0);
}
}
//------------------ここまで---------------------
//----------------丸の当たり判定--------------------
for(i=0; i<kosu; i++){//通常の円
if( (r_circ[i]+5)*(r_circ[i]+5) >
(x-x_circ[i])*(x-x_circ[i])+(25-y_circ[i])*(25-y_circ[i]) ){
gclr(win);
newpen(win, 1);
drawstr(win, 150, 250, 24, 0.0, "GAMEOVER");
msleep(time*30);
exit(0);
}
}
//--------------ここまで-------------------------
if(//左の四角
( (x > defence_x && x < defence_x+defence_w) &&
(25 > defence_y-5 && 25 < defence_y+defence_h1+5) ) ||
( (defence_x-5 < x && x < defence_x+defence_w+5) &&
(defence_y < 25 && 25 < defence_y+defence_h1) ) ||
( (defence_x-x)*(defence_x-x)+(defence_y-25)*(defence_y-25)
< 25 ) ||
( (defence_x-x)*(defence_x-x)+
(defence_y+defence_h1-25)*(defence_y+defence_h1-25) < 25 ) ||
( (defence_x+defence_w-x)*(defence_x+defence_w-x)+
(defence_y-25)*(defence_y-25) < 25 ) ||
( (defence_x+defence_w-x)*(defence_x+defence_w-x)+
(defence_y+defence_h1-25)*(defence_y+defence_h1-25) < 25 )
){
gclr(win);
newpen(win, 1);
drawstr(win, 150, 250, 24, 0.0, "GAMEOVER");
msleep(time*30);
exit(0);
}
if(//真ん中の四角
( (x > defence_x+40 && x < defence_x+40+defence_w) &&
(25 > defence_y+60-5 && 25 < defence_y+60+defence_h2+5) ) ||
( (defence_x+40-5 < x && x < defence_x+40+defence_w+5) &&
(defence_y+60 < 25 && 25 < defence_y+60+defence_h2) ) ||
( (defence_x+40-x)*(defence_x+40-x)+
(defence_y+60-25)*(defence_y+60-25) < 25 ) ||
( (defence_x+40-x)*(defence_x+40-x)+
(defence_y+60+defence_h2-25)*(defence_y+60+defence_h2-25)
< 25 ) ||
( (defence_x+40+defence_w-x)*(defence_x+40+defence_w-x)+
(defence_y+60-25)*(defence_y+60-25) < 25 ) ||
( (defence_x+40+defence_w-x)*(defence_x+40+defence_w-x)+
(defence_y+60+defence_h2-25)*(defence_y+60+defence_h2-25)
< 25 )
){
gclr(win);
newpen(win, 1);
drawstr(win, 150, 250, 24, 0.0, "GAMEOVER");
msleep(time*30);
exit(0);
}
if(//右の四角
( (x > defence_x+80 && x < defence_x+80+defence_w) &&
(25 > defence_y-5 && 25 < defence_y+defence_h3+5) ) ||
( (defence_x+80-5 < x && x < defence_x+80+defence_w+5) &&
(defence_y < 25 && 25 < defence_y+defence_h3) ) ||
( (defence_x+80-x)*(defence_x+80-x)+
(defence_y-25)*(defence_y-25) < 25 ) ||
( (defence_x+80-x)*(defence_x+80-x)+
(defence_y+defence_h3-25)*(defence_y+defence_h3-25) < 25 ) ||
( (defence_x+80+defence_w-x)*(defence_x+80+defence_w-x)+
(defence_y-25)*(defence_y-25) < 25 ) ||
( (defence_x+80+defence_w-x)*(defence_x+80+defence_w-x)+
(defence_y+defence_h3-25)*(defence_y+defence_h3-25) < 25 )
){
gclr(win);
newpen(win, 1);
drawstr(win, 150, 250, 24, 0.0, "GAMEOVER");
msleep(time*30);
exit(0);
}
}
void bougoheki(void){//防護壁の表記
newpen(win,1);
fillrect(win,defence_x, 0.0, defence_w, defence_h1);
fillrect(win,defence_x+40.0, 60.0, defence_w, defence_h2);
fillrect(win,defence_x+80.0, 0.0, defence_w, defence_h3);
}
void level(void){// レベルの表記
if(a==1) drawstr(win, 5, 485, 18, 0.0, "LV1");// 初期レベル1
if(a==2) drawstr(win, 5, 485, 18, 0.0, "LV2");
if(a==3) drawstr(win, 5, 485, 18, 0.0, "LV3");
if(a==4) drawstr(win, 5, 485, 18, 0.0, "LV4");
if(a==5) drawstr(win, 5, 485, 18, 0.0, "LV5");// 最高レベル5
}
void timecount(void){//タイムの表記
if(count % 10 == 0){
p++;
}
sprintf(k, "%d", p);
newpen(win, 1);
drawstr(win, 6, 468, 18, 0.0, k);
}
void lastline(void){//最後の線
for(explo_x=1; explo_x<400; explo_x= explo_x+5){
line(win, explo_x, 250, PENUP);
line(win, explo_x, explo_y1, PENDOWN);
line(win, explo_x, 250, PENUP);
line(win, explo_x, explo_y2, PENDOWN);
}
explo_y1-=5.0;//下に伸びる
explo_y2+=5.0;//上に伸びる
}
void LEVEL2(void){//レベル2以上の動作
if(a>1){ //レベル2以上で左右に揺れる
if(rand()%4 == 0){
x_sq[i]-=dx;
x_circ[i]-=dx;
}
else if(rand()%4 == 2){
x_sq[i]+=dx;
x_circ[i]+=dx;
}
}
//毎回の値の変化
if(y_sq[i] < -5){
x_sq[i] = rand() % 400;
y_sq[i] = rand() % 100+500;
w_sq[i] = rand() % 20+5;
h_sq[i] = rand() % 20+5;
}
if(y_circ[i] < -5){
x_circ[i] = rand() % 400;
y_circ[i] = rand() % 150 + 500;
r_circ[i] = rand() % 20+5;
}
}
void LEVEL4(void){//レベル4に出る半分を埋め尽くす円
if(a==4){//半分を埋め尽くす円
newpen(win, 4);//色は青
fillcirc(win, harf_x, harf_y, 200.0, 200.0);
if(harf_x == 400){//右側の場合の当たり判定
if( (200+5)*(200+5) >
(x-400)*(x-400)+(25-harf_y)*(25-harf_y) ){
gclr(win);
newpen(win, 1);
drawstr(win, 150, 250, 24, 0.0, "GAMEOVER");
msleep(time*30);
exit(0);
}
}
if(harf_x == 0){//左側の場合の当たり判定
if( (200+5)*(200+5) >
(x-0)*(x-0)+(25-harf_y)*(25-harf_y) ){
gclr(win);
newpen(win, 1);
drawstr(win, 150, 250, 24, 0.0, "GAMEOVER");
msleep(time*30);
exit(0);
}
}
harf_y-=5;//落下速度
}
}
void LEVEL5(void){//レベル5の動作
if(a==5){
while(1){
gclr(win);
human();//棒人間
input();//入力待ち
newpen(win, 1);//色は白
//防護壁表記
fillrect(win,defence_x, defence_y, defence_w, defence_h1);
fillrect(win,defence_x+40.0, defence_y+60.0, defence_w, defence_h2);
fillrect(win,defence_x+80.0, defence_y, defence_w, defence_h3);
defence_y -= 15.0;//速度
atari();//当たり判定
//一番下まで落ちたら
if(defence_y == 0){
while(1){
gclr(win);//画面消去
human();//棒人間
input();//入力待ち
bougoheki();//防護壁
atari();//当たり判定
newpen(win, 2);//太陽の色は赤で
fillcirc(win,all_x, all_y, 200, 200);//太陽
all_y-=5.0;//落下速度
//太陽が防護壁に当たったら
if(all_y==280.0){
while(1){
gclr(win);//画面消去
human();//棒人間
input();//入力待ち
bougoheki();//防護壁
atari();//当たり判定
newpen(win, 2);//線は赤
//太陽ぶつかった後の線
lastline();
msleep(time);
if(explo_y1<0){//下に伸びた線が0以下になったら
if(defence_x+40 < x && x < defence_x+80){//中にいれば
newpen(win, 1);
drawstr(win, 180, 250, 24, 0, "SAFE");
msleep(time*10);
gclr(win);
newpen(win, 1);
drawstr(win, 100, 300, 24, 0.0, "CONGRATULATIONS!");
drawstr(win, 170, 250, 24, 0.0, "CLEAR");
msleep(time*30);
exit(0);
}
else {//外にいれば
newpen(win, 1);
drawstr(win, 190, 250, 24, 0, "OUT");
msleep(time*10);
gclr(win);
newpen(win, 1);
drawstr(win, 150, 250, 24, 0.0, "GAMEOVER");
msleep(time*30);
exit(0);
}
}
}
}
msleep(time);
}
}
msleep(time);
}
}
}