From 996addcaf8351291b1f30b06e83f88c79dfdedb6 Mon Sep 17 00:00:00 2001 From: punchready Date: Mon, 19 Jul 2021 14:36:18 +0200 Subject: [PATCH] fix: fix terrible vector handling --- .../java/uulm/teamname/marvelous/gamelibrary/IntVector2.java | 4 +++- .../teamname/marvelous/gamelibrary/gamelogic/GameLogic.java | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/IntVector2.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/IntVector2.java index fa076f3..801e45a 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/IntVector2.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/IntVector2.java @@ -79,7 +79,9 @@ public class IntVector2 implements Serializable { } public IntVector2 sub(int x, int y) { - return new IntVector2(this.x - x, this.y - y); + this.x -= x; + this.y -= y; + return this; } public IntVector2 sub(IntVector2 v) { diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java index a1c2f38..f885d9c 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java @@ -711,7 +711,7 @@ public class GameLogic { } for(IntVector2 dir: IntVector2.CardinalDirections) { - IntVector2 pos = start.add(dir); + IntVector2 pos = start.copy().add(dir); if(pos.getX() < 0 || pos.getX() >= state.mapSize.getX() || pos.getY() < 0 || pos.getY() >= state.mapSize.getY()) { return options; } @@ -721,7 +721,7 @@ public class GameLogic { } if(options.size() == 0) { - return getFreeNeighbour(state, start.add(IntVector2.CardinalDirections[rand.nextInt(IntVector2.CardinalDirections.length)])); + return getFreeNeighbour(state, start.copy().add(IntVector2.CardinalDirections[rand.nextInt(IntVector2.CardinalDirections.length)])); }else { return options; }