質問編集履歴

3

追記しました

2019/05/04 03:51

投稿

noberon
noberon

スコア17

test CHANGED
File without changes
test CHANGED
@@ -8,7 +8,9 @@
8
8
 
9
9
 
10
10
 
11
- 以下にはおそらく問題であろうプレイヤー動き関する部分だけ載せておきます。
11
+ 文字数制限があるので変更後のコードは以下に、変更前のコード編集依頼返信画面に載せてあります。
12
+
13
+ お手数おかけしますがご確認よろしくお願いします。
12
14
 
13
15
 
14
16
 

2

文字数制限があるので変更後のみ載せます。自機の移動ができなくなったのでPlayer系の関数に問題があると思います

2019/05/04 03:51

投稿

noberon
noberon

スコア17

test CHANGED
File without changes
test CHANGED
@@ -12,9 +12,9 @@
12
12
 
13
13
 
14
14
 
15
+
16
+
15
- ,,,processing 変更
17
+ ,,,processing 変更後(引数渡し)
16
-
17
-
18
18
 
19
19
  int keyy; //流れ管理
20
20
 
@@ -24,11 +24,13 @@
24
24
 
25
25
 
26
26
 
27
+ int px1=240,py1=50,ph1=50,pw1=50; //プレイヤー1の座標と高さ幅
28
+
27
- int px,pw=50,py=50,ph=50;
29
+ int px2,pw2=50,py2=700,ph2=50;//プレイヤー2の座標と高さ幅
28
-
29
-
30
-
30
+
31
+
32
+
31
- float[] ex =new float[12];
33
+ float[] ex =new float[12]; //敵の座標
32
34
 
33
35
  int[] ey = new int[12];
34
36
 
@@ -38,9 +40,13 @@
38
40
 
39
41
 
40
42
 
41
- int[] bPx = new int[6]; //Player弾
43
+ int[] bPx1 = new int[6]; //Player弾
42
-
44
+
43
- int[] bPy = new int[6];
45
+ int[] bPy1= new int[6];
46
+
47
+ int[] bPx2 = new int[6]; //Player弾
48
+
49
+ int[] bPy2= new int[6];
44
50
 
45
51
 
46
52
 
@@ -74,7 +80,7 @@
74
80
 
75
81
  imgLoad();
76
82
 
77
- gameInit(); //ゲーム初期化
83
+ gameInit(bPy1); //ゲーム初期化
78
84
 
79
85
  }
80
86
 
@@ -92,6 +98,8 @@
92
98
 
