diff --git a/src/ei/game/algo/AStar.java b/src/ei/game/algo/AStar.java index 5dee3e1..57c24f4 100644 --- a/src/ei/game/algo/AStar.java +++ b/src/ei/game/algo/AStar.java @@ -5,7 +5,6 @@ import java.util.List; import java.util.Random; import ei.engine.math.Vector2i; -import ei.game.algo.AStarNode2D.Heuristic; import ei.game.gamestate.InGameState; public class AStar{ @@ -43,13 +42,13 @@ public class AStar{ // Create the map. map = new AStarNode2D[width][hight]; for(int x = 0, nodeId = 0; width > x; x++) { + for(int y = 0; hight > y; y++, nodeId++) { map[x][y] = new AStarNode2D(x, y, nodeId); - + if(!InGameState.getMap().isPosEmpty(x, y)) { map[x][y].setBlocked(true); } - } } @@ -60,21 +59,21 @@ public class AStar{ List neighbours = new LinkedList(); if(y-1 >= 0) - neighbours.add(new AStarNeighbour(map[x][y-1], AStarNeighbour.Location.Adjacent)); // North. + neighbours.add(new AStarNeighbour(map[x][y-1], AStarNeighbour.Location.Diagonal)); // North. if(x+1 < width && y-1 > 0) - neighbours.add(new AStarNeighbour(map[x+1][y-1], AStarNeighbour.Location.Diagonal)); // North-East. + neighbours.add(new AStarNeighbour(map[x+1][y-1], AStarNeighbour.Location.Adjacent)); // North-East. if(x+1 < width) - neighbours.add(new AStarNeighbour(map[x+1][y], AStarNeighbour.Location.Adjacent)); // East. + neighbours.add(new AStarNeighbour(map[x+1][y], AStarNeighbour.Location.Diagonal)); // East. if(x+1 < width && y+1 < hight) - neighbours.add(new AStarNeighbour(map[x+1][y+1], AStarNeighbour.Location.Diagonal)); // South-East. + neighbours.add(new AStarNeighbour(map[x+1][y+1], AStarNeighbour.Location.Adjacent)); // South-East. if(y+1 < hight) - neighbours.add(new AStarNeighbour(map[x][y+1], AStarNeighbour.Location.Adjacent)); // South. + neighbours.add(new AStarNeighbour(map[x][y+1], AStarNeighbour.Location.Diagonal)); // South. if(x-1 >= 0 && y+1 < hight) - neighbours.add(new AStarNeighbour(map[x-1][y+1], AStarNeighbour.Location.Diagonal)); // South-West. + neighbours.add(new AStarNeighbour(map[x-1][y+1], AStarNeighbour.Location.Adjacent)); // South-West. if(x-1 >= 0) - neighbours.add(new AStarNeighbour(map[x-1][y], AStarNeighbour.Location.Adjacent)); // West. - - if(x-1 >= 0 && y-1 > 0) neighbours.add(new AStarNeighbour(map[x-1][y-1], AStarNeighbour.Location.Diagonal)); // North-West. + neighbours.add(new AStarNeighbour(map[x-1][y], AStarNeighbour.Location.Diagonal)); // West. + if(x-1 >= 0 && y-1 > 0) + neighbours.add(new AStarNeighbour(map[x-1][y-1], AStarNeighbour.Location.Adjacent)); // North-West. map[x][y].setNeighbours(neighbours); diff --git a/src/ei/game/algo/AStarNode2D.java b/src/ei/game/algo/AStarNode2D.java index e445453..a853ed8 100644 --- a/src/ei/game/algo/AStarNode2D.java +++ b/src/ei/game/algo/AStarNode2D.java @@ -9,7 +9,7 @@ import ei.game.algo.AStarNeighbour.Location; */ public class AStarNode2D extends AStarNode { protected final static float adjacentCost = 1; - protected final static float diagonalCost = (float)Math.sqrt(2)*adjacentCost+1; + protected final static float diagonalCost = (float)Math.sqrt(2)*adjacentCost; protected final static float tieBreaker = adjacentCost/(1024f/1024f); public enum Heuristic { diff --git a/src/ei/game/gamestate/InGameState.java b/src/ei/game/gamestate/InGameState.java index 8035080..67c89db 100644 --- a/src/ei/game/gamestate/InGameState.java +++ b/src/ei/game/gamestate/InGameState.java @@ -23,9 +23,14 @@ public class InGameState extends GameState{ super.getInput().addInput(mouse); HumanPlayer player = new HumanPlayer(); - player.addUnit(new Tank()); - player.addUnit(new Tank(1,0)); + Tank t1 = new Tank(); + t1.setLife(10); + player.addUnit(t1); + Tank t2 = new Tank(1,0); + t2.setLife(30); + player.addUnit(t2); player.addUnit(new Tank(2,0)); + rootNode.add(player.getNode()); PlayerHandler.getInstance().addPlayer(player); } diff --git a/src/ei/game/scene/GameEntity.java b/src/ei/game/scene/GameEntity.java index 44a093f..c244370 100644 --- a/src/ei/game/scene/GameEntity.java +++ b/src/ei/game/scene/GameEntity.java @@ -31,6 +31,7 @@ public abstract class GameEntity{ if(life > max_life){ max_life = life; } + if(getSelection() != null)getSelection().setValue(l); } /** diff --git a/src/ei/game/scene/SelectBox.java b/src/ei/game/scene/SelectBox.java index 97a70fe..2451009 100644 --- a/src/ei/game/scene/SelectBox.java +++ b/src/ei/game/scene/SelectBox.java @@ -64,6 +64,17 @@ public class SelectBox { * @param v The value of the health bar */ public void setValue(int v){ - value.setSize(new Vector2f((v/max)*width,height)); + value.setSize(new Vector2f(((float)v/max)*width,height));//(v/max)*width + value.setLocation(new Vector2f(-width/2+(((float)v/max)*width)/2,-width/2+height/2)); + + if(((float)v/max) < 0.15f){ + value.getTexture().setColor(new Vector4f(1.0f, 0f, 0f, 0.6f)); + } + else if(((float)v/max) < 0.50f){ + value.getTexture().setColor(new Vector4f(1.0f, .95f, 0, 0.6f)); + } + else{ + value.getTexture().setColor(new Vector4f(0.3f, 1.0f, 0.3f, 0.6f)); + } } } diff --git a/src/ei/game/scene/units/Unit.java b/src/ei/game/scene/units/Unit.java index cf909cf..5baf744 100644 --- a/src/ei/game/scene/units/Unit.java +++ b/src/ei/game/scene/units/Unit.java @@ -97,17 +97,13 @@ public abstract class Unit extends GameEntity{ * Updating the unit */ public void update() { - getSelection().setValue(getLife()); if(moveTo != null) { Vector2i moveVect = new Vector2i((int)moveTo.getX(),(int)moveTo.getY()); //Vector2i currentVect = new Vector2i((int)unitNode.getLocation().getX(), (int)unitNode.getLocation().getY()); - int moveXminus = moveVect.getX()-oldVect.getX(); int moveYminus = moveVect.getY()-oldVect.getY(); - System.out.println("moveVect: "+moveVect); - //System.out.println("currentVect: "+currentVect); float divideY = (moveVect.getY()+1)/(oldVect.getY()+1); float divideX = (moveVect.getX()+1)/(oldVect.getX()+1);