teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

5

画像の掲載

2018/05/06 12:57

投稿

plarex
plarex

スコア12

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

4

2018/05/06 12:57

投稿

plarex
plarex

スコア12

title CHANGED
File without changes
body CHANGED
@@ -1,5 +1,5 @@
1
1
  ### 実現したいこと
2
- 自機やボスの当たり判定がうまくいきません
2
+ レーザーとボス、自機と弾幕の当たり判定がうまくいきません
3
3
 
4
4
 
5
5
  ### 発生している問題・エラーメッセージ

3

2018/05/05 15:43

投稿

plarex
plarex

スコア12

title CHANGED
File without changes
body CHANGED
@@ -1,5 +1,5 @@
1
1
  ### 実現したいこと
2
- 自機やボスが倒されるとゲーム画面が切り替わる仕様にしたいですがうまくいきません
2
+ 自機やボスの当たり判定がうまくいきません
3
3
 
4
4
 
5
5
  ### 発生している問題・エラーメッセージ

2

コードの変更

2018/05/05 11:36

投稿

plarex
plarex

スコア12

title CHANGED
File without changes
body CHANGED
@@ -18,8 +18,7 @@
18
18
  Boss boss;
19
19
  GameStage gamestage;
20
20
 
21
- private ArrayList<Bullet> danmaku = new ArrayList<Bullet>(); //オブジェクトの宣言,returnで初期値入れる?
21
+ private ArrayList<Bullet> danmaku = new ArrayList<Bullet>();
22
-
23
22
  enum GameScene {
24
23
  START, PLAY, CLEAR, OVER;
25
24
  }
@@ -127,7 +126,7 @@
127
126
  move();
128
127
  }
129
128
  if (routine % 30 == 0) {
130
- danmaku.addAll(this.shot()); //?????
129
+ danmaku.addAll(this.shot());
131
130
  println("#shot!!" +routine + ":" + tx + "," + ty);
132
131
  }
133
132
  }
@@ -144,10 +143,10 @@
144
143
  ArrayList<Bullet> danmaku = new ArrayList();
145
144
  for (int i = 0; i < 360; i+= 10) { //インスタンス(弾幕)の作成
146
145
  double rad = radians(i);
147
- danmaku.add(new Bullet(this.tx, this.ty, 10, Math.cos(rad), Math.sin(rad))); //↑で作ったそれぞれのインスタンスに代入
146
+ danmaku.add(new Bullet(this.tx, this.ty, 10, Math.cos(rad), Math.sin(rad)));
148
147
  }
149
- return danmaku; //3行目のやつに↑を入れる
148
+ return danmaku;
150
- }
149
+
151
150
  }
152
151
 
153
152
  // Bullet(弾幕) class

1

コードの変更

2018/05/05 11:36

投稿

plarex
plarex

スコア12

title CHANGED
File without changes
body CHANGED
@@ -3,12 +3,10 @@
3
3
 
4
4
 
5
5
  ### 発生している問題・エラーメッセージ
6
- shipクラスのupdateの中で
6
+ 動くことは動くが当たり判定が出ない
7
- cannot make a static referrence to the non-static field ship.hp.
8
- と出る。
9
7
 
10
- drawの中のship(mouseX,mouseY)でエラーが出る。
11
8
 
9
+
12
10
  ### 該当のソースコード
13
11
  PImage pStart;
14
12
  PImage pGameback;
@@ -16,11 +14,12 @@
16
14
  PImage pGameclear;
17
15
 
18
16
  Bullet bullet;
17
+ Ship ship;
18
+ Boss boss;
19
+ GameStage gamestage;
19
20
 
21
+ private ArrayList<Bullet> danmaku = new ArrayList<Bullet>(); //オブジェクトの宣言,returnで初期値入れる?
20
22
 
21
-
22
- private ArrayList<Bullet> danmaku = new ArrayList<Bullet>();
23
-
24
23
  enum GameScene {
25
24
  START, PLAY, CLEAR, OVER;
26
25
  }
@@ -38,37 +37,40 @@
38
37
  pGameover = loadImage("gameover.png");
39
38
  pGameclear = loadImage("gameclear.png");
40
39
 
41
- bullet = new Bullet(width/2, height/2, 10, 0, 0 ); //クラスからインスタンスを生成
40
+ bullet = new Bullet(width/2, height/2, 20, 0, 0 );//クラスからインスタンスを生成
41
+ ship = new Ship(mouseX,mouseY);
42
+ gamestage = new GameStage() ;
43
+ boss = new Boss(160, 150);
42
44
  }
43
45
 
