Hello Everybody,
I just want to shoot a Fireball in the direction, the actor faces to.
My code is probably wrong and I dont know how to fix it.
If I Run the Program Java says "java.lang.NullPointerException" on the "if-line" on the second code in line xx (considering which Direction it is)
Fireball(engl.) = Feuerball
Player(engl.) = Spieler
I already tested out something with " != null " but it didnt works.
Help me!
public void checkArrow(){ // in class "Player"
if(Greenfoot.isKeyDown("space")) {
if (this.getRotation() == 0){
getWorld().addObject(new Pfeil(), getX()+1, getY());
}
if (this.getRotation() == 90){
getWorld().addObject(new Pfeil(), getX(), getY()+1);
}
if (this.getRotation() == 180){
getWorld().addObject(new Pfeil(), getX()-1, getY());
}
if (this.getRotation() == 270){
getWorld().addObject(new Pfeil(), getX(), getY()-1);
}
if (this.getRotation() == 315 % 360){
getWorld().addObject(new Pfeil(), getX()+1, getY()-1);
}
if (this.getRotation() == 45 % 360){
getWorld().addObject(new Pfeil(), getX()+1, getY()+1);
}
if (this.getRotation() == 135 % 360){
getWorld().addObject(new Pfeil(), getX()-1, getY()+1);
}
if (this.getRotation() == 225 % 360){
getWorld().addObject(new Pfeil(), getX()-1, getY()-1);
}
}
}public void shootingDirection(){ // in class "Fireball"
Spieler aktSpieler = (Spieler) this.getOneObjectAtOffset(getX(),getY(),Spieler.class);
if (aktSpieler.getRotation() == 0){
setLocation(getX() + speed, getY());
}
if (aktSpieler.getRotation() == 90){
this.setLocation(getX(), getY() + speed);
}
if (aktSpieler.getRotation() == 180){
this.setLocation(getX() - speed, getY());
}
if (aktSpieler.getRotation() == 270){
this.setLocation(getX(), getY() - speed);
}
if (aktSpieler.getRotation() == 315 % 360){
this.setLocation(getX() + speed, getY() - speed);
}
if (aktSpieler.getRotation() == 45 % 360){
this.setLocation(getX() + speed, getY() + speed);
}
if (aktSpieler.getRotation() == 135 % 360){
this.setLocation(getX() - speed, getY() + speed);
}
if (aktSpieler.getRotation() == 225 % 360){
this.setLocation(getX() - speed, getY() - speed);
}
}
