質問編集履歴

5

画像の掲載

2018/05/06 12:57

投稿

plarex
plarex

スコア12

test CHANGED
File without changes
test CHANGED
@@ -1,3 +1,29 @@
1
+ ### 使用している画像
2
+
3
+ ![pStart](1d82ad37ef11356f610de484ff08d0c6.png)
4
+
5
+ ![pGameclear](4ca583c7edd2a4e9120fbdb20348e970.png)
6
+
7
+ ![pGameover](4e978ec35b988da96f457089c34fa209.png)
8
+
9
+ ![pGameback](1e044deacc1f02c55623119762e2e817.png)
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
1
27
  ### 実現したいこと
2
28
 
3
29
  レーザーとボス、自機と弾幕の当たり判定がうまくいきません

4

2018/05/06 12:57

投稿

plarex
plarex

スコア12

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,6 @@
1
1
  ### 実現したいこと
2
2
 
3
- 自機やボスの当たり判定がうまくいきません
3
+ レーザーとボス、自機と弾幕の当たり判定がうまくいきません
4
4
 
5
5
 
6
6
 

3

2018/05/05 15:43

投稿

plarex
plarex

スコア12

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,6 @@
1
1
  ### 実現したいこと
2
2
 
3
- 自機やボスが倒されるとゲーム画面が切替わる仕様にしたいのですがうまくいきません
3
+ 自機やボスの当た判定がうまくいきません
4
4
 
5
5
 
6
6
 

2

コードの変更

2018/05/05 11:36

投稿

plarex
plarex

スコア12

test CHANGED
File without changes
test CHANGED
@@ -38,9 +38,7 @@
38
38
 
39
39
 
40
40
 
41
- private ArrayList<Bullet> danmaku = new ArrayList<Bullet>(); //オブジェクトの宣言,returnで初期値入れる?
41
+ private ArrayList<Bullet> danmaku = new ArrayList<Bullet>();
42
-
43
-
44
42
 
45
43
  enum GameScene {
46
44
 
@@ -256,7 +254,7 @@
256
254
 
257
255
  if (routine % 30 == 0) {
258
256
 
259
- danmaku.addAll(this.shot()); //?????
257
+ danmaku.addAll(this.shot());
260
258
 
261
259
  println("#shot!!" +routine + ":" + tx + "," + ty);
262
260
 
@@ -290,13 +288,13 @@
290
288
 
291
289
  double rad = radians(i);
292
290
 
293
- danmaku.add(new Bullet(this.tx, this.ty, 10, Math.cos(rad), Math.sin(rad))); //↑で作ったそれぞれのインスタンスに代入
291
+ danmaku.add(new Bullet(this.tx, this.ty, 10, Math.cos(rad), Math.sin(rad)));
294
-
292
+
295
- }
293
+ }
296
-
294
+
297
- return danmaku; //3行目のやつに↑を入れる
295
+ return danmaku;
298
-
299
- }
296
+
297
+
300
298
 
301
299
  }
302
300
 

1

コードの変更

2018/05/05 11:36

投稿

plarex
plarex

スコア12

test CHANGED
File without changes
test CHANGED
@@ -8,15 +8,11 @@
8
8
 
9
9
  ### 発生している問題・エラーメッセージ
10
10
 
11
- shipクラスのupdateの中で
11
+ 動くことは動くが当たり判定が出ない
12
-
13
- cannot make a static referrence to the non-static field ship.hp.
12
+
14
-
15
- と出る。
13
+
16
-
17
-
18
-
19
- drawの中のship(mouseX,mouseY)でエラーが出る。
14
+
15
+
20
16
 
21
17
 
22
18
 
@@ -34,13 +30,15 @@
34
30
 
35
31
  Bullet bullet;
36
32
 
37
-
33
+ Ship ship;
34
+
38
-
35
+ Boss boss;
36
+
39
-
37
+ GameStage gamestage;
40
-
41
-
42
-
38
+
39
+
40
+
43
- private ArrayList<Bullet> danmaku = new ArrayList<Bullet>();
41
+ private ArrayList<Bullet> danmaku = new ArrayList<Bullet>(); //オブジェクトの宣言,returnで初期値入れる?
44
42
 
45
43
 
46
44
 
@@ -78,44 +76,50 @@
78
76
 
79
77
 
80
78
 
81
- bullet = new Bullet(width/2, height/2, 10, 0, 0 ); //クラスからインスタンスを生成
79
+ bullet = new Bullet(width/2, height/2, 20, 0, 0 );//クラスからインスタンスを生成
80
+
81
+ ship = new Ship(mouseX,mouseY);
82
+
83
+ gamestage = new GameStage() ;
84
+
85
+ boss = new Boss(160, 150);
82
86
 
