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;
}
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
*

View file

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