Fixed the astar algoritm and added some comments
This commit is contained in:
parent
c356ddf327
commit
e280861f2d
14 changed files with 776 additions and 1365 deletions
Binary file not shown.
|
|
@ -10,6 +10,7 @@ import ei.game.algo.AStarNeighbour.Location;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Árni Arent
|
* @author Árni Arent
|
||||||
|
* @author Ziver Koc
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class AStarPathfinder{
|
public class AStarPathfinder{
|
||||||
|
|
@ -17,6 +18,7 @@ public class AStarPathfinder{
|
||||||
protected LinkedList<AStarNode> closed;
|
protected LinkedList<AStarNode> closed;
|
||||||
private AStarNode start;
|
private AStarNode start;
|
||||||
private AStarNode goal;
|
private AStarNode goal;
|
||||||
|
private AStarNode closest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a Pathfinder.
|
* Constructs a Pathfinder.
|
||||||
|
|
@ -55,6 +57,10 @@ public class AStarPathfinder{
|
||||||
node = (AStarNode) open.removeFirst();
|
node = (AStarNode) open.removeFirst();
|
||||||
node.setVisited(true);
|
node.setVisited(true);
|
||||||
node.setVisitOrder(order++);
|
node.setVisitOrder(order++);
|
||||||
|
// calculates the nearest way to the destination
|
||||||
|
if(closest == null || closest.estimatedCostToGoal > node.estimatedCostToGoal){
|
||||||
|
closest = node;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if we found the goal.
|
// Check if we found the goal.
|
||||||
if (node == goal) {
|
if (node == goal) {
|
||||||
|
|
@ -96,9 +102,9 @@ public class AStarPathfinder{
|
||||||
closed.add(node);
|
closed.add(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
System.out.println("Path Not found!!");
|
||||||
//return null;
|
//return null;
|
||||||
return constructPath(node);
|
return constructPath(closest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,5 @@
|
||||||
package ei.game.gamestate;
|
package ei.game.gamestate;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
|
|
@ -12,7 +9,6 @@ import ei.engine.sound.SoundLoader;
|
||||||
import ei.engine.state.GameState;
|
import ei.engine.state.GameState;
|
||||||
import ei.engine.state.GameStateManager;
|
import ei.engine.state.GameStateManager;
|
||||||
import ei.engine.texture.TextureLoader;
|
import ei.engine.texture.TextureLoader;
|
||||||
import ei.engine.util.FileFinderHasher;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class handels the loading of the
|
* This class handels the loading of the
|
||||||
|
|
@ -21,12 +17,66 @@ import ei.engine.util.FileFinderHasher;
|
||||||
* @author Ziver
|
* @author Ziver
|
||||||
*/
|
*/
|
||||||
public class LoadingState extends GameState{
|
public class LoadingState extends GameState{
|
||||||
//The extensions of the files
|
//The files to load
|
||||||
private static final String[] TEXTURES = {
|
private static final String[] TEXTURES = {
|
||||||
"jpg","png","bmp"
|
"data/font.bmp",
|
||||||
|
"data/loadbar_back.png",
|
||||||
|
"data/loadbar_front.png",
|
||||||
|
"data/loadbar.png",
|
||||||
|
"data/logo.png",
|
||||||
|
"data/particle.bmp",
|
||||||
|
"data/splash.png",
|
||||||
|
"data/buildings/cc/cc_building.png",
|
||||||
|
"data/buildings/cc/cc_ground.png",
|
||||||
|
"data/buildings/cc/cc.png",
|
||||||
|
"data/hud/buildmenu.png",
|
||||||
|
"data/hud/money.png",
|
||||||
|
"data/map/Grass.png",
|
||||||
|
"data/map/redmud.jpg",
|
||||||
|
"data/map/sand.jpg",
|
||||||
|
"data/map/redstone/redstone0000.png",
|
||||||
|
"data/map/redstone/redstone0001.png",
|
||||||
|
"data/map/redstone/redstone0002.png",
|
||||||
|
"data/map/redstone/redstone0003.png",
|
||||||
|
"data/map/stone/stone0000.png",
|
||||||
|
"data/map/stone/stone0001.png",
|
||||||
|
"data/map/stone/stone0002.png",
|
||||||
|
"data/map/stone/stone0003.png",
|
||||||
|
"data/ui/apu_button_selected.png",
|
||||||
|
"data/ui/apu_button.png",
|
||||||
|
"data/ui/bomber_button_selected.png",
|
||||||
|
"data/ui/bomber_button.png",
|
||||||
|
"data/ui/tank_button_selected.png",
|
||||||
|
"data/ui/tank_button.png",
|
||||||
|
"data/units/apu/apu0000.png",
|
||||||
|
"data/units/apu/apu0001.png",
|
||||||
|
"data/units/apu/apu0002.png",
|
||||||
|
"data/units/bomber/bomber0000.png",
|
||||||
|
"data/units/bomber/bomber0001.png",
|
||||||
|
"data/units/bomber/bomber0002.png",
|
||||||
|
"data/units/bomber/bomber0003.png",
|
||||||
|
"data/units/tank/tank0000.png",
|
||||||
|
"data/units/tank/tank0001.png",
|
||||||
|
"data/units/tank/tank0002.png"
|
||||||
};
|
};
|
||||||
private static final String[] SOUNDS = {
|
private static final String[] SOUNDS = {
|
||||||
"wav","ogg"
|
"data/sounds/APUattack.wav",
|
||||||
|
"data/sounds/APUmove1.wav",
|
||||||
|
"data/sounds/APUmove2.wav",
|
||||||
|
"data/sounds/APUselect.wav",
|
||||||
|
"data/sounds/APUyes.wav",
|
||||||
|
"data/sounds/BOMBERattack.wav",
|
||||||
|
"data/sounds/BOMBERmove1.wav",
|
||||||
|
"data/sounds/BOMBERmove2.wav",
|
||||||
|
"data/sounds/BOMBERselect.wav",
|
||||||
|
"data/sounds/bomberweapon.wav",
|
||||||
|
"data/sounds/ei.ogg",
|
||||||
|
"data/sounds/machinegun.wav",
|
||||||
|
"data/sounds/TANKattack.wav",
|
||||||
|
"data/sounds/TANKmove1.wav",
|
||||||
|
"data/sounds/TANKmove2.wav",
|
||||||
|
"data/sounds/TANKselect.wav",
|
||||||
|
"data/sounds/tankweapon.wav"
|
||||||
};
|
};
|
||||||
// The things to load
|
// The things to load
|
||||||
private Queue<String> loadTextures;
|
private Queue<String> loadTextures;
|
||||||
|
|
@ -56,33 +106,13 @@ public class LoadingState extends GameState{
|
||||||
progress.setProgressTexture(new Sprite("Progress","data/loadbar.png"));
|
progress.setProgressTexture(new Sprite("Progress","data/loadbar.png"));
|
||||||
progress.setBackgroundTexture(new Sprite("progressBackground","data/loadbar_back.png"));
|
progress.setBackgroundTexture(new Sprite("progressBackground","data/loadbar_back.png"));
|
||||||
|
|
||||||
try {
|
for(int i=0; i<TEXTURES.length ;i++){
|
||||||
File dir = new File(getClass().getClassLoader().getResource("data/").toURI());
|
addTexture(TEXTURES[i]);
|
||||||
ArrayList<File> files = FileFinderHasher.Search(dir);
|
|
||||||
for(int i=0; i<files.size() ;i++){
|
|
||||||
String ext = files.get(i).getName();
|
|
||||||
ext = ext.substring(ext.lastIndexOf ('.')+1,ext.length());
|
|
||||||
|
|
||||||
if(contains(TEXTURES,ext)){
|
|
||||||
addTexture(files.get(i).getPath().substring(files.get(i).getPath().lastIndexOf("data"), files.get(i).getPath().length()));
|
|
||||||
}
|
}
|
||||||
else if(contains(SOUNDS,ext)){
|
for(int i=0; i<SOUNDS.length ;i++){
|
||||||
addSound(files.get(i).getPath().substring(files.get(i).getPath().lastIndexOf("data"), files.get(i).getPath().length()));
|
addSound(SOUNDS[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (URISyntaxException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean contains(String[] array, String search){
|
|
||||||
for(int i=0; i<array.length ;i++){
|
|
||||||
if(array[i].equals(search)){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a texture to be loaded
|
* Add a texture to be loaded
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@ public class SplashState extends GameState{
|
||||||
public SplashState(String name,String next) {
|
public SplashState(String name,String next) {
|
||||||
super(name);
|
super(name);
|
||||||
nextState = next;
|
nextState = next;
|
||||||
|
fadeInDone = false;
|
||||||
|
time = 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -27,9 +29,6 @@ public class SplashState extends GameState{
|
||||||
s.setLocation(new Vector2f(LWJGLGameWindow.getWidth()/2,LWJGLGameWindow.getHeight()/2));
|
s.setLocation(new Vector2f(LWJGLGameWindow.getWidth()/2,LWJGLGameWindow.getHeight()/2));
|
||||||
splash.setEntity(s);
|
splash.setEntity(s);
|
||||||
splash.fadeOut(false);
|
splash.fadeOut(false);
|
||||||
fadeInDone = false;
|
|
||||||
|
|
||||||
time = 200;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,11 @@ import ei.game.scene.SelectBox;
|
||||||
import ei.game.scene.weapons.Explotion;
|
import ei.game.scene.weapons.Explotion;
|
||||||
import ei.game.scene.weapons.WeaponHandler;
|
import ei.game.scene.weapons.WeaponHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jesper Lundin
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class CommandCenter extends Building{
|
public class CommandCenter extends Building{
|
||||||
private SelectBox selectionBox;
|
private SelectBox selectionBox;
|
||||||
private Sprite sprite;
|
private Sprite sprite;
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,11 @@ import ei.game.scene.weapons.MachineGun;
|
||||||
import ei.game.scene.weapons.Weapon;
|
import ei.game.scene.weapons.Weapon;
|
||||||
import ei.game.scene.weapons.WeaponHandler;
|
import ei.game.scene.weapons.WeaponHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jesper Lundin
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class APU extends Unit{
|
public class APU extends Unit{
|
||||||
private SelectBox selectionBox;
|
private SelectBox selectionBox;
|
||||||
private Sprite sprite;
|
private Sprite sprite;
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,11 @@ import ei.game.scene.weapons.Explotion;
|
||||||
import ei.game.scene.weapons.Weapon;
|
import ei.game.scene.weapons.Weapon;
|
||||||
import ei.game.scene.weapons.WeaponHandler;
|
import ei.game.scene.weapons.WeaponHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jesper Lundin
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class Bomber extends Unit{
|
public class Bomber extends Unit{
|
||||||
private SelectBox selectionBox;
|
private SelectBox selectionBox;
|
||||||
private Sprite sprite;
|
private Sprite sprite;
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,11 @@ import ei.game.scene.weapons.Explotion;
|
||||||
import ei.game.scene.weapons.Weapon;
|
import ei.game.scene.weapons.Weapon;
|
||||||
import ei.game.scene.weapons.WeaponHandler;
|
import ei.game.scene.weapons.WeaponHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jesper Lundin
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class Tank extends Unit{
|
public class Tank extends Unit{
|
||||||
private SelectBox selectionBox;
|
private SelectBox selectionBox;
|
||||||
private Sprite sprite;
|
private Sprite sprite;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,11 @@ import ei.engine.math.Vector2i;
|
||||||
import ei.game.gamestate.InGameState;
|
import ei.game.gamestate.InGameState;
|
||||||
import ei.game.scene.Map;
|
import ei.game.scene.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the bomber units webon
|
||||||
|
* @author Jesper Lundin
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class BomberWeapon extends Weapon{
|
public class BomberWeapon extends Weapon{
|
||||||
private Particles part;
|
private Particles part;
|
||||||
private boolean hit;
|
private boolean hit;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,10 @@ package ei.game.scene.weapons;
|
||||||
import ei.engine.effects.Particles;
|
import ei.engine.effects.Particles;
|
||||||
import ei.engine.math.Vector2f;
|
import ei.engine.math.Vector2f;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Jesper Lundin
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class CannonBall extends Weapon{
|
public class CannonBall extends Weapon{
|
||||||
|
|
||||||
public CannonBall(Vector2f startPos) {
|
public CannonBall(Vector2f startPos) {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,11 @@ package ei.game.scene.weapons;
|
||||||
import ei.engine.effects.Particles;
|
import ei.engine.effects.Particles;
|
||||||
import ei.engine.math.Vector2f;
|
import ei.engine.math.Vector2f;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Ziver
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class Explotion extends Weapon{
|
public class Explotion extends Weapon{
|
||||||
private Particles part;
|
private Particles part;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,11 @@ package ei.game.scene.weapons;
|
||||||
import ei.engine.effects.Particles;
|
import ei.engine.effects.Particles;
|
||||||
import ei.engine.math.Vector2f;
|
import ei.engine.math.Vector2f;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jesper Lundin
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class MachineGun extends Weapon{
|
public class MachineGun extends Weapon{
|
||||||
|
|
||||||
public MachineGun(Vector2f startPos) {
|
public MachineGun(Vector2f startPos) {
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,12 @@ import ei.engine.math.Vector2i;
|
||||||
import ei.engine.scene.Entity;
|
import ei.engine.scene.Entity;
|
||||||
import ei.game.gamestate.InGameState;
|
import ei.game.gamestate.InGameState;
|
||||||
import ei.game.scene.Map;
|
import ei.game.scene.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The weapon class.
|
* The weapon class.
|
||||||
* @author Jesper Lundin
|
* @author Jesper Lundin
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public abstract class Weapon {
|
public abstract class Weapon {
|
||||||
private int range;
|
private int range;
|
||||||
private int damage;
|
private int damage;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue