質問編集履歴
5
画像の掲載
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
### 使用している画像
|
2
|
+

|
3
|
+

|
4
|
+

|
5
|
+

|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
|
1
14
|
### 実現したいこと
|
2
15
|
レーザーとボス、自機と弾幕の当たり判定がうまくいきません
|
3
16
|
|
4
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
### 実現したいこと
|
2
|
-
|
2
|
+
レーザーとボス、自機と弾幕の当たり判定がうまくいきません
|
3
3
|
|
4
4
|
|
5
5
|
### 発生している問題・エラーメッセージ
|
3
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
### 実現したいこと
|
2
|
-
自機やボス
|
2
|
+
自機やボスの当たり判定がうまくいきません
|
3
3
|
|
4
4
|
|
5
5
|
### 発生している問題・エラーメッセージ
|
2
コードの変更
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>();
|
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;
|
148
|
+
return danmaku;
|
150
|
-
|
149
|
+
|
151
150
|
}
|
152
151
|
|
153
152
|
// Bullet(弾幕) class
|
1
コードの変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,12 +3,10 @@
|
|
3
3
|
|
4
4
|
|
5
5
|
### 発生している問題・エラーメッセージ
|
6
|
-
|
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,
|
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
|
-
|
48
|
+
|
47
49
|
|
48
|
-
|
50
|
+
void update() {
|
49
|
-
|
51
|
+
boss.doShinking();
|
50
|
-
|
52
|
+
|
51
|
-
|
53
|
+
//画面切り替え
|
52
|
-
|
54
|
+
if (ship.hp == 0) {
|
53
|
-
|
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
|
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
|
-
|
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
|
-
|
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
|
87
|
+
if (abs(ship.sx -boss.tx) < (boss.bw/2)) {
|
91
|
-
|
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 =
|
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 =
|
109
|
+
dx = 10;
|
113
|
-
dy = -
|
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
|
-
|
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
|
-
|
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
|
-
|
156
|
+
private double tx, ty;
|
160
|
-
|
157
|
+
private final double tr;
|
161
|
-
|
158
|
+
private double dx, dy;
|
162
|
-
|
159
|
+
private boolean is_alive = true;
|
163
|
-
|
160
|
+
Bullet(double x, double y, double r, double temp_dx, double temp_dy ) {
|
164
|
-
|
161
|
+
tx = x;
|
165
|
-
|
162
|
+
ty = y;
|
166
|
-
|
163
|
+
tr = r;
|
167
|
-
|
164
|
+
dx = temp_dx;
|
168
|
-
|
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
|
-
|
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
|
-
|
184
|
+
stroke(255, 0, 0);
|
188
185
|
|
189
|
-
|
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
|
-
|
196
|
+
background(0); // clear
|
194
197
|
|
195
|
-
|
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
|
-
|
210
|
+
for (int i = danmaku.size() -1; i >= 0; i--) {
|
199
|
-
|
211
|
+
Bullet b = (Bullet)danmaku.get(i);
|
200
|
-
|
212
|
+
if (!b.isAlive()) {
|
201
|
-
|
213
|
+
danmaku.remove(i);
|
202
|
-
|
214
|
+
continue;
|
215
|
+
}
|
216
|
+
b.update();
|
203
217
|
}
|
204
|
-
b.update();
|
205
|
-
}
|
206
218
|
|
207
|
-
|
219
|
+
if (scene == GameScene.START) {
|
208
|
-
|
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
|
-
|
227
|
+
if (scene == GameScene.PLAY) {
|
216
|
-
|
228
|
+
gamestage.update();
|
229
|
+
//image(pGameback,0,0);
|
217
|
-
|
230
|
+
}
|
218
|
-
|
231
|
+
if (scene == GameScene.OVER) {
|
219
|
-
|
232
|
+
image(pGameover, 0, 0);
|
233
|
+
|
220
|
-
|
234
|
+
}
|
221
|
-
|
235
|
+
if (scene == GameScene.CLEAR) {
|
222
|
-
|
236
|
+
image(pGameclear, 0, 0);
|
223
|
-
|
237
|
+
}
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
|
224
|
-
}
|
242
|
+
}
|