15
15
import de .amr .pacmanfx .ui ._2d .GameRenderer ;
16
16
import de .amr .pacmanfx .uilib .assets .SpriteSheet ;
17
17
import javafx .scene .canvas .Canvas ;
18
+ import javafx .scene .image .Image ;
18
19
import javafx .scene .paint .Color ;
19
20
import javafx .scene .text .Font ;
20
21
import javafx .scene .text .FontWeight ;
@@ -52,41 +53,42 @@ public void drawHUD(GameContext gameContext, HUD hud, Vector2f sceneSize, long t
52
53
requireNonNull (hud );
53
54
if (!hud .isVisible ()) return ;
54
55
56
+ GameModel game = gameContext .theGame ();
55
57
if (hud .isScoreVisible ()) {
56
58
ctx .setFont (assets ().arcadeFont (scaled (8 )));
57
59
ctx .setFill ((ARCADE_WHITE ));
58
- drawScore (gameContext . theGame () .score (), "SCORE" , TS (1 ), TS (1 ));
59
- drawScore (gameContext . theGame () .highScore (), "HIGH SCORE" , TS (14 ), TS (1 ));
60
+ drawScore (game .score (), "SCORE" , TS (1 ), TS (1 ));
61
+ drawScore (game .highScore (), "HIGH SCORE" , TS (14 ), TS (1 ));
60
62
}
61
63
62
64
if (hud .isLevelCounterVisible ()) {
63
65
LevelCounter levelCounter = hud .theLevelCounter ();
64
- float x = sceneSize .x () - 4 * TS , y = sceneSize .y () - 2 * TS + 2 ;
66
+ float x = sceneSize .x () - TS ( 4 ) , y = sceneSize .y () - TS ( 2 ) + 2 ;
65
67
for (byte symbol : levelCounter .symbols ()) {
66
68
RectShort sprite = spriteSheet .spriteSeq (SpriteID .BONUS_SYMBOLS )[symbol ];
67
69
drawSpriteScaled (sprite , x , y );
68
- x -= TS * 2 ;
70
+ x -= TS ( 2 ) ;
69
71
}
70
72
}
71
73
72
74
if (hud .isLivesCounterVisible ()) {
73
75
LivesCounter livesCounter = hud .theLivesCounter ();
74
- float x = 2 * TS , y = sceneSize .y () - 2 * TS ;
76
+ float x = TS ( 2 ) , y = sceneSize .y () - TS ( 2 ) ;
75
77
RectShort sprite = spriteSheet .sprite (SpriteID .LIVES_COUNTER_SYMBOL );
76
78
for (int i = 0 ; i < livesCounter .visibleLifeCount (); ++i ) {
77
- drawSpriteScaled (sprite , x + TS * (2 * i ), y );
79
+ drawSpriteScaled (sprite , x + TS (2 * i ), y );
78
80
}
79
- if (gameContext . theGame () .lifeCount () > livesCounter .maxLivesDisplayed ()) {
81
+ if (game .lifeCount () > livesCounter .maxLivesDisplayed ()) {
80
82
// show text indicating that more lives are available than symbols displayed (cheating may cause this)
81
83
Font font = Font .font ("Serif" , FontWeight .BOLD , scaled (8 ));
82
- fillTextAtScaledPosition ("%d" .formatted (gameContext .theGame ().lifeCount ()), ARCADE_YELLOW , font ,
83
- x - 14 , y + TS );
84
+ fillTextAtScaledPosition ("%d" .formatted (game .lifeCount ()), ARCADE_YELLOW , font , x - 14 , y + TS );
84
85
}
85
86
}
86
87
87
88
if (hud .isCreditVisible ()) {
88
89
String text = "CREDIT %2d" .formatted (gameContext .theCoinMechanism ().numCoins ());
89
- fillTextAtScaledPosition (text , ARCADE_WHITE , assets ().arcadeFont (scaled (8 )), 2 * TS , sceneSize .y ());
90
+ Font font = assets .arcadeFont (scaled (8 ));
91
+ fillTextAtScaledPosition (text , ARCADE_WHITE , font , TS (2 ), sceneSize .y ());
90
92
}
91
93
}
92
94
@@ -110,14 +112,14 @@ public void drawLevel(
110
112
ctx .save ();
111
113
ctx .scale (scaling (), scaling ());
112
114
if (mazeHighlighted ) {
113
- String assetNamespace = ArcadePacMan_UIConfig .ASSET_NAMESPACE ;
114
- ctx .drawImage (assets . image ( assetNamespace + ".flashing_maze" ) , 0 , GameLevel .EMPTY_ROWS_OVER_MAZE * TS );
115
+ Image flashingMaze = assets . image ( ArcadePacMan_UIConfig .ASSET_NAMESPACE + ".flashing_maze" ) ;
116
+ ctx .drawImage (flashingMaze , 0 , GameLevel .EMPTY_ROWS_OVER_MAZE * TS );
115
117
}
116
118
else if (level .uneatenFoodCount () == 0 ) {
117
- drawSprite (spriteSheet .sprite (SpriteID .MAP_EMPTY ), 0 , GameLevel .EMPTY_ROWS_OVER_MAZE * TS );
119
+ drawSprite (spriteSheet .sprite (SpriteID .MAP_EMPTY ), 0 , TS ( GameLevel .EMPTY_ROWS_OVER_MAZE ) );
118
120
}
119
121
else {
120
- drawSprite (spriteSheet .sprite (SpriteID .MAP_FULL ), 0 , GameLevel .EMPTY_ROWS_OVER_MAZE * TS );
122
+ drawSprite (spriteSheet .sprite (SpriteID .MAP_FULL ), 0 , TS ( GameLevel .EMPTY_ROWS_OVER_MAZE ) );
121
123
ctx .setFill (backgroundColor );
122
124
level .worldMap ().tiles ()
123
125
.filter (not (level ::isEnergizerPosition ))
0 commit comments