Fixed selection bug and changed the astar a bit but its still not right
This commit is contained in:
parent
bdb12e2000
commit
397fb7ebd0
4 changed files with 15 additions and 10 deletions
|
|
@ -27,7 +27,7 @@ public class AStar{
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<AStarNode> startSearch(Vector2i start, Vector2i goal){
|
public List<AStarNode> 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()]);
|
return pathfinder.findPath(map[start.getX()][start.getY()], map[goal.getX()][goal.getY()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,11 +47,12 @@ public class AStarPathfinder{
|
||||||
start.costFromStart = 0;
|
start.costFromStart = 0;
|
||||||
open.add(start);
|
open.add(start);
|
||||||
|
|
||||||
|
AStarNode node = null;
|
||||||
// Go through all the items in the open storage.
|
// 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)
|
int order = 0; // defines the order of which the nodes were visited (used in gui visuals)
|
||||||
while (!open.isEmpty()) {
|
while (!open.isEmpty()) {
|
||||||
// Let's retrieve the first item from the storage.
|
// Let's retrieve the first item from the storage.
|
||||||
AStarNode node = (AStarNode) open.removeFirst();
|
node = (AStarNode) open.removeFirst();
|
||||||
node.setVisited(true);
|
node.setVisited(true);
|
||||||
node.setVisitOrder(order++);
|
node.setVisitOrder(order++);
|
||||||
|
|
||||||
|
|
@ -96,7 +97,8 @@ public class AStarPathfinder{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
//return null;
|
||||||
|
return constructPath(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,10 @@ public class InGameMouseInput extends MouseInput{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if(oldMouseOver != null)oldMouseOver.setMouseOver(false);
|
if(oldMouseOver != null){
|
||||||
|
oldMouseOver.setMouseOver(false);
|
||||||
|
oldMouseOver = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package ei.game.scene.units;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
import ei.engine.effects.Particles;
|
|
||||||
import ei.engine.math.Vector2f;
|
import ei.engine.math.Vector2f;
|
||||||
import ei.engine.math.Vector2i;
|
import ei.engine.math.Vector2i;
|
||||||
import ei.engine.math.Vector3f;
|
import ei.engine.math.Vector3f;
|
||||||
|
|
@ -209,13 +208,14 @@ public abstract class Unit extends GameEntity{
|
||||||
unitNode.getLocation().add(0f, -getVelocity(), 0f);
|
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
|
else if(Math.abs(moveTo.getX() - unitNode.getLocation().getX()) < getVelocity()+1
|
||||||
&& Math.abs(moveTo.getY() - unitNode.getLocation().getY())< 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();
|
AStarNode temp = path.poll();
|
||||||
if(InGameState.getMap().isPosEmpty(temp.getX(), temp.getY())){
|
if(InGameState.getMap().isPosEmpty(temp.getX(), temp.getY())){
|
||||||
oldVect = new Vector2i((int)moveTo.getX(), (int)moveTo.getY());
|
oldVect = new Vector2i((int)moveTo.getX(), (int)moveTo.getY());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue