From ef061fe0d6bfc50935d03895d13f821038a16b53 Mon Sep 17 00:00:00 2001 From: stephancode Date: Sun, 11 Feb 2018 16:38:57 +0200 Subject: [PATCH 1/3] Changed the name color due to low visibility on sand; Fixed the position for the username text and cached the divisions. --- src/com/redomar/game/entities/Player.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/com/redomar/game/entities/Player.java b/src/com/redomar/game/entities/Player.java index 245b675..2422b62 100644 --- a/src/com/redomar/game/entities/Player.java +++ b/src/com/redomar/game/entities/Player.java @@ -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 int fontCharSize = 8; + // "Cache" the division for the username length, no need for 60 divisions per second here. + private int nameOffset; public Player(LevelHandler level, int x, int y, InputHandler input, String userName, int shirtCol, int faceCol) { @@ -38,6 +43,8 @@ public Player(LevelHandler level, int x, int y, InputHandler input, this.shirtCol = shirtCol; this.colour = Colours.get(-1, 111, shirtCol, faceCol); fireRate = Small.FIRE_RATE; + // Perfectly matches the text over the head + nameOffset = (userName.length() / 2) * fontCharSize - ((userName.length() & 1) == 0 ? fontCharSize / 2 : 0); } public static double getSpeed() { @@ -193,12 +200,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); } } From c5dd785207b0b26b6dfef5aa1cf6231e487ce316 Mon Sep 17 00:00:00 2001 From: stephancode Date: Mon, 12 Feb 2018 17:24:41 +0200 Subject: [PATCH 2/3] Fixed a bug with the username left blank. --- src/com/redomar/game/entities/Player.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/com/redomar/game/entities/Player.java b/src/com/redomar/game/entities/Player.java index 2422b62..3ccf243 100644 --- a/src/com/redomar/game/entities/Player.java +++ b/src/com/redomar/game/entities/Player.java @@ -30,9 +30,9 @@ public class Player extends Mob { private int fireRate = 0; // Need to add a class for constants - private int fontCharSize = 8; + private final int fontCharSize = 8; // "Cache" the division for the username length, no need for 60 divisions per second here. - private int nameOffset; + private int nameOffset = 0; public Player(LevelHandler level, int x, int y, InputHandler input, String userName, int shirtCol, int faceCol) { @@ -43,8 +43,6 @@ public Player(LevelHandler level, int x, int y, InputHandler input, this.shirtCol = shirtCol; this.colour = Colours.get(-1, 111, shirtCol, faceCol); fireRate = Small.FIRE_RATE; - // Perfectly matches the text over the head - nameOffset = (userName.length() / 2) * fontCharSize - ((userName.length() & 1) == 0 ? fontCharSize / 2 : 0); } public static double getSpeed() { @@ -224,6 +222,11 @@ 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 return this.getUsername(); From 9968cc2ebba924b590309378e83c2b82da327247 Mon Sep 17 00:00:00 2001 From: stephancode Date: Mon, 12 Feb 2018 17:28:06 +0200 Subject: [PATCH 3/3] Fixed another bug for the username, result from the previous commit. --- src/com/redomar/game/entities/Player.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/com/redomar/game/entities/Player.java b/src/com/redomar/game/entities/Player.java index 3ccf243..e959c1b 100644 --- a/src/com/redomar/game/entities/Player.java +++ b/src/com/redomar/game/entities/Player.java @@ -229,6 +229,10 @@ public String getSanitisedUsername() { return guestPlayerName; } else + if(nameOffset == 0){ + int offsetUnit = ((userName.length() & 1) == 0 ? fontCharSize / 2 : 0); + nameOffset = (userName.length() / 2) * fontCharSize - offsetUnit; + } return this.getUsername(); }