hi,
can someone help me? i am trying to do a star wars game with an tie fighter. the tie fighter has to shoot the asteroids. but everytime when an asteroid is at edge the IllegalStateException fault shows up.
Code of asteroid class:
and the code of the tie fighter:
thanks
public class Asteroid extends Actor
{
int speed;
public Asteroid(){
speed = Greenfoot.getRandomNumber(5)+2;
}
public void act()
{
setLocation(getX()-speed, getY());
turn(speed);
if (getX()<=2){
getWorld().removeObject(this);
}
//if(isTouching(GruenerLaser.class)){
//getWorld().removeObject(this);
//}
if(isTouching(RoterLaser.class)){ // here is always the IllegalStateException problem
getWorld().removeObject(this);
}
else
if(isAtEdge()){
getWorld().removeObject(this);
}
}
}
public class Tie extends Actor
{
private int velocity = 4;
int delay=50;
GreenfootSound powerup = new GreenfootSound("powerup.mp3");
public void act()
{
if(Greenfoot.isKeyDown("w")){
//setRotation(270);
move(velocity);
}
if(Greenfoot.isKeyDown("a")){
turn(-velocity);
//move(2);
}
if(Greenfoot.isKeyDown("d")){
//setRotation(0);
turn(velocity);
}
if(delay==50){
if(Greenfoot.isKeyDown("space")){
getWorld().addObject(new RoterLaser(getRotation()), getX(), getY());
delay=0;
}
}
else{
delay = delay +1;
}
if (isTouching(Asteroid.class)){
getWorld().addObject(new GameOverScreen(), 450, 300);
getWorld().addObject(new KleineExplosion(),getX() ,getY() );
getWorld().removeObject(this);
Greenfoot.playSound("game over.mp3");
}
}
}
