44import engine .DrawManager ;
55import engine .Score ;
66import entity .Entity ;
7- import entity .ShipFactory ;
7+ import entity .player . PlayerLevel ;
88import entity .player .PlayerShip ;
99import java .awt .*;
1010import java .awt .geom .AffineTransform ;
11+ import java .awt .image .BufferedImage ;
1112import java .util .List ;
1213import screen .Screen ;
1314
@@ -36,20 +37,6 @@ public static void drawAlertMessage(final Screen screen, final String alertMessa
3637 alertMessage , (screen .getWidth () - fontRegularMetrics .stringWidth (alertMessage )) / 2 , 65 );
3738 }
3839
39- /**
40- * Draws number of remaining lives on screen.
41- *
42- * @param screen Screen to draw on.
43- * @param lives Current lives.
44- */
45- public void drawLives (final Screen screen , final int lives , final PlayerShip .ShipType shipType ) {
46- backBufferGraphics .setFont (fontRegular );
47- backBufferGraphics .setColor (Color .WHITE );
48- backBufferGraphics .drawString (Integer .toString (lives ), 20 , 25 );
49- PlayerShip dummyPlayerShip = ShipFactory .create (shipType , 0 , 0 );
50- for (int i = 0 ; i < lives ; i ++) drawEntity (dummyPlayerShip , 40 + 35 * i , 10 );
51- }
52-
5340 /**
5441 * Draws level on screen.
5542 *
@@ -218,6 +205,21 @@ public static void drawHorizontalLine(final Screen screen, final int positionY)
218205 backBufferGraphics .drawLine (0 , positionY + 1 , screen .getWidth (), positionY + 1 );
219206 }
220207
208+ /**
209+ * Draw a background box for HUD.
210+ *
211+ * @param screen Screen to draw on.
212+ * @param x X coordinate of the box.
213+ * @param y Y coordinate of the box.
214+ * @param w Width of the box.
215+ * @param h Height of the box.
216+ */
217+ public static void drawHudPanel (
218+ final Screen screen , final int x , final int y , final int w , final int h ) {
219+ backBufferGraphics .setColor (Color .BLACK );
220+ backBufferGraphics .fillRect (x , y , w , h );
221+ }
222+
221223 /**
222224 * Draws a horizontal bar composed of multiple box segments.
223225 *
@@ -234,15 +236,17 @@ public static void drawSegmentedBar(
234236 int basicWidth = w / maximumValue ; // Basic width of each box
235237 int remainingWidth = w % maximumValue ; // Remaining width to be distributed
236238
237- // Draw filled and empty boxes
239+ int filledBoxes = (int ) ((double ) currentValue / maximumValue * w );
240+
238241 int startX = x ; // Initial x coordinate for the first box
239242 for (int i = 0 ; i < maximumValue ; i ++) {
240243 int boxWidth = basicWidth ;
244+
241245 if (i < remainingWidth ) {
242246 boxWidth += 1 ; // Distribute the remaining width to the first few boxes
243247 }
244248
245- if (i < currentValue ) {
249+ if (startX < x + filledBoxes ) {
246250 backBufferGraphics .setColor (color ); // Color for filled boxes
247251 } else {
248252 backBufferGraphics .setColor (Color .GRAY ); // Color for empty boxes
@@ -253,33 +257,50 @@ public static void drawSegmentedBar(
253257 }
254258 }
255259
256- /**
257- * Draws a thicker box outline by drawing two overlapping boxes.
258- *
259- * @param screen Screen to draw on.
260- * @param x X coordinate of the upper-left corner of the inner box.
261- * @param y Y coordinate of the upper-left corner of the inner box.
262- * @param w Width of the inner box.
263- * @param h Height of the inner box.
264- * @param thickness Thickness of the outer box.
265- */
266- public static void drawThickBox (
267- final Screen screen ,
268- final int x ,
269- final int y ,
270- final int w ,
271- final int h ,
272- final int thickness ) {
273- // Ensure thickness is not greater than the width or height
274- if (thickness * 2 > w || thickness * 2 > h ) {
275- throw new IllegalArgumentException ("Thickness is too large for the given width or height" );
276- }
260+ /** Draws a stat value */
261+ public static void drawStat (final Screen screen , final int stat , int x , int y ) {
262+ int BOX_WIDTH = 48 ;
263+ int BOX_HEIGHT = 48 ;
264+ backBufferGraphics .setColor (Color .WHITE );
265+ String statText = Integer .toString (stat );
277266
278- backBufferGraphics .setColor (Color .GREEN );
279- backBufferGraphics .fillRect (x , y , w , h ); // Outer box
280- backBufferGraphics .setColor (Color .BLACK );
281- backBufferGraphics .fillRect (
282- x + thickness , y + thickness , w - 2 * thickness , h - 2 * thickness ); // Draw inner box
267+ FontMetrics metrics = backBufferGraphics .getFontMetrics (fontBig );
268+ int textWidth = metrics .stringWidth (statText );
269+ int textHeight = metrics .getHeight ();
270+
271+ int drawX = x + (BOX_WIDTH - textWidth ) / 2 ;
272+ int drawY = y + (BOX_HEIGHT + textHeight ) / 2 ;
273+
274+ backBufferGraphics .drawString (statText , drawX , drawY );
275+ }
276+
277+ /** Draws a stat icon */
278+ public static void drawStatIcon (Screen screen , int num , int x , int y ) {
279+ BufferedImage [] statImages =
280+ new BufferedImage [] {
281+ img_movespeed ,
282+ img_bulletspeed ,
283+ img_attackdamage ,
284+ img_shotinterval ,
285+ img_bulletscount ,
286+ img_additionallife
287+ };
288+ backBufferGraphics .drawImage (statImages [num ], x , y , 25 , 18 , null );
289+ }
290+
291+ /** Draws a player level */
292+ public static void drawPlayerLevel (final Screen screen , final PlayerLevel level , int x , int y ) {
293+ backBufferGraphics .setFont (fontBig );
294+ backBufferGraphics .setColor (Color .WHITE );
295+
296+ int levelValue = level .getLevel ();
297+ if (levelValue < 10 ) {
298+ String scoreString = String .format ("lv.0%d" , levelValue );
299+ backBufferGraphics .drawString (scoreString , x , y );
300+ } else {
301+ String scoreString = String .format ("lv.%d" , levelValue );
302+ backBufferGraphics .drawString (scoreString , x , y );
303+ }
283304 }
284305
285306 /**
0 commit comments