-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEclipseBeam.java
More file actions
985 lines (834 loc) · 36.3 KB
/
Copy pathEclipseBeam.java
File metadata and controls
985 lines (834 loc) · 36.3 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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
/*
* Authors: Jerry Li & Victor Jiang
* Date: June 13, 2025
* Description: This is used to support the massive void beam fired by the Eclipse Harbinger
*/
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.BufferedImage;
import java.util.Arrays;
import java.util.Random;
import java.util.concurrent.CopyOnWriteArrayList;
public class EclipseBeam extends Projectile {
private GamePanel panel;
private float angle;
private float desiredAngle;
private float length;
private float chargeTimer = 0f;
private float activeTimer = 0f;
private float fadeTimer = 0f;
private float trackTimer = 0f;
private final CopyOnWriteArrayList<ChargeOrbParticle> chargeParticles = new CopyOnWriteArrayList<>();
private final CopyOnWriteArrayList<RingPulseEffect> ringEffects = new CopyOnWriteArrayList<>();
private final CopyOnWriteArrayList<ArcTrailParticle> arcParticles = new CopyOnWriteArrayList<>();
// Caching for beam effects
private BufferedImage cachedGlow = null;
private float lastCachedWidth = 0f;
// Animation timers for various effects
private float pulsePhase = 0f;
private float colorCyclePhase = 0f;
private static final float CHARGE_DURATION = 0.4f;
private static final float DURATION = 6.5f;
private static final float FADE_DURATION = 0.3f;
private static final float TRACK_INTERVAL = 0.5f;
private static final float MAX_SWEEP = (float) Math.toRadians(360f);
private static final float BASE_WIDTH = 160f;
private static final float PULSE_AMPLITUDE = 65f; // Increased for more dramatic pulse
private static final float FLARE_RADIUS = 100f; // Increased for larger flare effect
private static final float MAX_TURN_RATE = (float) Math.toRadians(360f);
private static final float SWEEP_RATE = (float) Math.toRadians(0.85f);
// New constants for enhanced effects
private static final float CORE_WIDTH_RATIO = 0.4f; // Width of the inner core relative to outer beam
private static final float GLOW_WIDTH_RATIO = 2.2f; // Width of the glow relative to beam width
private static final float PULSE_FREQUENCY = 8f; // How fast the beam pulses
private static final float COLOR_CYCLE_SPEED = 0.8f; // How fast colors shift
private static final float ARC_FREQUENCY = 15f; // How many arcs to generate per second
private float sweepDirection = 1f;
private boolean sweeping = false;
private float[] angleHistory = new float[5];
private int historyIndex = 0;
private float lockAngle;
private Random rand = new Random();
private enum Phase {
CHARGING, ACTIVE, FADEOUT
}
private Phase phase = Phase.CHARGING;
public EclipseBeam(float x, float y, float angle, float length, GamePanel gp) {
super(x, y);
this.angle = angle;
this.desiredAngle = angle;
this.lockAngle = angle;
this.length = length;
this.panel = gp;
Arrays.fill(angleHistory, angle);
}
/**
* Directly set the beam angle (used by the boss to sync visuals).
*/
public void setAngle(float angle) {
this.angle = angle;
this.desiredAngle = angle;
}
private static float normalizeAngle(float a) {
while (a < -Math.PI)
a += Math.PI * 2f;
while (a > Math.PI)
a -= Math.PI * 2f;
return a;
}
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);
}
@Override
public void update(float dt) {
float tx = 0f;
float ty = 0f;
float newAng = 0f;
float diff = 0f;
float chargeProgress = 0f;
float arcAngle = 0f;
float arcPos = 0f;
float arcX = 0f;
float arcY = 0f;
float arcLength = 0f;
float ex = 0f;
float ey = 0f;
float currentWidth = 0f;
int i = 0;
ChargeOrbParticle p = null;
RingPulseEffect r = null;
ArcTrailParticle a = null;
if (phase == Phase.CHARGING && panel != null && panel.player != null) {
trackTimer += dt;
if (trackTimer >= TRACK_INTERVAL) {
trackTimer = 0f;
tx = (float) panel.player.getCenterX();
ty = (float) panel.player.getCenterY();
newAng = (float) Math.atan2(ty - y, tx - x);
diff = normalizeAngle(newAng - lockAngle);
if (Math.abs(diff) > MAX_SWEEP) {
newAng = lockAngle + Math.signum(diff) * MAX_SWEEP;
}
desiredAngle = newAng;
}
angle = rotateTowards(angle, desiredAngle, MAX_TURN_RATE * dt);
} else if (sweeping) {
angle += sweepDirection * SWEEP_RATE;
angle = normalizeAngle(angle);
}
switch (phase) {
case CHARGING:
chargeTimer += dt;
pulsePhase += dt * PULSE_FREQUENCY * 1.5f; // Faster pulse during charging
colorCyclePhase += dt * COLOR_CYCLE_SPEED * 0.5f;
// Spawn more particles during charging phase for dramatic effect
if (rand.nextFloat() < dt * 30f)
spawnChargeParticle();
// Create pulsing ring effects
if (rand.nextFloat() < dt * 3.5f) {
ringEffects.add(new RingPulseEffect(x, y, chargeTimer / CHARGE_DURATION));
}
// As charging progresses, create more intense effects
chargeProgress = chargeTimer / CHARGE_DURATION;
if (rand.nextFloat() < dt * 10f * chargeProgress) {
// Spawn occasional arcs near the source point
arcAngle = angle + (rand.nextFloat() - 0.5f) * 0.5f;
spawnArcParticle(x, y, arcAngle, 20f + rand.nextFloat() * 40f);
}
if (chargeTimer >= CHARGE_DURATION) {
phase = Phase.ACTIVE;
activeTimer = 0f;
sweeping = true;
sweepDirection = Math.random() < 0.5 ? 1f : -1f;
pulsePhase = 0f; // Reset pulse for active phase
// More dramatic activation effects
if (panel != null) {
panel.startScreenShake(0.5f, 10f); // More intense screen shake
panel.startPurpleFlash(0.25f); // Longer flash
// Create a burst of particles at activation
for (i = 0; i < 20; i++) {
spawnChargeParticle();
}
}
// Invalidate cached glow
cachedGlow = null;
}
break;
case ACTIVE:
activeTimer += dt;
pulsePhase += dt * PULSE_FREQUENCY;
colorCyclePhase += dt * COLOR_CYCLE_SPEED;
historyIndex = (historyIndex + 1) % angleHistory.length;
angleHistory[historyIndex] = angle;
ex = x + (float) Math.cos(angle) * length;
ey = y + (float) Math.sin(angle) * length;
// Generate arc particles along the beam
if (rand.nextFloat() < dt * ARC_FREQUENCY) {
arcPos = rand.nextFloat();
arcX = x + (float) Math.cos(angle) * length * arcPos;
arcY = y + (float) Math.sin(angle) * length * arcPos;
arcAngle = angle + (rand.nextFloat() - 0.5f) * 0.8f;
arcLength = 10f + rand.nextFloat() * 30f;
arcParticles.add(new ArcTrailParticle(arcX, arcY, arcAngle, arcLength));
}
// Generate occasional ring effects at beam source
if (rand.nextFloat() < dt * 2f) {
ringEffects.add(new RingPulseEffect(x, y));
}
// Check for collision with player
if (panel != null && panel.player != null) {
if (new Line2D.Float(x, y, ex, ey).intersects(panel.player.getBounds())) {
panel.player.takeDamage(panel.player.getHp());
}
}
if (activeTimer >= DURATION) {
phase = Phase.FADEOUT;
fadeTimer = 0f;
// Invalidate cached glow
cachedGlow = null;
}
break;
case FADEOUT:
fadeTimer += dt;
pulsePhase += dt * PULSE_FREQUENCY * 0.5f; // Slower pulse during fadeout
colorCyclePhase += dt * COLOR_CYCLE_SPEED * 0.3f;
if (fadeTimer >= FADE_DURATION)
dead = true;
break;
}
for (i = chargeParticles.size() - 1; i >= 0; i--) {
p = chargeParticles.get(i);
if (p.update(dt)) chargeParticles.remove(i);
}
for (i = ringEffects.size() - 1; i >= 0; i--) {
r = ringEffects.get(i);
if (r.update(dt)) ringEffects.remove(i);
}
for (i = arcParticles.size() - 1; i >= 0; i--) {
a = arcParticles.get(i);
if (a.update(dt)) arcParticles.remove(i);
}
// If beam width changed significantly, invalidate the cached glow
currentWidth = getBeamWidth();
if (Math.abs(currentWidth - lastCachedWidth) > 5f) {
cachedGlow = null;
lastCachedWidth = currentWidth;
}
}
// Helper method to get current beam width based on phase and pulse
private float getBeamWidth() {
float pulse = (float) Math.sin(pulsePhase) * 0.5f + 0.5f;
float baseW = BASE_WIDTH + pulse * PULSE_AMPLITUDE;
if (phase == Phase.FADEOUT) {
float t = fadeTimer / FADE_DURATION;
baseW *= (1f - t);
}
return baseW;
}
// Methods to spawn new particle types
private void spawnArcParticle(float x, float y, float angle, float length) {
arcParticles.add(new ArcTrailParticle(x, y, angle, length));
}
@Override
public void draw(Graphics2D g) {
int i = 0;
int idx = 0;
float histAng = 0f;
float layerA = 0f;
float layerW = 0f;
ArcTrailParticle arc = null;
RingPulseEffect r = null;
ChargeOrbParticle p = null;
float pulse = (float) Math.sin(pulsePhase) * 0.5f + 0.5f;
float baseW = BASE_WIDTH + pulse * PULSE_AMPLITUDE;
float alpha = 1f;
float drawWidth = baseW;
if (phase == Phase.CHARGING) {
alpha = 0.3f + 0.7f * (chargeTimer / CHARGE_DURATION);
// Draw enhanced warning line with glow
drawWarningLine(g, alpha);
// Draw a pulsing circle at the beam origin during charging
drawChargingOriginEffect(g, alpha);
} else {
// Draw main beam
if (phase == Phase.FADEOUT) {
float t = fadeTimer / FADE_DURATION;
alpha *= (1f - t);
drawWidth *= (1f - t);
}
// Draw beam glow effect first (behind the main beam)
drawBeamGlow(g, angle, drawWidth * GLOW_WIDTH_RATIO, alpha * 0.6f);
// Draw history layers for motion blur effect
for (i = 0; i < angleHistory.length; i++) {
idx = (historyIndex - i + angleHistory.length) % angleHistory.length;
histAng = angleHistory[idx];
layerA = alpha * (1f - i * 0.2f);
layerW = drawWidth * (1f - i * 0.1f);
drawBeamLayer(g, histAng, layerW, layerA);
}
// Draw arc trail effects on top of beam
int aIndex = 0;
ArcTrailParticle aIter = null;
for (aIndex = 0; aIndex < arcParticles.size(); aIndex++) {
aIter = arcParticles.get(aIndex);
arc = aIter;
arc.draw(g);
}
}
// Draw ring effects and charge particles
int rIndex = 0;
RingPulseEffect rIter = null;
int pIndex = 0;
ChargeOrbParticle pIter = null;
for (rIndex = 0; rIndex < ringEffects.size(); rIndex++) {
rIter = ringEffects.get(rIndex);
r = rIter;
r.draw(g);
}
for (pIndex = 0; pIndex < chargeParticles.size(); pIndex++) {
pIter = chargeParticles.get(pIndex);
p = pIter;
p.draw(g);
}
}
// New method to draw pulsing charging effect at beam origin
private void drawChargingOriginEffect(Graphics2D g, float alpha) {
Composite oldComp = g.getComposite();
// Calculate pulse based on charge progress
float chargeProgress = chargeTimer / CHARGE_DURATION;
float pulseSize = 20f + chargeProgress * 60f + (float) Math.sin(pulsePhase) * 10f;
// Draw outer glow
RadialGradientPaint outerGlow = new RadialGradientPaint(
new Point2D.Float(x, y),
pulseSize * 1.2f,
new float[] { 0.2f, 1f },
new Color[] {
new Color(220, 100, 255, (int) (120 * alpha)),
new Color(220, 100, 255, 0)
});
g.setComposite(AlphaComposite.SrcOver.derive(alpha * 0.7f));
g.setPaint(outerGlow);
g.fill(new Ellipse2D.Float(x - pulseSize * 1.2f, y - pulseSize * 1.2f,
pulseSize * 2.4f, pulseSize * 2.4f));
// Draw inner circle with shifting colors
float hue = (colorCyclePhase * 0.2f) % 1.0f;
Color innerColor = Color.getHSBColor(hue, 0.7f, 1.0f);
g.setComposite(AlphaComposite.SrcOver.derive(alpha * 0.9f));
g.setColor(innerColor);
g.fill(new Ellipse2D.Float(x - pulseSize * 0.4f, y - pulseSize * 0.4f,
pulseSize * 0.8f, pulseSize * 0.8f));
// Draw pulsing rings
g.setComposite(AlphaComposite.SrcOver.derive(alpha * 0.5f));
g.setStroke(new BasicStroke(2f));
g.setColor(new Color(220, 150, 255));
g.drawOval((int) (x - pulseSize * 0.8f), (int) (y - pulseSize * 0.8f),
(int) (pulseSize * 1.6f), (int) (pulseSize * 1.6f));
g.setComposite(oldComp);
}
// New method to draw the beam's outer glow
private void drawBeamGlow(Graphics2D g, float ang, float width, float alpha) {
Composite oldComp = g.getComposite();
int i = 0;
int sx = (int) x;
int sy = (int) y;
int ex = (int) (x + Math.cos(ang) * length);
int ey = (int) (y + Math.sin(ang) * length);
// Use cached glow if available, otherwise create it
if (cachedGlow == null || cachedGlow.getWidth() < width * 2) {
int glowSize = (int) (width * 2);
cachedGlow = new BufferedImage(glowSize, glowSize, BufferedImage.TYPE_INT_ARGB);
Graphics2D glowG = cachedGlow.createGraphics();
// Create a radial gradient for the glow
RadialGradientPaint glowPaint = new RadialGradientPaint(
new Point2D.Float(glowSize / 2f, glowSize / 2f),
glowSize / 2f,
new float[] { 0f, 0.5f, 1f },
new Color[] {
new Color(220, 100, 255, 180),
new Color(180, 50, 255, 100),
new Color(100, 20, 200, 0)
});
glowG.setPaint(glowPaint);
glowG.fillOval(0, 0, glowSize, glowSize);
glowG.dispose();
lastCachedWidth = width;
}
g.setComposite(AlphaComposite.SrcOver.derive(alpha * 0.7f));
// Draw the glow along the beam path
AffineTransform oldTransform = g.getTransform();
// Calculate beam angle
double beamAngle = Math.atan2(ey - sy, ex - sx);
// Draw glow at multiple points along the beam
int steps = (int) (length / (width / 2)) + 1;
for (i = 0; i < steps; i++) {
float t = (float) i / steps;
int px = (int) (sx + (ex - sx) * t);
int py = (int) (sy + (ey - sy) * t);
// Modulate glow size slightly for more interest
float sizeModifier = 1.0f + 0.1f * (float) Math.sin(pulsePhase + t * 5f);
int glowWidth = (int) (width * sizeModifier);
g.drawImage(cachedGlow,
px - glowWidth / 2, py - glowWidth / 2,
glowWidth, glowWidth, null);
}
g.setTransform(oldTransform);
g.setComposite(oldComp);
}
private void drawWarningLine(Graphics2D g, float alpha) {
Composite old = g.getComposite();
Stroke oldStroke = g.getStroke();
int sx = (int) x;
int sy = (int) y;
int ex = (int) (x + Math.cos(angle) * length);
int ey = (int) (y + Math.sin(angle) * length);
// Calculate charging progress
float progress = chargeTimer / CHARGE_DURATION;
// Draw outer glow line
g.setComposite(AlphaComposite.SrcOver.derive(alpha * 0.5f));
g.setStroke(new BasicStroke(12f * progress + 4f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
g.setColor(new Color(220, 100, 255, 120));
g.drawLine(sx, sy, ex, ey);
// Draw main line with pulsating effect
float pulse = (float) Math.sin(pulsePhase) * 0.5f + 0.5f;
float width = 4f + pulse * 4f * progress;
// Draw inner line with shifting hue
float hue = (colorCyclePhase * 0.2f) % 1.0f;
Color lineColor = Color.getHSBColor(hue, 0.6f, 1.0f);
g.setComposite(AlphaComposite.SrcOver.derive(alpha * 0.8f));
g.setStroke(new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
g.setColor(lineColor);
g.drawLine(sx, sy, ex, ey);
// Draw dashed overlay effect
float dashPhase = pulsePhase * 2f % (float) (Math.PI * 2);
g.setComposite(AlphaComposite.SrcOver.derive(alpha * 0.6f));
g.setStroke(new BasicStroke(width * 0.8f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
10.0f, new float[] { 15.0f, 10.0f }, dashPhase));
g.setColor(new Color(255, 255, 255, 180));
g.drawLine(sx, sy, ex, ey);
g.setComposite(old);
g.setStroke(oldStroke);
}
private void drawBeamLayer(Graphics2D g, float ang, float width, float alpha) {
Composite oldComp = g.getComposite();
Stroke oldStroke = g.getStroke();
Color oldColor = g.getColor();
int sx = (int) x;
int sy = (int) y;
int ex = (int) (x + Math.cos(ang) * length);
int ey = (int) (y + Math.sin(ang) * length);
// Calculate dynamic color values based on pulse and color cycle
float pulse = (float) Math.sin(pulsePhase) * 0.5f + 0.5f;
float hueShift = colorCyclePhase * 0.15f % 1.0f;
Color outerColor = Color.getHSBColor(
(0.75f + hueShift) % 1.0f, // Purple-to-blue hue range
0.7f,
0.9f);
Color coreColor = Color.getHSBColor(
(0.83f + hueShift) % 1.0f, // Shifting from deep purple to violet
0.6f,
1.0f);
// Outer glow layer - large, soft gradient
g.setComposite(AlphaComposite.SrcOver.derive(alpha * 0.3f));
g.setStroke(new BasicStroke(width * 1.6f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
g.setPaint(new GradientPaint(
sx, sy,
new Color(255, 255, 255, 120),
ex, ey,
new Color(
outerColor.getRed(),
outerColor.getGreen(),
outerColor.getBlue(),
0)));
g.drawLine(sx, sy, ex, ey);
// Middle layer - vibrant, semi-transparent
g.setComposite(AlphaComposite.SrcOver.derive(alpha * 0.8f));
g.setColor(new Color(
outerColor.getRed(),
outerColor.getGreen(),
outerColor.getBlue(),
200));
g.setStroke(new BasicStroke(width * 1.1f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
g.drawLine(sx, sy, ex, ey);
// Inner core - intensely bright
g.setComposite(AlphaComposite.SrcOver.derive(alpha * 0.95f));
g.setColor(Color.WHITE);
g.setStroke(new BasicStroke(width * 0.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
g.drawLine(sx, sy, ex, ey);
// Dark core - adds depth
g.setComposite(AlphaComposite.SrcOver.derive(alpha * 0.8f));
g.setColor(coreColor);
g.setStroke(new BasicStroke(width * CORE_WIDTH_RATIO, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
g.drawLine(sx, sy, ex, ey);
// Draw energy arcs emanating from beam
g.setComposite(AlphaComposite.SrcOver.derive(alpha * 0.7f));
g.setStroke(new BasicStroke(2f + pulse * 1.5f));
g.setColor(Color.WHITE);
float frac = 0f;
int ax = 0;
int ay = 0;
int len = 0;
double off = 0.0;
int bx = 0;
int by = 0;
int j = 0;
for (j = 0; j < 15; j++) {
frac = rand.nextFloat();
ax = (int) (sx + Math.cos(ang) * length * frac);
ay = (int) (sy + Math.sin(ang) * length * frac);
len = 15 + rand.nextInt(30);
off = (rand.nextFloat() - 0.5f) * Math.PI / 2.5f;
bx = (int) (ax + Math.cos(ang + off) * len);
by = (int) (ay + Math.sin(ang + off) * len);
// Create a gradient for each arc
g.setPaint(new GradientPaint(
ax, ay,
new Color(255, 255, 255, 180),
bx, by,
new Color(200, 100, 255, 0)));
g.drawLine(ax, ay, bx, by);
}
// Source flare (beam origin) - enhanced with shifting colors
Color sourceColor = Color.getHSBColor(
(0.12f + hueShift) % 1.0f, // Gold to orange
0.8f,
1.0f);
RadialGradientPaint srcFlare = new RadialGradientPaint(
new Point2D.Float(sx, sy),
FLARE_RADIUS * (1.0f + pulse * 0.2f),
new float[] { 0f, 0.5f, 1f },
new Color[] {
Color.WHITE,
new Color(sourceColor.getRed(), sourceColor.getGreen(), sourceColor.getBlue(),
(int) (220 * alpha)),
new Color(sourceColor.getRed(), sourceColor.getGreen(), sourceColor.getBlue(), 0)
});
g.setPaint(srcFlare);
float flareSize = FLARE_RADIUS * (1.0f + pulse * 0.2f);
g.fill(new Ellipse2D.Float(
sx - flareSize,
sy - flareSize,
flareSize * 2,
flareSize * 2));
// Tip flare (end of beam) - pulsing, vivid corona
Color tipColor = Color.getHSBColor(
(0.78f + hueShift) % 1.0f, // Purple to magenta
0.7f,
1.0f);
float tipSize = FLARE_RADIUS * 0.8f * (1.0f + pulse * 0.3f);
RadialGradientPaint tipFlare = new RadialGradientPaint(
new Point2D.Float(ex, ey),
tipSize,
new float[] { 0f, 0.4f, 1f },
new Color[] {
Color.WHITE,
new Color(tipColor.getRed(), tipColor.getGreen(), tipColor.getBlue(), (int) (200 * alpha)),
new Color(tipColor.getRed(), tipColor.getGreen(), tipColor.getBlue(), 0)
});
g.setPaint(tipFlare);
g.fill(new Ellipse2D.Float(
ex - tipSize,
ey - tipSize,
tipSize * 2,
tipSize * 2));
// Pulsing ring at the beam tip
float ringR = 20f + (float) Math.sin(pulsePhase * 1.5f) * 8f;
g.setComposite(AlphaComposite.SrcOver.derive(alpha * 0.7f));
g.setStroke(new BasicStroke(2f + pulse * 1.5f));
g.setColor(new Color(230, 180, 255));
g.drawOval((int) (ex - ringR), (int) (ey - ringR), (int) (ringR * 2), (int) (ringR * 2));
// Second ring with opposite pulse
float ring2R = 15f + (float) Math.sin(pulsePhase * 1.5f + Math.PI) * 6f;
g.setComposite(AlphaComposite.SrcOver.derive(alpha * 0.5f));
g.setStroke(new BasicStroke(1.5f));
g.setColor(Color.WHITE);
g.drawOval((int) (ex - ring2R), (int) (ey - ring2R), (int) (ring2R * 2), (int) (ring2R * 2));
g.setComposite(oldComp);
g.setStroke(oldStroke);
g.setColor(oldColor);
}
private void spawnChargeParticle() {
float v = 50f + rand.nextFloat() * 80f;
float ang = rand.nextFloat() * (float) (Math.PI * 2);
float vx = (float) Math.cos(ang) * v;
float vy = (float) Math.sin(ang) * v;
float size = 8f + rand.nextFloat() * 6f;
chargeParticles.add(new ChargeOrbParticle(x, y, vx, vy, size));
}
private static class ChargeOrbParticle {
private float x, y, vx, vy, size, life = 0f;
private float rotationAngle, rotationSpeed;
private static final float MAX_LIFE = 0.6f;
public ChargeOrbParticle(float x, float y, float vx, float vy, float size) {
this.x = x;
this.y = y;
this.vx = vx;
this.vy = vy;
this.size = size;
// Random rotation for more dynamic particles
Random rand = new Random();
this.rotationAngle = rand.nextFloat() * (float) (Math.PI * 2);
this.rotationSpeed = (rand.nextFloat() * 2f + 1f) * (rand.nextBoolean() ? 1 : -1);
}
public boolean update(float dt) {
life += dt;
x += vx * dt;
y += vy * dt;
// Slow down over time
vx *= 0.95f;
vy *= 0.95f;
// Rotate
rotationAngle += rotationSpeed * dt;
return life >= MAX_LIFE;
}
public void draw(Graphics2D g) {
float lifeProgress = 0f;
float a = 0f;
float currentSize = 0f;
Composite old = null;
AffineTransform oldTransform = null;
int points = 0;
float outerRadius = 0f;
float innerRadius = 0f;
int[] xPoints = null;
int[] yPoints = null;
int i = 0;
float radius = 0f;
float angle = 0f;
lifeProgress = life / MAX_LIFE;
a = 1f - lifeProgress;
// Size expands slightly then contracts
currentSize = size * (1.0f + 0.5f * lifeProgress - lifeProgress * lifeProgress * 2f);
old = g.getComposite();
oldTransform = g.getTransform();
// Inner glow
g.setComposite(AlphaComposite.SrcOver.derive(a * 0.7f));
// Calculate colors with hue shifting
float hue = (0.12f + lifeProgress * 0.05f) % 1.0f;
Color particleColor = Color.getHSBColor(hue, 0.8f, 1.0f);
// Draw outer glow
RadialGradientPaint glowPaint = new RadialGradientPaint(
new Point2D.Float(x, y),
Math.max(0.1f, currentSize * 1.5f),
new float[] { 0.2f, 1f },
new Color[] {
new Color(particleColor.getRed(), particleColor.getGreen(), particleColor.getBlue(),
(int) (150 * a)),
new Color(particleColor.getRed(), particleColor.getGreen(), particleColor.getBlue(), 0)
});
g.setPaint(glowPaint);
g.fill(new Ellipse2D.Float(
x - currentSize * 1.5f,
y - currentSize * 1.5f,
currentSize * 3f,
currentSize * 3f));
// Draw core
g.setComposite(AlphaComposite.SrcOver.derive(a * 0.9f));
// Apply rotation for the star shape
g.translate(x, y);
g.rotate(rotationAngle);
// Draw star shape
points = 5;
outerRadius = currentSize * 0.5f;
innerRadius = outerRadius * 0.4f;
xPoints = new int[points * 2];
yPoints = new int[points * 2];
for (i = 0; i < points * 2; i++) {
radius = (i % 2 == 0) ? outerRadius : innerRadius;
angle = (float) (i * Math.PI / points);
xPoints[i] = (int) (Math.cos(angle) * radius);
yPoints[i] = (int) (Math.sin(angle) * radius);
}
g.setColor(Color.WHITE);
g.fillPolygon(xPoints, yPoints, points * 2);
// Core glow
g.setColor(particleColor);
g.fillOval(
(int) (-currentSize * 0.25f),
(int) (-currentSize * 0.25f),
(int) (currentSize * 0.5f),
(int) (currentSize * 0.5f));
g.setTransform(oldTransform);
g.setComposite(old);
}
}
private static class RingPulseEffect {
private float x, y, timer = 0f;
private float initialAlpha;
private int ringColor;
private float rotationAngle, rotationSpeed;
static final float DUR = 0.4f;
public RingPulseEffect(float x, float y) {
this(x, y, 0.8f);
}
public RingPulseEffect(float x, float y, float chargeProgress) {
this.x = x;
this.y = y;
// Vary the color based on charge progress
Random rand = new Random();
float hue;
if (chargeProgress < 0.5f) {
// Purple to pink
hue = 0.75f + (rand.nextFloat() * 0.1f);
} else {
// Pink to gold
hue = 0.85f + (rand.nextFloat() * 0.15f);
}
this.ringColor = Color.HSBtoRGB(hue % 1.0f, 0.7f, 1.0f);
this.initialAlpha = 0.5f + 0.5f * chargeProgress;
// Random rotation for the ring gaps
this.rotationAngle = rand.nextFloat() * (float) (Math.PI * 2);
this.rotationSpeed = (rand.nextFloat() * 0.5f + 0.5f) * (rand.nextBoolean() ? 1 : -1);
}
public boolean update(float dt) {
timer += dt;
rotationAngle += rotationSpeed * dt;
return timer >= DUR;
}
public void draw(Graphics2D g) {
float t = 0f;
float r = 0f;
float a = 0f;
Composite old = null;
Stroke oldStroke = null;
int segments = 0;
float segmentAngle = 0f;
float gapAngle = 0f;
int i = 0;
float startAngle = 0f;
float arcAngle = 0f;
t = timer / DUR;
r = FLARE_RADIUS * (1f + t * 1.2f);
a = (1f - t) * initialAlpha;
old = g.getComposite();
oldStroke = g.getStroke();
// Draw outer glow
g.setComposite(AlphaComposite.SrcOver.derive(a * 0.4f));
g.setStroke(new BasicStroke(3f + t * 2f));
Color outerColor = new Color(ringColor & 0xFFFFFF, true); // Remove alpha
g.setColor(outerColor);
g.drawOval((int) (x - r * 1.05f), (int) (y - r * 1.05f), (int) (2 * r * 1.05f), (int) (2 * r * 1.05f));
// Draw main ring
g.setComposite(AlphaComposite.SrcOver.derive(a * 0.8f));
g.setStroke(new BasicStroke(2f));
g.setColor(new Color((ringColor & 0xFFFFFF) | ((int) (255 * a) << 24), true));
// Draw main ring with gaps
AffineTransform oldTransform = g.getTransform();
g.translate(x, y);
g.rotate(rotationAngle);
// Draw arc segments instead of complete circle
segments = 8;
segmentAngle = (float) (2 * Math.PI / segments);
gapAngle = segmentAngle * 0.3f;
for (i = 0; i < segments; i++) {
startAngle = i * segmentAngle;
arcAngle = segmentAngle - gapAngle;
g.drawArc(
(int) (-r), (int) (-r),
(int) (2 * r), (int) (2 * r),
(int) Math.toDegrees(startAngle),
(int) Math.toDegrees(arcAngle));
}
// Draw a second ring with a different phase
float r2 = r * 0.85f;
g.setComposite(AlphaComposite.SrcOver.derive(a * 0.6f));
g.rotate(Math.PI / segments); // Offset for the second ring
for (i = 0; i < segments; i++) {
startAngle = i * segmentAngle;
arcAngle = segmentAngle - gapAngle;
g.drawArc(
(int) (-r2), (int) (-r2),
(int) (2 * r2), (int) (2 * r2),
(int) Math.toDegrees(startAngle),
(int) Math.toDegrees(arcAngle));
}
g.setTransform(oldTransform);
g.setComposite(old);
g.setStroke(oldStroke);
}
}
/**
* Arc trail effect that creates electrical arc particles along the beam
*/
private static class ArcTrailParticle {
private float x, y, angle, length;
private float life = 0f, maxLife;
private int segments;
private float[] offsets;
private float offsetScale;
private static Random rand = new Random();
public ArcTrailParticle(float x, float y, float angle, float length) {
int i = 0;
this.x = x;
this.y = y;
this.angle = angle;
this.length = length;
this.maxLife = 0.2f + rand.nextFloat() * 0.2f;
// Create jagged arc
this.segments = 5 + rand.nextInt(4);
this.offsets = new float[segments];
this.offsetScale = 2f + rand.nextFloat() * 3f;
for (i = 0; i < segments; i++) {
offsets[i] = (rand.nextFloat() * 2f - 1f);
}
}
public boolean update(float dt) {
life += dt;
// Increase jaggedness over time
offsetScale += dt * 5f;
return life >= maxLife;
}
public void draw(Graphics2D g) {
float lifeProgress = 0f;
float alpha = 0f;
GeneralPath path = null;
float segmentLength = 0f;
float currentX = 0f;
float currentY = 0f;
int i = 0;
float progress = 0f;
float offsetAngle = 0f;
float nextX = 0f;
float nextY = 0f;
Composite oldComp = null;
Stroke oldStroke = null;
lifeProgress = life / maxLife;
alpha = 1f - lifeProgress;
// Create a path for the arc
path = new GeneralPath();
path.moveTo(x, y);
segmentLength = length / segments;
currentX = x;
currentY = y;
for (i = 0; i < segments; i++) {
progress = (float) (i + 1) / segments;
offsetAngle = offsets[i] * offsetScale * (1f + lifeProgress * 2f);
// The offset angle increases with time for more chaotic effect
nextX = x + (float) Math.cos(angle + offsetAngle * 0.2f) * length * progress;
nextY = y + (float) Math.sin(angle + offsetAngle * 0.2f) * length * progress;
path.lineTo(nextX, nextY);
currentX = nextX;
currentY = nextY;
}
// Draw with glow effect
oldComp = g.getComposite();
oldStroke = g.getStroke();
// Outer glow
g.setComposite(AlphaComposite.SrcOver.derive(alpha * 0.5f));
g.setStroke(new BasicStroke(4f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
g.setColor(new Color(180, 100, 255, (int) (100 * alpha)));
g.draw(path);
// Inner bright core
g.setComposite(AlphaComposite.SrcOver.derive(alpha * 0.8f));
g.setStroke(new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
g.setColor(new Color(255, 255, 255, (int) (230 * alpha)));
g.draw(path);
g.setComposite(oldComp);
g.setStroke(oldStroke);
}
}
}