93
99
  }else if( keyy == 1){
94
100
 
101
+ //px1,py1,pw1,ph1,bPx1,bPy1
102
+
95
103
  gamePlay();
96
104
 
97
105
  }else if( keyy == 2){
@@ -106,11 +114,15 @@
106
114
 
107
115
 
108
116
 
109
- void gameInit(){
117
+ void gameInit(int[] bPy){
110
118
 
111
119
  keyy = 0;
112
120
 
113
- px =240;
121
+ //px =240;
122
+
123
+
124
+
125
+
114
126
 
115
127
  for(int i =0; i<12; i++){
116
128
 
@@ -152,19 +164,21 @@
152
164
 
153
165
  }
154
166
 
167
+ //int px,int py,int pw,int ph,int[]bPx,int[]bPy
168
+
155
169
  void gamePlay(){
156
170
 
157
- playerMove();
171
+ playerMove(bPx1,bPy1,px1,pw1);
158
-
172
+
159
- image(player1,px,py,pw,ph);
173
+ image(player1,px1,py1,pw1,ph1);
160
174
 
161
175
  enemyMove();
162
176
 
163
- enemyDisp();
177
+ enemyDisp(bPx1,bPy1);
164
-
178
+
165
- bombPMove();
179
+ bombPMove(bPx1,bPy1);
166
-
180
+
167
- bombEMove();
181
+ bombEMove(px1,py1,pw1,ph1);
168
182
 
169
183
  scoreDisp();
170
184
 
@@ -188,7 +202,7 @@
188
202
 
189
203
  }
190
204
 
191
- void playerMove(){
205
+ void playerMove(int[] bPx,int[] bPy,int px,int pw){
192
206
 
193
207
  // if( (keyPressed == true) && (key == CODED) ){
194
208
 
@@ -216,7 +230,7 @@
216
230
 
217
231
  bombWait =10; //10秒まち
218
232
 
219
- bombPAdd();
233
+ bombPAdd(bPx,bPy,px,pw);
220
234
 
221
235
 
222
236
 
@@ -254,216 +268,284 @@
254
268
 
255
269
 
256
270
 
257
-
258
-
259
- ,,,processing 変更後(引数渡し)
260
-
261
- int keyy; //流れ管理
262
-
263
- PImage player1,bg, bombP;// bP: プレイヤーの弾
264
-
265
- PImage[] enemy = new PImage[2];
266
-
267
- int px1=240,py1=50,ph1=50,pw1=50; //プレイヤー1の座標と高さ幅
268
-
269
- int[] bPx1 = new int[6]; //Player弾
270
-
271
- int[] bPy1= new int[6];
272
-
273
- int bombWait;
274
-
275
- int keyKeep; //押下中のキー
276
-
277
-
278
-
279
-
280
-
281
- void setup(){
282
-
283
- size(600,800);
284
-
285
- noStroke();
286
-
287
- frameRate(30);
288
-
289
- imgLoad();
290
-
291
- gameInit(bPy1); //ゲーム初期化
292
-
293
- }
294
-
295
-
296
-
297
- void draw(){
298
-
299
- background(100);
300
-
301
- if( keyy == 0){
302
-
303
- gameTitle();
304
-
305
-
306
-
307
- }else if( keyy == 1){
308
-
309
- //px1,py1,pw1,ph1,bPx1,bPy1
310
-
311
- gamePlay();
312
-
313
- }else if( keyy == 2){
314
-
315
- gameOver();
316
-
317
- }
318
-
319
-
320
-
321
- }
322
-
323
-
324
-
325
- void gameInit(int[] bPy){
326
-
327
- keyy = 0;
328
-
329
- //px1 =240;
330
-
331
-
332
-
333
-
334
-
335
- for(int i =0; i<12; i++){
336
-
337
- ef[i] = 2;
338
-
339
- }
340
-
341
- for(int i=0; i<6; i++){
342
-
343
- bPy[i] = -20; //-20:未使用
344
-
345
- }
346
-
347
- bombWait = 0;
348
-
349
- keyKeep = 0;
350
-
351
-
352
-
353
- for(int i=0; i<20; i++){
354
-
355
- bEy[i] = -20; //-20:未使用
356
-
357
- }
358
-
359
-
360
-
361
- }
362
-
363
- void gameTitle(){
364
-
365
- keyy =1;
366
-
367
- }
368
-
369
- //int px,int py,int pw,int ph,int[]bPx,int[]bPy
370
-
371
- void gamePlay(){
372
-
373
- playerMove(bPx1,bPy1,px1,pw1);
374
-
375
- image(player1,px1,py1,pw1,ph1);
376
-
377
- enemyMove();
378
-
379
- enemyDisp(bPx1,bPy1);
380
-
381
- bombPMove(bPx1,bPy1);
382
-
383
- bombEMove(px1,py1,pw1,ph1);
384
-
385
- scoreDisp();
386
-
387
- }
388
-
389
- void gameOver(){
390
-
391
- scoreDisp();
392
-
393
- }
394
-
395
-
396
-
397
- void imgLoad(){
398
-
399
- player1 = loadImage("player1.png");
400
-
401
- enemy[0] =loadImage("敵.png");
402
-
403
- bombP =loadImage("弾.png");
404
-
405
- }
406
-
407
- void playerMove(int[] bPx,int[] bPy,int px,int pw){
408
-
409
- // if( (keyPressed == true) &&(key == CODED) ){
410
-
411
- if( ( keyKeep == LEFT) &&(px>0) ){
412
-
413
- px -= 3;
414
-
415
- }
416
-
417
- if( ( keyKeep == RIGHT) &&(px <600-pw) ){
418
-
419
- px += 3;
420
-
421
- }
422
-
423
- // }
424
-
425
- if( bombWait>0){
426
-
427
- bombWait--;
428
-
429
- }
430
-
431
- if( (keyPressed == true) &&(key == ' ' ) &&(bombWait == 0) ){
432
-
433
- bombWait =10; //10秒まち
434
-
435
- bombPAdd(bPx,bPy,px,pw);
436
-
437
-
438
-
439
- }
440
-
441
- }
442
-
443
- void keyPressed(){
444
-
445
- if (key == CODED){
446
-
447
- if( (keyCode == LEFT) || (keyCode == RIGHT) ){
448
-
449
- keyKeep = keyCode;
450
-
451
- }
452
-
453
- }
454
-
455
- }
456
-
457
- void keyReleased(){
458
-
459
- if (key == CODED){
460
-
461
- if( (keyCode == LEFT) || (keyCode == RIGHT) ){
462
-
463
- keyKeep = 0;
464
-
465
- }
466
-
467
- }
468
-
469
- }
271
+ void enemyMove(){
272
+
273
+ for(int i=0; i<12; i++){
274
+
275
+ ex[i] += ev[i];
276
+
277
+ if( (ef[i] ==0) && (ex[i] < -50) ){
278
+
279
+ ef[i]= 2; //画面外皮表示
280
+
281
+ }
282
+
283
+ if( (ef[i] ==1) && (ex[i] >600) ){
284
+
285
+ ef[i]= 2; //画面外皮表示
286
+
287
+ }
288
+
289
+ }
290
+
291
+ if ( random(1000)<20){ //敵の発生率
292
+
293
+ enemyAdd();
294
+
295
+ }
296
+
297
+ }
298
+
299
+
300
+
301
+
302
+
303
+ void enemyDisp(int[] bPx,int[] bPy){
304
+
305
+ for(int i=0; i<12; i++){
306
+
307
+ if ( ef[i] <2){
308
+
309
+ image(enemy[0],ex[i],ey[i],50,50);
310
+
311
+
312
+
313
+ for(int j=0; j<6; j++){
314
+
315
+ if( (bPx[j] < ex[i]+50) && (bPx[j]+25 > ex[i])
316
+
317
+ && (bPy[j] < ey[i]+50) && (bPy[j]+25 > ey[i]) ){
318
+
319
+ bPy[j] = -20;
320
+
321
+ ef[i] = 2;
322
+
323
+ scoreS +=10;
324
+
325
+ break;
326
+
327
+ }
328
+
329
+
330
+
331
+ }
332
+
333
+
334
+
335
+ }
336
+
337
+ if ( (ef[i] < 2) && (random(2000)<10) ){ //敵爆弾発生率
338
+
339
+ bombEAdd(int (ex[i]), ey[i] );
340
+
341
+ }
342
+
343
+ }
344
+
345
+ }
346
+
347
+
348
+
349
+ void enemyAdd(){
350
+
351
+ for(int i=0; i<12; i++){
352
+
353
+ if( ef[i] == 2){ //未使用の中から敵を追加
354
+
355
+ ev[i] = random(0.5,2.5);
356
+
357
+ if (random(100) <50){
358
+
359
+ ef[i] = 0 ; //左
360
+
361
+ ex[i] = 600;
362
+
363
+ ev[i] =-ev[i] ;
364
+
365
+ }
366
+
367
+ else{
368
+
369
+ ef[i] = 1;
370
+
371
+ ex[i]= -80;
372
+
373
+ }
374
+
375
+ ey[i] = int(random(150,650));
376
+
377
+ break;
378
+
379
+ }
380
+
381
+ }
382
+
383
+ }
384
+
385
+
386
+
387
+ void bombPAdd(int[] bPx,int[]bPy,int px,int pw){
388
+
389
+ for(int i=0; i<3; i++){
390
+
391
+ if ( bPy[i] == -20){ //未使用の弾を使う
392
+
393
+ bPx[i] = px + (pw/2)-15; //Pの中心
394
+
395
+ bPy[i] = 70;
396
+
397
+ break; //一発のみ
398
+
399
+ }
400
+
401
+ }
402
+
403
+ }
404
+
405
+
406
+
407
+ void bombPMove(int[] bPx,int[]bPy){
408
+
409
+ int bcnt =3;
410
+
411
+ for(int i= 0; i<3; i++){
412
+
413
+ if ( bPy[i] >0){
414
+
415
+ bPy[i] += 5;
416
+
417
+ bcnt--;
418
+
419
+ }
420
+
421
+ if ( bPy[i] >800){ //画面上外
422
+
423
+ bPy[i] = -20; //未使用に戻す
424
+
425
+ }
426
+
427
+ image(bombP,bPx[i],bPy[i]-8,30,30);
428
+
429
+ //for(int e= 0; e<12; e++){
430
+
431
+ // if( (bPx[i] < ex[e]+50) && (bPx[i]+25 > ex[e])
432
+
433
+ // && (bPy[i] < ey[e]+50) && (bPy[i]+25 > ey[e]) ){
434
+
435
+ // scoreS +=10;
436
+
437
+
438
+
439
+ // }
440
+
441
+ //}
442
+
443
+
444
+
445
+ }
446
+
447
+ for(int i=0; i< bcnt; i++){
448
+
449
+ image(bombP, 230+i*26,10,25,25);
450
+
451
+ }
452
+
453
+ }
454
+
455
+
456
+
457
+ void bombEAdd(int xx, int yy){
458
+
459
+ for( int i=0; i<20; i++){
460
+
461
+ if ( bEy[i] == -20){
462
+
463
+ bEx[i] = xx +18;
464
+
465
+ bEy[i] = yy;
466
+
467
+ if( random(100) < 50 ){
468
+
469
+ bEv[i] = 1;
470
+
471
+ }else{
472
+
473
+ bEv[i] = -1;
474
+
475
+ }
476
+
477
+ break;
478
+
479
+ }
480
+
481
+ }
482
+
483
+ }
484
+
485
+
486
+
487
+ void bombEMove(int px,int py,int pw,int ph ){
488
+
489
+ for( int i = 0; i<20; i++){
490
+
491
+ //bEv[i] = 1;
492
+
493
+ if ( (bEy[i] > 0) ){
494
+
495
+ //if( random(100) < 50 ){
496
+
497
+ bEy[i] -= bEv[i];
498
+
499
+ // }
500
+
501
+ //else{
502
+
503
+ // bEy[i] +=bEv[i];
504
+
505
+ //}
506
+
507
+ }
508
+
509
+ if(( bEy[i] <= 0) || ( bEy[i] >=800) ) {
510
+
511
+ //if(bEy[i] < 90) {
512
+
513
+ bEy[i] = -20;
514
+
515
+ }
516
+
517
+
518
+
519
+ if( (bEx[i] < px+pw) && (bEx[i]+10 >px)
520
+
521
+ && (bEy[i] < py+ph) && (bEy[i]+10 >py) ) {
522
+
523
+ bEy[i] = -20;
524
+
525
+ scoreS -=50;
526
+
527
+ }
528
+
529
+
530
+
531
+
532
+
533
+ fill(0);
534
+
535
+ rect(bEx[i],bEy[i],10,10);
536
+
537
+ // image(bombP,bEx[i],bEy[i]-8,10,10);
538
+
539
+ }
540
+
541
+ }
542
+
543
+
544
+
545
+ void scoreDisp(){
546
+
547
+ textSize(24);
548
+
549
+ text( "score:"+scoreS, 10,25);
550
+
551
+ }

1

プログラムの変更前と後を追記

2019/05/04 03:47

投稿

noberon
noberon

スコア17

test CHANGED
File without changes
test CHANGED
@@ -8,9 +8,11 @@
8
8
 
9
9
 
10
10
 
11
- 以下にはおそらく問題であろう部分だけ載せておきますが、補足に全プログラムを載せておきます
11
+ 以下にはおそらく問題であろうプレイヤーの動きに関する部分だけ載せておきます。
12
+
13
+
14
+
12
-
15
+ ,,,processing 変更前
13
-
14
16
 
15
17
 
16
18
 
@@ -20,6 +22,248 @@
20
22
 
21
23
  PImage[] enemy = new PImage[2];
22
24
 
25
+
26
+
27
+ int px,pw=50,py=50,ph=50;
28
+
29
+
30
+
31
+ float[] ex =new float[12];
32
+
33
+ int[] ey = new int[12];
34
+
35
+ int[] ef = new int[12]; //フラグ  0:左方向  1:右方向 2:未使用
36
+
37
+ float[] ev = new float[12]; //敵の移動速度
38
+
39
+
40
+
41
+ int[] bPx = new int[6]; //Player弾
42
+
43
+ int[] bPy = new int[6];
44
+
45
+
46
+
47
+ int[] bEx = new int[20]; //Enemy弾
48
+
49
+ int[] bEy = new int[20];
50
+
51
+ int[] bEv = new int[20]; //E弾速度
52
+
53
+
54
+
55
+ int bombWait;
56
+
57
+ int keyKeep; //押下中のキー
58
+
59
+
60
+
61
+ int scoreS = 0;
62
+
63
+ int scoreC = 0;
64
+
65
+
66
+
67
+ void setup(){
68
+
69
+ size(600,800);
70
+
71
+ noStroke();
72
+
73
+ frameRate(30);
74
+
75
+ imgLoad();
76
+
77
+ gameInit(); //ゲーム初期化
78
+
79
+ }
80
+
81
+
82
+
83
+ void draw(){
84
+
85
+ background(100);
86
+
87
+ if( keyy == 0){
88
+
89
+ gameTitle();
90
+
91
+
92
+
93
+ }else if( keyy == 1){
94
+
95
+ gamePlay();
96
+
97
+ }else if( keyy == 2){
98
+
99
+ gameOver();
100
+
101
+ }
102
+
103
+
104
+
105
+ }
106
+
107
+
108
+
109
+ void gameInit(){
110
+
111
+ keyy = 0;
112
+
113
+ px =240;
114
+
115
+ for(int i =0; i<12; i++){
116
+
117
+ ef[i] = 2;
118
+
119
+ //ex[i] = i*20;
120
+
121
+ //ey[i] = 110 + i*50;
122
+
123
+ //ev[i] =random(0.5,2.5);
124
+
125
+ }
126
+
127
+ for(int i=0; i<6; i++){
128
+
129
+ bPy[i] = -20; //-20:未使用
130
+
131
+ }
132
+
133
+ bombWait = 0;
134
+
135
+ keyKeep = 0;
136
+
137
+
138
+
139
+ for(int i=0; i<20; i++){
140
+
141
+ bEy[i] = -20; //-20:未使用
142
+
143
+ }
144
+
145
+
146
+
147
+ }
148
+
149
+ void gameTitle(){
150
+
151
+ keyy =1;
152
+
153
+ }
154
+
155
+ void gamePlay(){
156
+
157
+ playerMove();
158
+
159
+ image(player1,px,py,pw,ph);
160
+
161
+ enemyMove();
162
+
163
+ enemyDisp();
164
+
165
+ bombPMove();
166
+
167
+ bombEMove();
168
+
169
+ scoreDisp();
170
+
171
+ }
172
+
173
+ void gameOver(){
174
+
175
+ scoreDisp();
176
+
177
+ }
178
+
179
+
180
+
181
+ void imgLoad(){
182
+
183
+ player1 = loadImage("player2.png");
184
+
185
+ enemy[0] =loadImage("敵.png");
186
+
187
+ bombP =loadImage("2弾.png");
188
+
189
+ }
190
+
191
+ void playerMove(){
192
+
193
+ // if( (keyPressed == true) && (key == CODED) ){
194
+
195
+ if( ( keyKeep == LEFT) && (px>0) ){
196
+
197
+ px -= 3;
198
+
199
+ }
200
+
201
+ if( ( keyKeep == RIGHT) &&(px <600-pw) ){
202
+
203
+ px += 3;
204
+
205
+ }
206
+
207
+ // }
208
+
209
+ if( bombWait>0){
210
+
211
+ bombWait--;
212
+
213
+ }
214
+
215
+ if( (keyPressed == true) && (key == ' ' ) && (bombWait == 0) ){
216
+
217
+ bombWait =10; //10秒まち
218
+
219
+ bombPAdd();
220
+
221
+
222
+
223
+ }
224
+
225
+ }
226
+
227
+ void keyPressed(){
228
+
229
+ if (key == CODED){
230
+
231
+ if( (keyCode == LEFT) || (keyCode == RIGHT) ){
232
+
233
+ keyKeep = keyCode;
234
+
235
+ }
236
+
237
+ }
238
+
239
+ }
240
+
241
+ void keyReleased(){
242
+
243
+ if (key == CODED){
244
+
245
+ if( (keyCode == LEFT) || (keyCode == RIGHT) ){
246
+
247
+ keyKeep = 0;
248
+
249
+ }
250
+
251
+ }
252
+
253
+ }
254
+
255
+
256
+
257
+
258
+
259
+ ,,,processing 変更後(引数渡し)
260
+
261
+ int keyy; //流れ管理
262
+
263
+ PImage player1,bg, bombP;// bP: プレイヤーの弾
264
+
265
+ PImage[] enemy = new PImage[2];
266
+
23
267
  int px1=240,py1=50,ph1=50,pw1=50; //プレイヤー1の座標と高さ幅
24
268
 
25
269
  int[] bPx1 = new int[6]; //Player弾
@@ -152,11 +396,11 @@
152
396
 
153
397
  void imgLoad(){
154
398
 
155
- player1 = loadImage("player2.png");
399
+ player1 = loadImage("player1.png");
156
400
 
157
401
  enemy[0] =loadImage("敵.png");
158
402
 
159
- bombP =loadImage("弾.png");
403
+ bombP =loadImage("弾.png");
160
404
 
161
405
  }
162
406