Hey guys! I am currently writing a Combat class to handle well you guessed it Combat in my game.
[java]
public class Combat implements Runnable {
public Combat(Game game) {
this.game = game;
attackThread = new Thread(this);
init();
run = true;
}//end of Combat Constructor
/**
* init method
*/
private void init() {
random = new Random();
randomHit = new Random();
run = false;
playerDamage = 0;
enemyDamage = 0;
attackThread.start();
}//end of init
@SuppressWarnings(“static-access”)
public void run() {
while (run) {
handleAttack();
try {
attackThread.sleep(500);
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* handleAttack method
*/
private void handleAttack() {
if(game.getPlayerModel().getWorldTranslation().distance(game.getOgre().getWorldTranslation()) < 25) {
game.getPlayer().decrementHealth(random.nextInt(3));
}
}
[/java]
I get a nullpointer in handleAttack on the if statement. If i remove the if statement i take damage every 500 milliseconds which i want but i want in a certain distance to take damage however i get the null pointer.