-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBoss.java
More file actions
96 lines (84 loc) · 2.74 KB
/
Copy pathBoss.java
File metadata and controls
96 lines (84 loc) · 2.74 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
/*
* Authors: Jerry Li & Victor Jiang
* Date: June 13, 2025
* Description: This class manages basic functions and properties for the generic boss class from which specific bosses extend
*/
import java.awt.*;
import java.awt.image.BufferedImage;
public abstract class Boss extends Enemy {
// Keeps track if boss has spawned its beautiful boss effects
private boolean spawnedEffects = false;
// Constructor
public Boss(int x, int y, int width, int height, int hp, float speed,
BufferedImage[] sprites, GamePanel gp) {
super(x, y, width, height, hp, speed, sprites, gp);
}
// Moves the boss around each frame
@Override
public void move(float dt, Player player) {
// Track how long boss update takes
if (!spawnedEffects) {
playSpawnEffects();
spawnedEffects = true;
}
// Don't let a stunned boss move and countdown timer
if (stunTimer > 0f) {
stunTimer -= dt;
if (stunTimer < 0f)
stunTimer = 0f;
x_velocity = 0f;
y_velocity = 0f;
return;
}
// Boss movement
moveBoss(dt, player);
// Sprite animation
spriteTimer += dt;
if (spriteTimer >= SPRITE_UPDATE_INTERVAL) {
currentSpriteIndex = (currentSpriteIndex + 1) % sprites.length;
spriteTimer -= SPRITE_UPDATE_INTERVAL;
}
// Stop tracking boss update time
}
// Effects when boss spawns
protected void playSpawnEffects() {
if (gamePanel != null) {
gamePanel.startScreenShake(4f, 100f);
}
}
// Handles how boss moves
protected abstract void moveBoss(float dt, Player player);
// Draws boss health bar on screen
protected void drawBossHealthBar(Graphics2D g) {
int barW = 0;
int barH = 0;
int bx = 0;
int by = 0;
float frac = 0f;
barW = 300;
barH = 12;
bx = (int) (getCenterX() - barW / 2);
by = (int) (getCenterY() + height / 2 + 10);
frac = Math.max(0f, Math.min(1f, getHp() / (float) getMaxHp()));
g.setColor(Color.DARK_GRAY);
g.fillRect(bx, by, barW, barH);
g.setColor(new Color(180, 70, 255));
g.fillRect(bx, by, (int) (barW * frac), barH);
g.setColor(Color.WHITE);
g.drawRect(bx, by, barW, barH);
}
// Draws damage numbers on screen
protected void drawDamageNumbers(Graphics2D g) {
int i = 0;
DamageNumber dn = null;
for (i = 0; i < damageNumbers.size(); i++) {
dn = damageNumbers.get(i);
dn.draw(g);
}
}
// Check if boss is boss!
@Override
public boolean isBoss() {
return true;
}
}