-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEclipseHarbinger.java
More file actions
284 lines (246 loc) · 10.1 KB
/
Copy pathEclipseHarbinger.java
File metadata and controls
284 lines (246 loc) · 10.1 KB
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
/*
* Authors: Jerry Li & Victor Jiang
* Date: June 13, 2025
* Description: This class represents the Eclipse Harbinger boss. It has a multi-phase attack cycle with orbiting crystals
* and a deadly charge-up beam.
*/
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.util.concurrent.CopyOnWriteArrayList;
public class EclipseHarbinger extends Boss {
public static final float CHARGE_DURATION = 3.0f;
public static final float COOLDOWN = 4.0f;
public static final float BEAM_LENGTH = 1600f;
private static final int CRYSTAL_COUNT = 5;
private static final float MAX_TURN_RATE = (float)Math.toRadians(2f);
private float chargeTimer;
private float cooldownTimer;
private boolean isCharging;
private boolean isFiring;
private float beamAngle;
private float patrolAngle = 0f;
private EclipseBeam beam;
private final CopyOnWriteArrayList<OrbitingCrystal> crystals = new CopyOnWriteArrayList<>();
private BufferedImage crystalSprite;
public EclipseHarbinger(int x, int y, int size, int hp, float speed,
BufferedImage[] sprites, GamePanel gp) {
super(x, y, size, size, hp, speed, sprites, gp);
crystalSprite = sprites.length > 3 ? sprites[3] : null;
int i = 0;
for (i = 0; i < CRYSTAL_COUNT; i++) {
crystals.add(new OrbitingCrystal(i * (float)Math.PI * 2 / CRYSTAL_COUNT));
}
}
@Override
protected void moveBoss(float dt, Player player) {
float dxA = 0f;
float dyA = 0f;
float targetA = 0f;
float dt60 = 0f;
float targetX = 0f;
float targetY = 0f;
float dx = 0f;
float dy = 0f;
float dist = 0f;
float desiredVx = 0f;
float desiredVy = 0f;
int loopIndex = 0;
OrbitingCrystal c = null;
if (beam != null) {
beam.update(dt);
if (beam.isDead()) {
beam = null;
isFiring = false;
cooldownTimer = 0f;
}
}
if (isCharging && player != null) {
dxA = (float)(player.getCenterX() - getCenterX());
dyA = (float)(player.getCenterY() - getCenterY());
targetA = (float)Math.atan2(dyA, dxA);
beamAngle = rotateTowards(beamAngle, targetA, MAX_TURN_RATE * dt);
}
dt60 = dt * 60f;
if (!isCharging && !isFiring) {
cooldownTimer += dt;
patrolAngle += dt * 0.4f;
targetX = GamePanel.GAME_WIDTH / 2f + (float) Math.cos(patrolAngle) * 260f;
targetY = GamePanel.GAME_HEIGHT / 2f + (float) Math.sin(patrolAngle) * 260f;
// movement interpolation...
dx = targetX - (float) getCenterX();
dy = targetY - (float) getCenterY();
dist = Math.max(0.001f, (float) Math.sqrt(dx * dx + dy * dy));
desiredVx = dx / dist * ENEMY_MAX_SPEED;
desiredVy = dy / dist * ENEMY_MAX_SPEED;
x_velocity += (desiredVx - x_velocity) * 0.08f * dt60;
y_velocity += (desiredVy - y_velocity) * 0.08f * dt60;
x += x_velocity * dt60;
y += y_velocity * dt60;
wrap();
if (cooldownTimer >= COOLDOWN) {
startCharging(player);
}
} else if (isCharging) {
chargeTimer += dt;
// damp motion
x_velocity *= 0.9f;
y_velocity *= 0.9f;
x += x_velocity * dt60;
y += y_velocity * dt60;
if (chargeTimer >= CHARGE_DURATION) {
startFiring();
}
} else if (isFiring) {
x_velocity *= 0.9f;
y_velocity *= 0.9f;
x += x_velocity * dt60;
y += y_velocity * dt60;
}
for (loopIndex = 0; loopIndex < crystals.size(); loopIndex++) {
c = crystals.get(loopIndex);
c.update(dt, isCharging ? 1.5f : 1f, chargeTimer / CHARGE_DURATION);
}
}
private void startCharging(Player player) {
isCharging = true;
chargeTimer = 0f;
float dx = 0f;
float dy = 0f;
dx = (float)(player.getCenterX() - getCenterX());
dy = (float)(player.getCenterY() - getCenterY());
beamAngle = (float)Math.atan2(dy, dx);
}
private void startFiring() {
isCharging = false;
isFiring = true;
beam = new EclipseBeam((float)getCenterX(), (float)getCenterY(),
beamAngle, BEAM_LENGTH, gamePanel);
}
@Override
public void draw(Graphics g) {
Graphics2D g2 = null;
int sx = 0;
int sy = 0;
int ex = 0;
int ey = 0;
float strokeWidth = 0f;
float alpha = 0f;
BufferedImage sprite = null;
int i = 0;
int loopIndex = 0;
OrbitingCrystal c = null;
if (isDead()) return;
g2 = (Graphics2D) g.create();
// 1) Draw the beam indicator
if (isCharging) {
sx = (int)getCenterX();
sy = (int)getCenterY();
ex = (int)(sx + Math.cos(beamAngle) * BEAM_LENGTH);
ey = (int)(sy + Math.sin(beamAngle) * BEAM_LENGTH);
strokeWidth = isCharging ? 40f : 80f;
alpha = isCharging
? 0.2f + 0.8f * (chargeTimer / CHARGE_DURATION)
: 0.8f;
g2.setStroke(new BasicStroke(strokeWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
g2.setComposite(AlphaComposite.SrcOver.derive(alpha));
g2.setColor(new Color(200, 50, 255));
g2.drawLine(sx, sy, ex, ey);
// subtle outer glow
for (i = 1; i <= 4; i++) {
g2.setStroke(new BasicStroke(strokeWidth + i * 15f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
g2.setComposite(AlphaComposite.SrcOver.derive(0.1f));
g2.drawLine(sx, sy, ex, ey);
}
g2.setComposite(AlphaComposite.SrcOver);
}
// 2) Draw the boss sprite
sprite = sprites[0];
if (isFiring && sprites.length > 2) sprite = sprites[2];
else if (isCharging && sprites.length > 1) sprite = sprites[1];
g2.drawImage(sprite, x, y, width, height, null);
// 3) Draw glowing, pulsing crystals with charge arcs
for (loopIndex = 0; loopIndex < crystals.size(); loopIndex++) {
c = crystals.get(loopIndex);
c.draw(g2);
}
// 4) Draw active beam
if (beam != null) beam.draw(g2);
drawBossHealthBar(g2);
drawDamageNumbers(g2);
g2.dispose();
}
private class OrbitingCrystal {
private float angle, x, y;
private float baseSpeed = 2f;
private float radius = Math.max(width, height) * 1.2f;
private int baseSize = 64;
private float speedFactor;
// chargePercent [0..1] used to draw the charging arc
private float chargePercent;
OrbitingCrystal(float startAngle) {
this.angle = startAngle;
this.speedFactor = 0.8f + (float)Math.random() * 0.4f;
}
public void update(float dt, float speedMult, float chargePct) {
this.chargePercent = chargePct;
angle += baseSpeed * speedMult * speedFactor * dt;
float r = radius + (float)Math.sin(angle * 2f) * 15f;
x = (float)(getCenterX() + Math.cos(angle) * r);
y = (float)(getCenterY() + Math.sin(angle) * r + Math.sin(angle*3f) * 15f);
}
public void draw(Graphics2D g2) {
int size = baseSize + (int)(10 * chargePercent); // crystals grow as they charge
int cx = (int)x - size/2, cy = (int)y - size/2;
// outer glow
int i = 0;
float a = 0f;
for (i = 4; i >= 1; i--) {
a = 0.07f * i;
g2.setComposite(AlphaComposite.SrcOver.derive(a));
g2.fillOval(cx - i*4, cy - i*4, size + i*8, size + i*8);
}
// core crystal
g2.setComposite(AlphaComposite.SrcOver);
if (crystalSprite != null) {
AffineTransform at = AffineTransform.getTranslateInstance(cx, cy);
at.scale(size/(float)crystalSprite.getWidth(), size/(float)crystalSprite.getHeight());
g2.drawImage(crystalSprite, at, null);
} else {
g2.setColor(new Color(150, 100, 255));
// Draw a rhombus instead of a circle
int[] xPoints = {cx + size/2, cx + size, cx + size/2, cx};
int[] yPoints = {cy, cy + size/2, cy + size, cy + size/2};
g2.fillPolygon(xPoints, yPoints, 4);
}
// halo ring
g2.setComposite(AlphaComposite.SrcOver.derive(0.3f));
g2.setStroke(new BasicStroke(2f));
g2.setColor(new Color(200,200,255));
g2.drawOval(cx - size, cy - size, size*2, size*2);
// charging arc and energy thread
if (isCharging) {
g2.setComposite(AlphaComposite.SrcOver.derive(0.8f));
g2.setStroke(new BasicStroke(4f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
g2.setColor(new Color(255, 200, 50, 200));
int arcSize = size + 8;
g2.drawArc(cx - 4, cy - 4, arcSize, arcSize,
90, -(int)(360 * chargePercent));
g2.drawLine((int)getCenterX(), (int)getCenterY(), cx + size/2, cy + size/2);
}
}
}
// Normalizes an angle to the range [-PI, PI]
private static float normalizeAngle(float a) {
while (a < -Math.PI) a += Math.PI * 2f;
while (a > Math.PI) a -= Math.PI * 2f;
return a;
}
// Rotates current angle towards target angle by maxDelta radians
private static float rotateTowards(float current, float target, float maxDelta) {
float diff = normalizeAngle(target - current);
if (diff > maxDelta) diff = maxDelta;
if (diff < -maxDelta) diff = -maxDelta;
return normalizeAngle(current + diff);
}
}