From 397fb7ebd09ed9c460cf559c6051e9044aaa95b5 Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Thu, 19 Apr 2007 15:41:31 +0000 Subject: [PATCH] Fixed selection bug and changed the astar a bit but its still not right --- src/ei/game/algo/AStar.java | 2 +- src/ei/game/algo/AStarPathfinder.java | 6 ++++-- src/ei/game/input/InGameMouseInput.java | 5 ++++- src/ei/game/scene/units/Unit.java | 12 ++++++------ 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/ei/game/algo/AStar.java b/src/ei/game/algo/AStar.java index bf69eb5..bad67a4 100644 --- a/src/ei/game/algo/AStar.java +++ b/src/ei/game/algo/AStar.java @@ -27,7 +27,7 @@ public class AStar{ } public List startSearch(Vector2i start, Vector2i goal){ - map[goal.getX()][goal.getY()].setBlocked(false); + //map[goal.getX()][goal.getY()].setBlocked(false); return pathfinder.findPath(map[start.getX()][start.getY()], map[goal.getX()][goal.getY()]); } diff --git a/src/ei/game/algo/AStarPathfinder.java b/src/ei/game/algo/AStarPathfinder.java index 24a9fe1..10bfe33 100644 --- a/src/ei/game/algo/AStarPathfinder.java +++ b/src/ei/game/algo/AStarPathfinder.java @@ -47,11 +47,12 @@ public class AStarPathfinder{ start.costFromStart = 0; open.add(start); + AStarNode node = null; // Go through all the items in the open storage. int order = 0; // defines the order of which the nodes were visited (used in gui visuals) while (!open.isEmpty()) { // Let's retrieve the first item from the storage. - AStarNode node = (AStarNode) open.removeFirst(); + node = (AStarNode) open.removeFirst(); node.setVisited(true); node.setVisitOrder(order++); @@ -96,7 +97,8 @@ public class AStarPathfinder{ } } - return null; + //return null; + return constructPath(node); } diff --git a/src/ei/game/input/InGameMouseInput.java b/src/ei/game/input/InGameMouseInput.java index 9db670c..2867e9f 100644 --- a/src/ei/game/input/InGameMouseInput.java +++ b/src/ei/game/input/InGameMouseInput.java @@ -98,7 +98,10 @@ public class InGameMouseInput extends MouseInput{ } } else{ - if(oldMouseOver != null)oldMouseOver.setMouseOver(false); + if(oldMouseOver != null){ + oldMouseOver.setMouseOver(false); + oldMouseOver = null; + } } } } diff --git a/src/ei/game/scene/units/Unit.java b/src/ei/game/scene/units/Unit.java index 2718729..26f5e2a 100644 --- a/src/ei/game/scene/units/Unit.java +++ b/src/ei/game/scene/units/Unit.java @@ -3,7 +3,6 @@ package ei.game.scene.units; import java.util.LinkedList; -import ei.engine.effects.Particles; import ei.engine.math.Vector2f; import ei.engine.math.Vector2i; import ei.engine.math.Vector3f; @@ -209,13 +208,14 @@ public abstract class Unit extends GameEntity{ unitNode.getLocation().add(0f, -getVelocity(), 0f); } - if(attack != null && getWeapon(new Vector2f(unitNode.getLocation().getX(), unitNode.getLocation().getY())) - .onRange(new Vector2f(attack.getNode().getLocation().getX(), attack.getNode().getLocation().getY()))){ - moveTo = null; - } else if(Math.abs(moveTo.getX() - unitNode.getLocation().getX()) < getVelocity()+1 && Math.abs(moveTo.getY() - unitNode.getLocation().getY())< getVelocity()+1 ){ - if(path != null && !path.isEmpty()){ + + if(attack != null && getWeapon(new Vector2f(unitNode.getLocation().getX(), unitNode.getLocation().getY())) + .onRange(new Vector2f(attack.getNode().getLocation().getX(), attack.getNode().getLocation().getY()))){ + moveTo = null; + } + else if(path != null && !path.isEmpty()){ AStarNode temp = path.poll(); if(InGameState.getMap().isPosEmpty(temp.getX(), temp.getY())){ oldVect = new Vector2i((int)moveTo.getX(), (int)moveTo.getY());