-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHUD.java
More file actions
89 lines (77 loc) · 2.52 KB
/
Copy pathHUD.java
File metadata and controls
89 lines (77 loc) · 2.52 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
/*
* Authors: Jerry Li & Victor Jiang
* Date: June 13, 2025
* Description: This class manages and renders UI elements like the health bar, wave progress bar, timer, etc.
*/
import java.awt.*;
public class HUD {
// The health bar component of the HUD, which displays the player's health.
public final HealthBar HEALTH_BAR;
// The wave progress bar component of the HUD, which shows the progress of the
// current wave.
public final WaveProgressBar WAVE_PROGRESS_BAR;
// The game timer component of the HUD, which tracks and displays elapsed time.
public final GameTimer GAME_TIMER;
/**
* Constructs the HUD with the specified player and font.
* Initializes the health bar, wave progress bar, and game timer.
*/
public HUD(Player player, Font font, GamePanel gamePanel) {
this.HEALTH_BAR = new HealthBar(player);
this.WAVE_PROGRESS_BAR = new WaveProgressBar(font, gamePanel);
this.GAME_TIMER = new GameTimer(font);
}
/**
* Starts the game timer.
*/
public void startTimer() {
GAME_TIMER.start();
}
/**
* Stops the game timer.
*/
public void stopTimer() {
GAME_TIMER.stop();
}
/**
* Resets the game timer to its initial state.
*/
public void resetTimer() {
GAME_TIMER.reset();
}
/**
* Updates the wave progress bar with the number of enemies defeated
* and the total number of enemies required to complete the wave.
*/
public void updateWaveProgress(int enemiesDefeated) {
WAVE_PROGRESS_BAR.updateProgress(enemiesDefeated);
}
/**
* Sets the current wave number in the wave progress bar.
*/
public void nextWave() {
WAVE_PROGRESS_BAR.nextWave();
}
public void setCurrentWave(int wave) {
WAVE_PROGRESS_BAR.setCurrentWave(wave);
}
public void reset() {
WAVE_PROGRESS_BAR.reset(); // Reset the wave progress bar
GAME_TIMER.reset(); // Reset the game timer
}
/**
* Retrieves the elapsed time in milliseconds from the game timer.
*/
public long getElapsedTimeMillis() {
return GAME_TIMER.getElapsedTimeMillis();
}
/**
* Draws the HUD components (health bar, wave progress bar, and game timer)
* on the screen using the provided Graphics2D object and screen width.
*/
public void draw(Graphics2D g2d, int screenWidth) {
HEALTH_BAR.draw(g2d);
WAVE_PROGRESS_BAR.draw(g2d, screenWidth);
GAME_TIMER.draw(g2d, screenWidth);
}
}