Skip to content

Commit ef061fe

Browse files
committed
Changed the name color due to low visibility on sand;
Fixed the position for the username text and cached the divisions.
1 parent 26bed52 commit ef061fe

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/com/redomar/game/entities/Player.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public class Player extends Mob {
2828
private boolean[] swimType;
2929
private int[] swimColour;
3030
private int fireRate = 0;
31+
32+
// Need to add a class for constants
33+
private int fontCharSize = 8;
34+
// "Cache" the division for the username length, no need for 60 divisions per second here.
35+
private int nameOffset;
3136

3237
public Player(LevelHandler level, int x, int y, InputHandler input,
3338
String userName, int shirtCol, int faceCol) {
@@ -38,6 +43,8 @@ public Player(LevelHandler level, int x, int y, InputHandler input,
3843
this.shirtCol = shirtCol;
3944
this.colour = Colours.get(-1, 111, shirtCol, faceCol);
4045
fireRate = Small.FIRE_RATE;
46+
// Perfectly matches the text over the head
47+
nameOffset = (userName.length() / 2) * fontCharSize - ((userName.length() & 1) == 0 ? fontCharSize / 2 : 0);
4148
}
4249

4350
public static double getSpeed() {
@@ -193,12 +200,12 @@ public void render(Screen screen) {
193200
* Using player's own x value cast to int with an adjusted formula
194201
* -posmicanomaly
195202
*/
196-
int fontCharSize = 8;
203+
197204
Font.render(userName,
198205
screen,
199-
(int)x - ((userName.length() /2) * fontCharSize),
206+
(int)x - nameOffset,
200207
yOffset - 10,
201-
Colours.get(-1, -1, -1, 555), 1);
208+
Colours.get(-1, -1, -1, 111), 1);
202209

203210
}
204211
}

0 commit comments

Comments
 (0)