83
87
  }
84
88
 
85
89
 
86
90
 
87
- //GameStage class
91
+ //GameStage class
88
-
92
+
89
- class GameStage {
93
+ class GameStage {
90
-
91
- private Boss boss = new Boss(160, 150);
94
+
92
-
93
-
94
-
95
+
96
+
97
+
98
+
95
- void update() {
99
+ void update() {
96
-
100
+
97
- boss.doShinking();
101
+ boss.doShinking();
98
-
99
-
100
-
102
+
103
+
104
+
101
- //画面切り替え
105
+ //画面切り替え
102
-
106
+
103
- if (ship.hp == 0) {
107
+ if (ship.hp == 0) {
104
-
108
+
105
- scene = GameScene.OVER;
109
+ scene = GameScene.OVER;
106
-
110
+
107
- }
111
+ }
108
-
112
+
109
- if (boss.hp == 0) {
113
+ if (boss.hp == 0) {
110
-
114
+
111
- scene = GameScene.CLEAR;
115
+ scene = GameScene.CLEAR;
116
+
117
+ }
112
118
 
113
119
  }
114
120
 
115
121
  }
116
122
 
117
- }
118
-
119
123
 
120
124
 
121
125
 
@@ -124,7 +128,7 @@
124
128
 
125
129
  // ship(自機) class
126
130
 
127
- class ship {
131
+ class Ship {
128
132
 
129
133
  private int sx, sy;
130
134
 
@@ -138,7 +142,7 @@
138
142
 
139
143
  }
140
144
 
141
- ship(int x, int y) {
145
+ Ship(int x, int y) {
142
146
 
143
147
  sx = x;
144
148
 
@@ -156,292 +160,324 @@
156
160
 
157
161
  noFill();
158
162
 
163
+
164
+
165
+ }
166
+
167
+
168
+
169
+ //hit check
170
+
171
+ void damage() {
172
+
173
+ if (abs(ship.sx -boss.tx) < (boss.bw/2)) {
174
+
175
+ boss.hp--;
176
+
177
+ }
178
+
179
+ }
180
+
181
+ }
182
+
183
+
184
+
185
+ // Boss class
186
+
187
+ class Boss {
188
+
189
+ private int tx, ty;
190
+
191
+ private int dx, dy;
192
+
193
+ private int bw = 20;
194
+
195
+ private int bh = 10;
196
+
197
+ private long routine = 0;
198
+
199
+ private int hp = 10;
200
+
201
+ boolean isAlive() {
202
+
203
+ //return is_alive;
204
+
205
+ return hp != 0;
206
+
207
+ }
208
+
209
+
210
+
211
+ Boss(int x, int y) {
212
+
213
+ tx = x;
214
+
215
+ ty = y;
216
+
217
+ dx = 10;
218
+
219
+ dy = -8;
220
+
221
+ }
222
+
223
+ void move() {
224
+
225
+ tx += dx;
226
+
227
+ ty += dy;
228
+
229
+ if (tx < 0 || tx > width) {
230
+
231
+ dx*= -1;
232
+
233
+ }
234
+
235
+ if (ty < 0 || ty > height/3) {
236
+
237
+ dy*= -1;
238
+
239
+ }
240
+
241
+ stroke(255, 204, 0);
242
+
243
+
244
+
245
+ }
246
+
247
+ void doShinking() {
248
+
249
+ routine++;
250
+
251
+ if (routine % 10 == 0) {
252
+
253
+ move();
254
+
255
+ }
256
+
257
+ if (routine % 30 == 0) {
258
+
259
+ danmaku.addAll(this.shot()); //?????
260
+
261
+ println("#shot!!" +routine + ":" + tx + "," + ty);
262
+
263
+ }
264
+
265
+ }
266
+
267
+ //hit check 
268
+
269
+ void damage() {
270
+
271
+ if (dist(tx, ty, ship.sx, ship.sy) < bullet.tr/2) {
272
+
273
+ ship.hp--;
274
+
275
+ }
276
+
277
+ }
278
+
279
+
280
+
281
+
282
+
283
+
284
+
285
+ ArrayList<Bullet> shot() {
286
+
287
+ ArrayList<Bullet> danmaku = new ArrayList();
288
+
289
+ for (int i = 0; i < 360; i+= 10) { //インスタンス(弾幕)の作成
290
+
291
+ double rad = radians(i);
292
+
293
+ danmaku.add(new Bullet(this.tx, this.ty, 10, Math.cos(rad), Math.sin(rad))); //↑で作ったそれぞれのインスタンスに代入
294
+
295
+ }
296
+
297
+ return danmaku; //3行目のやつに↑を入れる
298
+
299
+ }
300
+
301
+ }
302
+
303
+
304
+
305
+ // Bullet(弾幕) class
306
+
307
+
308
+
309
+ class Bullet {
310
+
311
+ private double tx, ty;
312
+
313
+ private final double tr;
314
+
315
+ private double dx, dy;
316
+
317
+ private boolean is_alive = true;
318
+
319
+ Bullet(double x, double y, double r, double temp_dx, double temp_dy ) {
320
+
321
+ tx = x;
322
+
323
+ ty = y;
324
+
325
+ tr = r;
326
+
327
+ dx = temp_dx;
328
+
329
+ dy = temp_dy;
330
+
331
+ }
332
+
333
+ boolean isAlive() {
334
+
335
+ return is_alive;
336
+
337
+ }
338
+
339
+ void update() {
340
+
341
+ tx += dx;
342
+
343
+ ty += dy;
344
+
345
+ //area check
346
+
347
+ if (Math.min(tx, ty) < 0) {
348
+
349
+ is_alive = false;
350
+
351
+ //println("#" + tx + "," + ty);
352
+
353
+ return ;
354
+
355
+ }
356
+
357
+ if (tx > width || ty > height) {
358
+
359
+ is_alive = false;
360
+
361
+ return ;
362
+
363
+ }
364
+
365
+
366
+
367
+ stroke(255, 0, 0);
368
+
369
+
370
+
371
+ ellipse((float)tx, (float)ty, (float)tr, (float)tr);
372
+
373
+ }
374
+
375
+ }
376
+
377
+ void draw() {
378
+
379
+ rect(boss.tx - boss.bw/2, boss.ty + boss.bh/2, boss.bw, boss.bh);
380
+
381
+ fill(255,0,0);
382
+
383
+ text("boss.hp",100,100);
384
+
385
+ fill(255,255,255);
386
+
387
+
388
+
389
+
390
+
391
+ background(0); // clear
392
+
393
+
394
+
159
- triangle(x, y -7, x - 10, y + 7, x + 10, y + 7);
395
+ triangle(mouseX, mouseY -7, mouseX - 10, mouseY + 7, mouseX + 10, mouseY + 7);
396
+
397
+
398
+
160
-
399
+ boss.damage();
400
+
161
-
401
+ ship.damage();
402
+
403
+
404
+
405
+
162
406
 
163
407
  //レーザーの描写
164
408
 
165
409
  if (mousePressed) {
166
410
 
167
- line(x, y - 7, x, 0);
411
+ line(mouseX, mouseY - 7, mouseX, 0);
168
-
412
+
169
- }
413
+ }
414
+
415
+
416
+
417
+
418
+
170
-
419
+ for (int i = danmaku.size() -1; i >= 0; i--) {
420
+
421
+ Bullet b = (Bullet)danmaku.get(i);
422
+
423
+ if (!b.isAlive()) {
424
+
425
+ danmaku.remove(i);
426
+
427
+ continue;
428
+
171
- }
429
+ }
172
-
173
-
174
-
175
- //hit check
430
+
176
-
177
- void damage() {
431
+ b.update();
178
-
179
- if (abs(sx -boss.tx) < (boss.bw /2)) {
432
+
180
-
181
- ship.hp--;
182
-
183
- }
433
+ }
434
+
435
+
436
+
184
-
437
+ if (scene == GameScene.START) {
438
+
439
+ image(pStart, 0, 0);
440
+
185
- }
441
+ }
442
+
443
+ if (mousePressed) {
444
+
445
+ if (mouseButton == LEFT) {
446
+
447
+ scene = GameScene.PLAY;
448
+
449
+ }
450
+
451
+ }
452
+
453
+ if (scene == GameScene.PLAY) {
454
+
455
+ gamestage.update();
456
+
457
+ //image(pGameback,0,0);
458
+
459
+ }
460
+
461
+ if (scene == GameScene.OVER) {
462
+
463
+ image(pGameover, 0, 0);
464
+
465
+
466
+
467
+ }
468
+
469
+ if (scene == GameScene.CLEAR) {
470
+
471
+ image(pGameclear, 0, 0);
472
+
473
+ }
474
+
475
+
476
+
477
+
478
+
479
+
480
+
481
+
186
482
 
187
483
  }
188
-
189
-
190
-
191
- // Boss class
192
-
193
- class Boss {
194
-
195
- private int tx, ty;
196
-
197
- private int dx, dy;
198
-
199
- private int bw = 20;
200
-
201
- private int bh = 10;
202
-
203
- private long routine = 0;
204
-
205
- private int hp = 1000;
206
-
207
- boolean isAlive() {
208
-
209
- //return is_alive;
210
-
211
- return hp != 0;
212
-
213
- }
214
-
215
-
216
-
217
- Boss(int x, int y) {
218
-
219
- tx = x;
220
-
221
- ty = y;
222
-
223
- dx = 1;
224
-
225
- dy = -5;
226
-
227
- }
228
-
229
- void move() {
230
-
231
- tx += dx;
232
-
233
- ty += dy;
234
-
235
- if (tx < 0 || tx > width) {
236
-
237
- dx*= -1;
238
-
239
- }
240
-
241
- if (ty < 0 || ty > height) {
242
-
243
- dy*= -1;
244
-
245
- }
246
-
247
- stroke(255, 204, 0);
248
-
249
- rect(tx - bw/2, ty + bh/2, bw, bh);
250
-
251
- }
252
-
253
- void doShinking() {
254
-
255
- routine++;
256
-
257
- if (routine % 10 == 0) {
258
-
259
- move();
260
-
261
- }
262
-
263
- if (routine % 30 == 0) {
264
-
265
- danmaku.addAll(this.shot());
266
-
267
- println("#shot!!" +routine + ":" + tx + "," + ty);
268
-
269
- }
270
-
271
- }
272
-
273
- //hit check 
274
-
275
- void damage() {
276
-
277
- if (dist(tx, ty, ship.sx, ship.sy) < bullet.tr/2) {
278
-
279
- boss.hp--;
280
-
281
- }
282
-
283
- }
284
-
285
-
286
-
287
-
288
-
289
-
290
-
291
- ArrayList<Bullet> shot() {
292
-
293
- ArrayList<Bullet> danmaku = new ArrayList();
294
-
295
- for (int i = 0; i < 360; i+= 10) { //インスタンス(弾幕)の作成
296
-
297
- double rad = radians(i);
298
-
299
- danmaku.add(new Bullet(this.tx, this.ty, 10, Math.cos(rad), Math.sin(rad)));
300
-
301
- }
302
-
303
- return danmaku;
304
-
305
- }
306
-
307
- }
308
-
309
-
310
-
311
- // Bullet(弾幕) class
312
-
313
-
314
-
315
- class Bullet {
316
-
317
- private double tx, ty;
318
-
319
- private final double tr;
320
-
321
- private double dx, dy;
322
-
323
- private boolean is_alive = true;
324
-
325
- Bullet(double x, double y, double r, double temp_dx, double temp_dy ) {
326
-
327
- tx = x;
328
-
329
- ty = y;
330
-
331
- tr = r;
332
-
333
- dx = temp_dx;
334
-
335
- dy = temp_dy;
336
-
337
- }
338
-
339
- boolean isAlive() {
340
-
341
- return is_alive;
342
-
343
- }
344
-
345
- void update() {
346
-
347
- tx += dx;
348
-
349
- ty += dy;
350
-
351
- //area check
352
-
353
- if (Math.min(tx, ty) < 0) {
354
-
355
- is_alive = false;
356
-
357
- //println("#" + tx + "," + ty);
358
-
359
- return ;
360
-
361
- }
362
-
363
- if (tx > width || ty > height) {
364
-
365
- is_alive = false;
366
-
367
- return ;
368
-
369
- }
370
-
371
-
372
-
373
- stroke(255, 0, 0);
374
-
375
-
376
-
377
- ellipse((float)tx, (float)ty, (float)tr, (float)tr);
378
-
379
- }
380
-
381
- }
382
-
383
- void draw() {
384
-
385
- background(0); // clear
386
-
387
-
388
-
389
- ship(mouseX, mouseY);
390
-
391
- boss.doShinking();
392
-
393
-
394
-
395
- for (int i = danmaku.size() -1; i >= 0; i--) {
396
-
397
- Bullet b = (Bullet)danmaku.get(i);
398
-
399
- if (!b.isAlive()) {
400
-
401
- danmaku.remove(i);
402
-
403
- continue;
404
-
405
- }
406
-
407
- b.update();
408
-
409
- }
410
-
411
-
412
-
413
- if (scene == GameScene.START) {
414
-
415
- image(pStart, 0, 0);
416
-
417
- }
418
-
419
- if (mousePressed) {
420
-
421
- if (mouseButton == LEFT) {
422
-
423
- scene = GameScene.PLAY;
424
-
425
- }
426
-
427
- }
428
-
429
- if (scene == GameScene.PLAY) {
430
-
431
- GameStage.update();
432
-
433
- }
434
-
435
- if (scene == GameScene.OVER) {
436
-
437
- image(pGameover, 0, 0);
438
-
439
- }
440
-
441
- if (scene == GameScene.CLEAR) {
442
-
443
- image(pGameclear, 0, 0);
444
-
445
- }
446
-
447
- }