-
Notifications
You must be signed in to change notification settings - Fork 1
/
StagBeetle.java
293 lines (264 loc) · 10.7 KB
/
StagBeetle.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class StagBeetle extends Boss {
//状態判断用変数
int mode = 0;
//方向反転判断
int direction = 1;
//フレームカウント
int flameCount = 0;
int beamFlameCount = 0;
//横移動の基準距離(振幅)
int distanceBaseX = MyWorld.WIDTH / 2 - 100;
//角度用変数
double angle = 0;
int dangle = 1;
boolean beaming = false;
//ビームパターン判別
int beamPattern = 1;
//ビームとして渡す画像
GreenfootImage beamImg = new GreenfootImage(800, 20);
GreenfootImage SubbeamImg = new GreenfootImage(400, 20);
//ビーム用オブジェクト
EnemyBulletForStag beams = new EnemyBulletForStag();
EnemyBulletForStag dualBeam[] = {new EnemyBulletForStag(), new EnemyBulletForStag()};
//ビーム音
GreenfootSound beamSound = new GreenfootSound("./sounds/beam.mp3");
GreenfootSound beamWaitSound = new GreenfootSound("./sounds/beamwait.mp3");
//風の音
GreenfootSound wind = new GreenfootSound("./sounds/wind.mp3");
//竜巻
GreenfootImage cycronImg = new GreenfootImage("./images/cycron.png");
EnemyBulletForCycron cycron[] = new EnemyBulletForCycron[20];
//new GreenfootImage[20];
public StagBeetle() {
HITPOINT = 200;
hitpoint = HITPOINT;
giveScore = 1;
range = 15;
int[] items = {0, 0, 0};
this.items = items;
direction = 1;
dangle = 1;
img = new GreenfootImage("./images/stag.png");
setImage(img);
beaming = false;
beamImg.setColor(new Color(92, 244, 66));
beamImg.fill();
beamImg.setTransparency(45);
SubbeamImg.setColor(new Color(92, 244, 66));
SubbeamImg.fill();
SubbeamImg.setTransparency(45);
for (int i = 0; i < cycron.length; i++) {
cycron[i] = new EnemyBulletForCycron(cycronImg);
}
}
public void beam() {
if (beamFlameCount == 0) {
beamImg.setTransparency(45);
beams.img = beamImg;
getWorld().addObject(beams, x, y + beams.img.getWidth() / 2 + img.getHeight() / 2);
beamWaitSound.play();
beaming = true;
//getWorld().setPaintOrder(this.getClass(),beams.getClass());
} else if (beamFlameCount == 100) {
beamImg.setTransparency(255);
beamWaitSound.stop();
beamSound.playLoop();
beams.isActive = true;
beams.img = beamImg;
} else if (beamFlameCount == 270) {
beams.isActive = false;
beamSound.stop();
beamImg.setTransparency(45);
beams.img = beamImg;
}
beamFlameCount++;
if (beamFlameCount > 300) {
getWorld().removeObject(beams);
beaming = false;
//beamPattern = 0;
flameCount = 0;
beamFlameCount = 0;
}
}
public void dualBeam() {
if (beamFlameCount == 0) {
beamImg.setTransparency(45);
for (int i = 0; i < dualBeam.length; i++) {
dualBeam[i].img = beamImg;
//distanceBaseX = MyWorld.WIDTH / 2 - 200;
}
if (x <= 100) {
dualBeam[0].img = SubbeamImg;
}
beaming = true;
getWorld().addObject(dualBeam[0], x + (int) (dualBeam[0].img.getWidth() / 2 * Math.cos(Math.toRadians(60))), y + 50 + (int) (dualBeam[0].img.getWidth() * Math.sin(Math.toRadians(60)) / 2));
dualBeam[0].setRotation(120);
getWorld().addObject(dualBeam[1], x + (int) (dualBeam[1].img.getWidth() / 2 * Math.cos(Math.toRadians(120))), y + 50 + (int) (dualBeam[1].img.getWidth() * Math.sin(Math.toRadians(120)) / 2));
dualBeam[1].setRotation(60);
//getWorld().setPaintOrder(this.getClass(),beams.getClass());
beamWaitSound.play();
} else if (beamFlameCount == 100) {
SubbeamImg.setTransparency(255);
beamImg.setTransparency(255);
beamWaitSound.stop();
beamSound.playLoop();
for (int i = 0; i < dualBeam.length; i++) {
dualBeam[i].isActive = true;
dualBeam[i].img = beamImg;
}
if (x <= 100) {
dualBeam[0].img = SubbeamImg;
}
} else if (beamFlameCount == 270) {
SubbeamImg.setTransparency(45);
beamImg.setTransparency(45);
beamSound.stop();
for (int i = 0; i < dualBeam.length; i++) {
dualBeam[i].isActive = false;
dualBeam[i].img = beamImg;
}
if (x <= 100) {
dualBeam[0].img = SubbeamImg;
}
}
beamFlameCount++;
if (beamFlameCount > 300) {
beaming = false;
getWorld().removeObject(dualBeam[0]);
getWorld().removeObject(dualBeam[1]);
//distanceBaseX = MyWorld.WIDTH / 2 - 100;
beamPattern = 0;
flameCount = 0;
beamFlameCount = 0;
}
}
@Override
public void shot() {
for (int i = 0; i < cycron.length; i++) {
try {
int check = cycron[i].getX();
} catch (Exception e) {
cycron[i] = new EnemyBulletForCycron(cycronImg);
wind.play();
getWorld().addObject(cycron[i], x, y);
break;
}
}
}
public void act() {
if (Stage.inPause) {
//ポーズ中なので空
} else {
if (startBattle) {
//位置情報の更新
statusUpdate();
switch (mode) {
case 0:
setLocation(x, y + 2);
if (getY() > 100) {
mode = 1;
}
break;
case 2:
case 3:
if (flameCount % 65 == 0) {
shot();
}
case 1:
flameCount++;
move(MyWorld.WIDTH / 2 + (int) (distanceBaseX * Math.sin(angle)) - x);
//角度を元に位置を更新
//setLocation(MyWorld.WIDTH / 2 + (int) (distanceBaseX * Math.sin(angle)), y);
try {
beams.setLocation(x, y + beams.img.getWidth() / 2 + img.getHeight() / 2);
} catch (Exception e) {
}
try {
if (x <= 200) {
//getWorld().removeObject(dualBeam[0]);
dualBeam[0].img = SubbeamImg;
dualBeam[0].setLocation(x + (int) (dualBeam[0].img.getWidth() / 2 * Math.cos(Math.toRadians(60))), y + 50 + (int) (dualBeam[0].img.getWidth() * Math.sin(Math.toRadians(60)) / 2));
} else {
dualBeam[0].img = beamImg;
dualBeam[0].setLocation(x + (int) (dualBeam[0].img.getWidth() / 2 * Math.cos(Math.toRadians(60))), y + 50 + (int) (dualBeam[0].img.getWidth() * Math.sin(Math.toRadians(60)) / 2));
}
dualBeam[0].setRotation(0);
dualBeam[1].setRotation(0);
dualBeam[0].move(x - (int) (dualBeam[0].img.getWidth() / 2 * Math.cos(Math.toRadians(60))) - dualBeam[0].getX());
dualBeam[1].move(x - (int) (dualBeam[1].img.getWidth() / 2 * Math.cos(Math.toRadians(120))) - dualBeam[1].getX());
dualBeam[0].setRotation(120);
dualBeam[1].setRotation(60);
} catch (Exception e) {
}
//角度を10°足す
angle += Math.toRadians(dangle);
//angleが360°になっていたら
if (angle >= 2 * Math.PI) {
//0に直す
angle = 0;
}
if (flameCount == 50) {
beamPattern = Greenfoot.getRandomNumber(2);
} else if (flameCount > 50) {
switch (beamPattern) {
case 0:
beam();
break;
case 1:
dualBeam();
break;
case 2:
beam();
dualBeam();
break;
}
}
break;
}
//体力を見てモードを切り替える
switch(mode){
case 1:
if(hitpoint <= 2 * HITPOINT/3){
mode = 2;
}
break;
case 2:
if(hitpoint <= HITPOINT/3){
mode = 3;
dangle = 2;
}
case 3:
break;
}
hitStatusCheck(img);
//消失判定(ボスなので、画面縁で消えないようにする)
if (hitpoint <= 0) {
beamSound.stop();
beamWaitSound.stop();
//ドロップアイテムの出現
putItem(items, giveScore);
try {
getWorld().removeObject(beams);
} catch (Exception e) {
}
try {
getWorld().removeObject(dualBeam[0]);
getWorld().removeObject(dualBeam[1]);
} catch (Exception e) {
}
//消滅
getWorld().removeObject(this);
//ステージのクリアフラグを立てる
MyWorld.clearStage = true;
}
} else {
if (caution.finishCaution) {
getWorld().addObject(new DisplayHitpoint("StagBeatle"),700, Stage.HEIGHT/2);
img.setTransparency(255);
startBattle = true;
}
}
}
}
}