44
- //GameStage class
46
+ //GameStage class
45
- class GameStage {
47
+ class GameStage {
46
- private Boss boss = new Boss(160, 150);
48
+
47
49
 
48
- void update() {
50
+ void update() {
49
- boss.doShinking();
51
+ boss.doShinking();
50
-
52
+
51
- //画面切り替え
53
+ //画面切り替え
52
- if (ship.hp == 0) {
54
+ if (ship.hp == 0) {
53
- scene = GameScene.OVER;
55
+ scene = GameScene.OVER;
56
+ }
57
+ if (boss.hp == 0) {
58
+ scene = GameScene.CLEAR;
59
+ }
54
60
  }
55
- if (boss.hp == 0) {
56
- scene = GameScene.CLEAR;
57
- }
58
61
  }
59
- }
60
62
 
61
63
 
62
64
 
63
65
  // ship(自機) class
64
- class ship {
66
+ class Ship {
65
67
  private int sx, sy;
66
68
  private int hp = 1;
67
69
  boolean is_Alive() {
68
70
  //return is_alive;
69
71
  return hp != 0;
70
72
  }
71
- ship(int x, int y) {
73
+ Ship(int x, int y) {
72
74
  sx = x;
73
75
  sy = y;
74
76
  }
@@ -77,18 +79,13 @@
77
79
  sy = y;
78
80
  stroke(255, 255, 255);
79
81
  noFill();
80
- triangle(x, y -7, x - 10, y + 7, x + 10, y + 7);
82
+
81
-
82
- //レーザーの描写
83
- if (mousePressed) {
84
- line(x, y - 7, x, 0);
85
- }
86
83
  }
87
84
 
88
85
  //hit check
89
86
  void damage() {
90
- if (abs(sx -boss.tx) < (boss.bw /2)) {
87
+ if (abs(ship.sx -boss.tx) < (boss.bw/2)) {
91
- ship.hp--;
88
+ boss.hp--;
92
89
  }
93
90
  }
94
91
  }
@@ -100,7 +97,7 @@
100
97
  private int bw = 20;
101
98
  private int bh = 10;
102
99
  private long routine = 0;
103
- private int hp = 1000;
100
+ private int hp = 10;
104
101
  boolean isAlive() {
105
102
  //return is_alive;
106
103
  return hp != 0;
@@ -109,8 +106,8 @@
109
106
  Boss(int x, int y) {
110
107
  tx = x;
111
108
  ty = y;
112
- dx = 1;
109
+ dx = 10;
113
- dy = -5;
110
+ dy = -8;
114
111
  }
115
112
  void move() {
116
113
  tx += dx;
@@ -118,11 +115,11 @@
118
115
  if (tx < 0 || tx > width) {
119
116
  dx*= -1;
120
117
  }
121
- if (ty < 0 || ty > height) {
118
+ if (ty < 0 || ty > height/3) {
122
119
  dy*= -1;
123
120
  }
124
121
  stroke(255, 204, 0);
125
- rect(tx - bw/2, ty + bh/2, bw, bh);
122
+
126
123
  }
127
124
  void doShinking() {
128
125
  routine++;
@@ -130,14 +127,14 @@
130
127
  move();
131
128
  }
132
129
  if (routine % 30 == 0) {
133
- danmaku.addAll(this.shot());
130
+ danmaku.addAll(this.shot()); //?????
134
131
  println("#shot!!" +routine + ":" + tx + "," + ty);
135
132
  }
136
133
  }
137
134
  //hit check 
138
135
  void damage() {
139
136
  if (dist(tx, ty, ship.sx, ship.sy) < bullet.tr/2) {
140
- boss.hp--;
137
+ ship.hp--;
141
138
  }
142
139
  }
143
140
 
@@ -147,78 +144,99 @@
147
144
  ArrayList<Bullet> danmaku = new ArrayList();
148
145
  for (int i = 0; i < 360; i+= 10) { //インスタンス(弾幕)の作成
149
146
  double rad = radians(i);
150
- danmaku.add(new Bullet(this.tx, this.ty, 10, Math.cos(rad), Math.sin(rad)));
147
+ danmaku.add(new Bullet(this.tx, this.ty, 10, Math.cos(rad), Math.sin(rad))); //↑で作ったそれぞれのインスタンスに代入
151
148
  }
152
- return danmaku;
149
+ return danmaku; //3行目のやつに↑を入れる
153
150
  }
154
151
  }
155
152
 
156
- // Bullet(弾幕) class
153
+ // Bullet(弾幕) class
157
154
 
158
- class Bullet {
155
+ class Bullet {
159
- private double tx, ty;
156
+ private double tx, ty;
160
- private final double tr;
157
+ private final double tr;
161
- private double dx, dy;
158
+ private double dx, dy;
162
- private boolean is_alive = true;
159
+ private boolean is_alive = true;
163
- Bullet(double x, double y, double r, double temp_dx, double temp_dy ) {
160
+ Bullet(double x, double y, double r, double temp_dx, double temp_dy ) {
164
- tx = x;
161
+ tx = x;
165
- ty = y;
162
+ ty = y;
166
- tr = r;
163
+ tr = r;
167
- dx = temp_dx;
164
+ dx = temp_dx;
168
- dy = temp_dy;
165
+ dy = temp_dy;
169
- }
170
- boolean isAlive() {
171
- return is_alive;
172
- }
173
- void update() {
174
- tx += dx;
175
- ty += dy;
176
- //area check
177
- if (Math.min(tx, ty) < 0) {
178
- is_alive = false;
179
- //println("#" + tx + "," + ty);
180
- return ;
181
166
  }
182
- if (tx > width || ty > height) {
183
- is_alive = false;
167
+ boolean isAlive() {
184
- return ;
168
+ return is_alive;
185
169
  }
170
+ void update() {
171
+ tx += dx;
172
+ ty += dy;
173
+ //area check
174
+ if (Math.min(tx, ty) < 0) {
175
+ is_alive = false;
176
+ //println("#" + tx + "," + ty);
177
+ return ;
178
+ }
179
+ if (tx > width || ty > height) {
180
+ is_alive = false;
181
+ return ;
182
+ }
186
183
 
187
- stroke(255, 0, 0);
184
+ stroke(255, 0, 0);
188
185
 
189
- ellipse((float)tx, (float)ty, (float)tr, (float)tr);
186
+ ellipse((float)tx, (float)ty, (float)tr, (float)tr);
187
+ }
190
188
  }
191
- }
192
- void draw() {
189
+ void draw() {
190
+ rect(boss.tx - boss.bw/2, boss.ty + boss.bh/2, boss.bw, boss.bh);
191
+ fill(255,0,0);
192
+ text("boss.hp",100,100);
193
+ fill(255,255,255);
194
+
195
+
193
- background(0); // clear
196
+ background(0); // clear
194
197
 
195
- ship(mouseX, mouseY);
198
+ triangle(mouseX, mouseY -7, mouseX - 10, mouseY + 7, mouseX + 10, mouseY + 7);
196
- boss.doShinking();
197
199
 
200
+ boss.damage();
201
+ ship.damage();
202
+
203
+
204
+ //レーザーの描写
205
+ if (mousePressed) {
206
+ line(mouseX, mouseY - 7, mouseX, 0);
207
+ }
208
+
209
+
198
- for (int i = danmaku.size() -1; i >= 0; i--) {
210
+ for (int i = danmaku.size() -1; i >= 0; i--) {
199
- Bullet b = (Bullet)danmaku.get(i);
211
+ Bullet b = (Bullet)danmaku.get(i);
200
- if (!b.isAlive()) {
212
+ if (!b.isAlive()) {
201
- danmaku.remove(i);
213
+ danmaku.remove(i);
202
- continue;
214
+ continue;
215
+ }
216
+ b.update();
203
217
  }
204
- b.update();
205
- }
206
218
 
207
- if (scene == GameScene.START) {
219
+ if (scene == GameScene.START) {
208
- image(pStart, 0, 0);
220
+ image(pStart, 0, 0);
209
- }
210
- if (mousePressed) {
211
- if (mouseButton == LEFT) {
212
- scene = GameScene.PLAY;
213
221
  }
222
+ if (mousePressed) {
223
+ if (mouseButton == LEFT) {
224
+ scene = GameScene.PLAY;
214
- }
225
+ }
226
+ }
215
- if (scene == GameScene.PLAY) {
227
+ if (scene == GameScene.PLAY) {
216
- GameStage.update();
228
+ gamestage.update();
229
+ //image(pGameback,0,0);
217
- }
230
+ }
218
- if (scene == GameScene.OVER) {
231
+ if (scene == GameScene.OVER) {
219
- image(pGameover, 0, 0);
232
+ image(pGameover, 0, 0);
233
+
220
- }
234
+ }
221
- if (scene == GameScene.CLEAR) {
235
+ if (scene == GameScene.CLEAR) {
222
- image(pGameclear, 0, 0);
236
+ image(pGameclear, 0, 0);
223
- }
237
+ }
238
+
239
+
240
+
241
+
224
- }
242
+ }