質問編集履歴
2
ソースコード
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,6 +20,140 @@
|
|
20
20
|
|
21
21
|
```Java
|
22
22
|
|
23
|
+
int px=200;
|
24
|
+
|
25
|
+
int py=350;
|
26
|
+
|
27
|
+
int pw=40;
|
28
|
+
|
29
|
+
int ph=20;
|
30
|
+
|
31
|
+
int ow=30;
|
32
|
+
|
33
|
+
int oh=30;
|
34
|
+
|
35
|
+
int[] oy=new int[10];
|
36
|
+
|
37
|
+
int[] oColor=new int[10];
|
38
|
+
|
39
|
+
int[] oWait=new int[10];
|
40
|
+
|
41
|
+
int score;
|
42
|
+
|
43
|
+
int hp;
|
44
|
+
|
45
|
+
int gseq;
|
46
|
+
|
47
|
+
int mcnt;
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
void setup(){
|
52
|
+
|
53
|
+
size(400,400);
|
54
|
+
|
55
|
+
noStroke();
|
56
|
+
|
57
|
+
gameInit();
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
void draw(){
|
62
|
+
|
63
|
+
background(0);
|
64
|
+
|
65
|
+
if(gseq==0){
|
66
|
+
|
67
|
+
gamePlay();
|
68
|
+
|
69
|
+
}else if(gseq==1){
|
70
|
+
|
71
|
+
gameOver();
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
void playerDisp(){
|
78
|
+
|
79
|
+
fill(255);
|
80
|
+
|
81
|
+
rect(px,py,pw,ph,5);
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
void playerMove(){
|
86
|
+
|
87
|
+
px=mouseX;
|
88
|
+
|
89
|
+
if((px+pw)>width){
|
90
|
+
|
91
|
+
px=width-pw;
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
void objDisp(){
|
98
|
+
|
99
|
+
for(int i=0;i<10;i++){
|
100
|
+
|
101
|
+
if(oColor[i]==0){
|
102
|
+
|
103
|
+
fill(255,0,0);
|
104
|
+
|
105
|
+
}else{
|
106
|
+
|
107
|
+
fill(0,255,0);
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
rect(i*40+5,oy[i],ow,oh,5);
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
void objMove(){
|
118
|
+
|
119
|
+
for(int i=0;i<10;i++){
|
120
|
+
|
121
|
+
if(oWait[i]>0){
|
122
|
+
|
123
|
+
oWait[i]--;
|
124
|
+
|
125
|
+
}else{
|
126
|
+
|
127
|
+
oy[i]+=2;
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
if(oy[i]>height){
|
132
|
+
|
133
|
+
if(oColor[i]==1){
|
134
|
+
|
135
|
+
hp--;
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
objInit(i);
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
void objInit(int no){
|
148
|
+
|
149
|
+
oy[no]=40;
|
150
|
+
|
151
|
+
oColor[no]=int(random(2));
|
152
|
+
|
153
|
+
oWait[no]=int(random(60,240));
|
154
|
+
|
155
|
+
}
|
156
|
+
|
23
157
|
void hitCheck(){
|
24
158
|
|
25
159
|
int ox;
|
@@ -50,7 +184,95 @@
|
|
50
184
|
|
51
185
|
}
|
52
186
|
|
53
|
-
|
187
|
+
void scoreDisp(){
|
188
|
+
|
189
|
+
textSize(24);
|
190
|
+
|
191
|
+
fill(255);
|
192
|
+
|
193
|
+
text("score:"+score,10,25);
|
194
|
+
|
195
|
+
text("HP:"+hp,300,25);
|
196
|
+
|
197
|
+
}
|
198
|
+
|
199
|
+
void gamePlay(){
|
200
|
+
|
201
|
+
objMove();
|
202
|
+
|
203
|
+
objDisp();
|
204
|
+
|
205
|
+
playerMove();
|
206
|
+
|
207
|
+
playerDisp();
|
208
|
+
|
209
|
+
hitCheck();
|
210
|
+
|
211
|
+
scoreDisp();
|
212
|
+
|
213
|
+
if(hp<1){
|
214
|
+
|
215
|
+
gseq=1;
|
216
|
+
|
217
|
+
}
|
218
|
+
|
219
|
+
}
|
220
|
+
|
221
|
+
void gameOver(){
|
222
|
+
|
223
|
+
objDisp();
|
224
|
+
|
225
|
+
playerDisp();
|
226
|
+
|
227
|
+
scoreDisp();
|
228
|
+
|
229
|
+
textSize(50);
|
230
|
+
|
231
|
+
fill(255,255,0);
|
232
|
+
|
233
|
+
text("GAME OVER",60,200);
|
234
|
+
|
235
|
+
mcnt++;
|
236
|
+
|
237
|
+
if((mcnt%60)<40){
|
238
|
+
|
239
|
+
textSize(20);
|
240
|
+
|
241
|
+
fill(255);
|
242
|
+
|
243
|
+
text("Click to retry!!",140,260);
|
244
|
+
|
245
|
+
}
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
void gameInit(){
|
250
|
+
|
251
|
+
for(int i=0;i<10;i++){
|
252
|
+
|
253
|
+
objInit(i);
|
254
|
+
|
255
|
+
}
|
256
|
+
|
257
|
+
score=0;
|
258
|
+
|
259
|
+
hp=10;
|
260
|
+
|
261
|
+
gseq=0;
|
262
|
+
|
263
|
+
mcnt=0;
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
void mousePressed(){
|
268
|
+
|
269
|
+
if(gseq==1){
|
270
|
+
|
271
|
+
gameInit();
|
272
|
+
|
273
|
+
}
|
274
|
+
|
275
|
+
}
|
54
276
|
|
55
277
|
```
|
56
278
|
|
1
ソースコード
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,6 +18,48 @@
|
|
18
18
|
|
19
19
|
|
20
20
|
|
21
|
+
```Java
|
22
|
+
|
23
|
+
void hitCheck(){
|
24
|
+
|
25
|
+
int ox;
|
26
|
+
|
27
|
+
for(int i=0;i<10;i++){
|
28
|
+
|
29
|
+
ox=i*40+5;
|
30
|
+
|
31
|
+
if((px<(ox+ow))&&((px+pw)>ox)
|
32
|
+
|
33
|
+
&&(py<(oy[i]+oh))&&((py+ph)>oy[i])){
|
34
|
+
|
35
|
+
if(oColor[i]==1){
|
36
|
+
|
37
|
+
score+=10;
|
38
|
+
|
39
|
+
}else{
|
40
|
+
|
41
|
+
hp--;
|
42
|
+
|
43
|
+
}
|
44
|
+
|
45
|
+
objInit(i);
|
46
|
+
|
47
|
+
}
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
```
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
当たり判定のソースコードはここだと思うので追加いたしました。
|
60
|
+
|
61
|
+
ご指摘ありがとうございます。
|
62
|
+
|
21
63
|
|
22
64
|
|
23
65
|
### 試したこと
|