Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/com/redomar/game/entities/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public class Player extends Mob {
private boolean[] swimType;
private int[] swimColour;
private int fireRate = 0;

// Need to add a class for constants
private final int fontCharSize = 8;
// "Cache" the division for the username length, no need for 60 divisions per second here.
private int nameOffset = 0;

public Player(LevelHandler level, int x, int y, InputHandler input,
String userName, int shirtCol, int faceCol) {
Expand Down Expand Up @@ -193,12 +198,12 @@ public void render(Screen screen) {
* Using player's own x value cast to int with an adjusted formula
* -posmicanomaly
*/
int fontCharSize = 8;

Font.render(userName,
screen,
(int)x - ((userName.length() /2) * fontCharSize),
(int)x - nameOffset,
yOffset - 10,
Colours.get(-1, -1, -1, 555), 1);
Colours.get(-1, -1, -1, 111), 1);

}
}
Expand All @@ -217,8 +222,17 @@ public void setUsername(String name) {
public String getSanitisedUsername() {
if (this.getUsername() == null || this.userName.isEmpty()) {
setUsername(guestPlayerName);

// Perfectly matches the text over the head
int offsetUnit = ((userName.length() & 1) == 0 ? fontCharSize / 2 : 0);
nameOffset = (userName.length() / 2) * fontCharSize - offsetUnit;

return guestPlayerName;
} else
if(nameOffset == 0){
int offsetUnit = ((userName.length() & 1) == 0 ? fontCharSize / 2 : 0);
nameOffset = (userName.length() / 2) * fontCharSize - offsetUnit;
}
return this.getUsername();
}

Expand Down