This commit is contained in:
Ziver Koc 2007-04-19 12:41:38 +00:00
parent a2d6b68992
commit 901206c108
2 changed files with 27 additions and 15 deletions

View file

@ -134,6 +134,17 @@ public class Map {
return mapNode; return mapNode;
} }
public Vector2i getPosIndex(GameEntity u){
for(int i=0; i<width ;i++){
for(int j=0; j<hight ;j++){
if(map[i][j] == u){
return new Vector2i(i,j);
}
}
}
return null;
}
/** /**
* Prints all the units on the map * Prints all the units on the map
* *

View file

@ -233,8 +233,11 @@ public abstract class Unit extends GameEntity{
} }
else if(attack != null){ else if(attack != null){
Weapon wepon = getWeapon(new Vector2f(unitNode.getLocation().getX(), unitNode.getLocation().getY())); Weapon wepon = getWeapon(new Vector2f(unitNode.getLocation().getX(), unitNode.getLocation().getY()));
Vector2i enamyPos = Map.getPosByPixel(attack.getNode().getLocation().getX(), attack.getNode().getLocation().getY()+1); Vector2i enamyPos = InGameState.getMap().getPosIndex(attack);
if(attack.getLife() <= 0 || enamyPos == null){
attack = null;
}
else{
if(wepon.onRange(new Vector2f(attack.getNode().getLocation().getX(), attack.getNode().getLocation().getY()))){ if(wepon.onRange(new Vector2f(attack.getNode().getLocation().getX(), attack.getNode().getLocation().getY()))){
if(weponTimer >= wepon.getReload()){ if(weponTimer >= wepon.getReload()){
wepon.launch(enamyPos); wepon.launch(enamyPos);
@ -248,8 +251,6 @@ public abstract class Unit extends GameEntity{
else{ else{
move(enamyPos.getX(),enamyPos.getY(), false); move(enamyPos.getX(),enamyPos.getY(), false);
} }
if(attack.getLife() <= 0){
attack = null;
} }
} }
} }