I didn't know why it didn't remove the Boss1 Object.
This is the code of the Mans:
this is the code of myWorld:
In Boss1 I didn't write anything. The Boss1 is an Object which says "Boss1". Thief1 is the real Boss. Mans is the Person you can move. I hope you can help me.
import greenfoot.*;
public class Mans extends Actor
{
public int ySpeed;
public int groundLevel=489;
private boolean pressed;
public void act()
{
boolean onGround = false;
ySpeed++;
setLocation(getX(), getY()+ySpeed);
// at ground level
if (getY() > groundLevel)
{
ySpeed = 0;
setLocation(getX(), groundLevel);
onGround = true;
}
// hitting box
Actor object = getOneIntersectingObject(Objects.class);
if (object != null)
{
int yDir = (int)Math.signum(ySpeed);
setLocation(getX(), object.getY()-yDir*((object.getImage().getHeight()+getImage().getHeight())/2+1));
ySpeed = 0;
if (yDir > 0) onGround = true;
}
// jumping
if (onGround && Greenfoot.isKeyDown("up"))
{
ySpeed = -15;
}
// firing weapon
if (pressed == Greenfoot.isKeyDown("space"))
{
pressed = !pressed;
if (pressed) getWorld().addObject(new Weapons(), getX()+80, getY()-25);
}
//die
if (this.isAtEdge())
{ this.removeTouching(Objects.class);
this.setImage("Mans3.png");
this.setLocation(400, 400);
Greenfoot.playSound("game-over.wav");
Greenfoot.stop();
MyWorld m = (MyWorld) getWorld();
m.GameOver();
}
//get a Coin
if(this.isTouching(Coin.class))
{
this.removeTouching(Coin.class);
this.setLocation(400, 350);
Greenfoot.playSound("pop.wav");
}
//start Boss Battle
if(Greenfoot.isKeyDown("enter"))
{
this.removeTouching(Boss1.class);
MyWorld m = (MyWorld) getWorld();
m.Bos1();
}
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class MyWorld extends World
{
int started=0;
/**
* Constructor for objects of class MyWorld.
*
*/
public MyWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(800, 600, 1);
prepare();
spawnObjects();
spawnBoxes();
}
public void start()
{
started=1;
addObject(new spawner(), 0, 0);
addObject(new Score(), 400, 100);
}
public void Game1()
{
started = 0;
addObject(new Boss1(), 400, 300);
}
public void Bos1()
{
addObject(new Thief1(), 750, 489);
}
public void GameOver()
{
End end = new End();
addObject(end,400,250);
}
private void prepare()
{
Line line = new Line();
addObject(line,352,596);
line.setLocation(352,589);
Mans mans = new Mans();
addObject(mans,155,496);
mans.setLocation(400,489);
}
public void spawnObjects()
{
addObject(new Toutorial(), 400, 100);
}
int x;
public void spawnBoxes()
{
if (started==1)
{
x = Greenfoot.getRandomNumber(30);
if (x==0)
{
addObject(new Boxes(), 550, 550);
addObject(new Walls(), 650, 532);
addObject(new Walls(), 750, 532);
}
if (x==1)
{
addObject(new Boxes(), 750, 550);
}
if (x==2)
{
addObject(new Boxes(), 650, 550);
addObject(new Walls(), 750, 532);
}
if (x==3)
{
addObject(new BadBoxes(), 750, 550);
}
if (x==4)
{
addObject(new Boxes(), 550, 550);
addObject(new BadWalls(), 650, 532);
addObject(new BadWalls(), 750, 532);
}
if (x==5)
{
addObject(new BadBoxes(), 550, 550);
addObject(new BadWalls(), 650, 532);
addObject(new BadWalls(), 750, 532);
}
if (x==6)
{
addObject(new BadBoxes(), 550, 550);
addObject(new Walls(), 650, 532);
addObject(new Walls(), 750, 532);
}
if (x==7)
{
addObject(new BadBoxes(), 550, 550);
addObject(new BadWalls(), 650, 532);
addObject(new Walls(), 750, 532);
}
if (x==8)
{
addObject(new BadBoxes(), 550, 550);
addObject(new Walls(), 650, 532);
addObject(new BadWalls(), 750, 532);
}
if (x==9)
{
addObject(new Boxes(), 550, 550);
addObject(new BadWalls(), 650, 532);
addObject(new Walls(), 750, 532);
}
if (x==10)
{
addObject(new Boxes(), 550, 550);
addObject(new Walls(), 650, 532);
addObject(new BadWalls(), 750, 532);
}
if (x==11)
{
addObject(new BadBoxes(), 650, 550);
addObject(new BadWalls(), 750, 532);
}
if (x==12)
{
addObject(new BadBoxes(), 650, 550);
addObject(new Walls(), 750, 532);
}
if (x==13)
{
addObject(new Boxes(), 650, 550);
addObject(new BadWalls(), 750, 532);
}
if (x==14)
{
addObject(new Boxes(), 650, 550);
addObject(new Boxes(), 750, 550);
}
if (x==15)
{
addObject(new BadBoxes(), 650, 550);
addObject(new BadBoxes(), 750, 550);
}
if (x==16)
{
addObject(new BadBoxes(), 650, 550);
addObject(new Boxes(), 750, 550);
}
if (x==17)
{
addObject(new Boxes(), 650, 550);
addObject(new BadBoxes(), 750, 550);
}
if (x==18)
{
addObject(new Coin(), 750, 325);
}
if (x==19)
{
addObject(new Barrels(), 716,487);
}
if (x==20)
{
addObject(new Barrels(), 716,487);
addObject(new Barrels(), 716,319);
}
if (x==21)
{
addObject(new Barrels(), 714,490);
addObject(new Barrels(), 586,490);
addObject(new Barrels(), 619,322);
}
}
}
}

