danpost wrote...
Ostarius wrote...
Danpost you here?((Boss)boss).loseLife(1);
((Boss)boss).loseLife(1);
if (getObjects(DonkeyKong.class).isEmpty() && getObjects(YouLost.class).isEmpty())
java.lang.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed. at greenfoot.Actor.failIfNotInWorld(Actor.java:711) at greenfoot.Actor.getOneObjectAtOffset(Actor.java:913) at DonkeyKong.onGround(DonkeyKong.java:105) at DonkeyKong.act(DonkeyKong.java:33) at greenfoot.core.Simulation.actActor(Simulation.java:604) at greenfoot.core.Simulation.runOneLoop(Simulation.java:562) at greenfoot.core.Simulation.runContent(Simulation.java:221) at greenfoot.core.Simulation.run(Simulation.java:211)
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class DonkeyKong here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class DonkeyKong extends Animal
{
/**
* Act - do whatever the DonkeyKong wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
private int speed = 5;
private int vSpeed = 5;
private boolean spaceDown;
private int timer = 0;
public static int score = 0;
private GreenfootImage left = new GreenfootImage("DKleft.png");
private GreenfootImage right = new GreenfootImage("DKright.png");
private GreenfootImage up = new GreenfootImage("DKjumping.png");
public DonkeyKong()
{
this.setImage(right);
}
public void act()
{
this.controls();
this.moveVertically();
this.onGround();
this.setLocation(getX(), getY()+vSpeed);
this.touchingBricks();
this.score();
this.brickFix();
this.atWorldEdge();
this.changeWorld();
//if (getOneIntersectingObject(Bricks.class) != null) move(-speed);
//if (getOneIntersectingObject(Bricks.class) != null) move(+speed);
//if (getOneIntersectingObject(Blocks.class) != null) move(-speed);
//if (getOneIntersectingObject(Blocks.class) != null) move(+speed);
}
public void changeWorld()
{
World world = null;
if (getX() == getWorld().getWidth()-1)
{
if (getWorld() instanceof MyWorld) world = new MyWorld2();
else if (getWorld() instanceof MyWorld2) world = new MyWorld3();
else if (getWorld() instanceof MyWorld3) world = new MyWorld4();
else if (getWorld() instanceof MyWorld4) world = new MyWorld5();
else if (getWorld() instanceof MyWorld5) world = new MyWorld6();
else if (getWorld() instanceof MyWorld6) world = new MyWorld7();
else if (getWorld() instanceof MyWorld7) world = new MyWorld8();
Greenfoot.setWorld(world);
}
}
public void controls()
{
if (Greenfoot.isKeyDown("right"))
{
this.setImage(right);
this.move(speed);
}
if (Greenfoot.isKeyDown("left"))
{
this.setImage(left);
this.move(-speed);
}
Actor bullet = new Weapons();
if (getWorld() instanceof MyWorld8) bullet = new DkBoss();
if (!spaceDown && Greenfoot.isKeyDown("space"))
{
spaceDown = true;
getWorld().addObject(bullet, getX() + 60, getY() - 10);
if (this.getImage() == left) bullet.setRotation(180);
else if (this.getImage() == up) bullet.setRotation(270);
}
if (spaceDown && !Greenfoot.isKeyDown("space"))
{
spaceDown = false;
}
if (this.isTouching(Enemies.class))
{
getWorld().removeObject(this);
}
}
public boolean onGround()
{
int height = getImage().getHeight();
Actor ground = getOneObjectAtOffset(5, height/2 + 5, Bricks.class);
return ground != null;
}
public void touchingBricks()
{
if (!getIntersectingObjects(Bricks.class).isEmpty())
{
this.setLocation(getX(), getY()-5);
//this.setImage("DKright.png");
}
}
public void moveVertically()
{
if( Greenfoot.isKeyDown("up"))
{
this.setImage(up);
this.setLocation(getX(), getY()-20);
}
}
public void score()
{
if (this.isTouching(Blocks.class))
{
this.score++;
}
}
public void brickFix()
{
if (isTouching(Bricks.class) && (getImage().equals(right)))
{
move(-speed);
}
if (isTouching(Bricks.class) && (getImage().equals(left)))
{
move(speed);
}
if (isTouching(Bricks.class) && (getImage().equals(up)))
{
this.setLocation(getX(), getY()+25);
}
}
}
if (getWorld() == null) return;