So I am currently trying to make a gameover when my actor comes into contact with bullets, the alien and the edge but am running into an error:
non-static method addObject(greenfoot.Actor,int,int) cannot be referenced from a static context
non-static method getWidth(); cannot be referenced from a static context // non-static method getHeight(); cannot be referenced from a static context
heres the code:
game over class:
any ideas on what is causing this / how to fix it is much appreciated
public void checkCollision()
{
if(getOneIntersectingObject(Bullet.class) != null)
{
((World)getWorld()).removeObject(this);
GameOver gameover = new GameOver();
World.addObject(gameover, World.getWidth()/2, getHeight()/2);
}
if(getOneIntersectingObject(Alien.class) != null)
{
((World)getWorld()).removeObject(this);
((World)getWorld()).removeObject(this);
GameOver gameover = new GameOver();
World.addObject(gameover, World.getWidth()/2, getHeight()/2);
}
if (isAtEdge())
{
((World)getWorld()).removeObject(this);
((World)getWorld()).removeObject(this);
GameOver gameover = new GameOver();
World.addObject(gameover, World.getWidth()/2, getHeight()/2);
}
}public class GameOver extends Actor
{
public GameOver()
{
setImage(new GreenfootImage("Game Over", 50, Color.RED, Color.BLACK));
}
}

