Hallo,
getWorld().removeObjects(getWorld().getObjects(P1.class));
don´t work,
it don´t remove some of the P1.class
pls help.
I want to remove all objects from the class which are at the world.
this.getWorld().addObject(this,10, 10);
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Affe here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Affe extends GifActor
{
/**
* gehört noch zu GifActor
*/
public void addedToWorld(World world)
{
setImage("Actor.gif"); //You must use the setImage method and not just right click + setImage in the GUI.
}
/**
* Steuerung und Weltgeschwindigkeit
*/
public void act()
{
int punkte = 0;
Greenfoot.setSpeed(50); //Setzt Welt auf 50% Speed
super.act(); // Animation starten
if(Greenfoot.isKeyDown("d")) // d gedrückt nach rechts gehen
{
move(1);
}
if(Greenfoot.isKeyDown("a")) // a gedrückz nach links gehen
{
move(-1);
}
if(Greenfoot.isKeyDown("w")) // w gedrückt nach oben gehen
{
setLocation(getX(),getY() -1);
}
if(Greenfoot.isKeyDown("s")) // s gedrückt nach unten gehen
{
setLocation(getX(),getY() +1);
}
if(bananeAufFeld())
{
bananeAufnehmen();
punkte = punkte+1;
bananeSpawn();
}
if(falleAufFeld())
{
falleAufnehmen();
punkte = punkte-1;
}
if(punkte==1)
{
P1 p1 = new P1();
this.getWorld().addObject(p1, 10, 10);
this.getWorld().addObject(this,10, 10);
P1 p11 = new P1();
this.getWorld().addObject(p11, 10, 11);
this.getWorld().addObject(this,10, 11);
P1 p12 = new P1();
this.getWorld().addObject(p12, 10, 12);
this.getWorld().addObject(this,10, 12);
P1 p13 = new P1();
this.getWorld().addObject(p13, 10, 13);
this.getWorld().addObject(this,10, 13);
P1 p14 = new P1();
this.getWorld().addObject(p14, 10, 14);
this.getWorld().addObject(this,10, 14);
P1 p15 = new P1();
this.getWorld().addObject(p15, 10, 15);
this.getWorld().addObject(this,10, 15);
P1 p16 = new P1();
this.getWorld().addObject(p16, 10, 16);
this.getWorld().addObject(this,10, 16);
P1 p17 = new P1();
this.getWorld().addObject(p17, 11, 10);
this.getWorld().addObject(this,11, 10);
P1 p18 = new P1();
this.getWorld().addObject(p18, 12, 10);
this.getWorld().addObject(this,12, 10);
P1 p19 = new P1();
this.getWorld().addObject(p19, 13, 10);
this.getWorld().addObject(this,13, 10);
P1 p20 = new P1();
this.getWorld().addObject(p20, 14, 10);
this.getWorld().addObject(this,14, 10);
P1 p21 = new P1();
this.getWorld().addObject(p21, 14, 11);
this.getWorld().addObject(this,14, 11);
P1 p22 = new P1();
this.getWorld().addObject(p22, 14, 12);
this.getWorld().addObject(this,14, 12);
P1 p23 = new P1();
this.getWorld().addObject(p23, 14, 13);
this.getWorld().addObject(this,14, 13);
P1 p24 = new P1();
this.getWorld().addObject(p24, 14, 14);
this.getWorld().addObject(this,14, 14);
P1 p25 = new P1();
this.getWorld().addObject(p25, 14, 15);
this.getWorld().addObject(this,14, 16);
P1 p26 = new P1();
this.getWorld().addObject(p26, 14, 16);
this.getWorld().addObject(this,14, 16);
P1 p27 = new P1();
this.getWorld().addObject(p27, 13, 16);
this.getWorld().addObject(this,13, 16);
P1 p28 = new P1();
this.getWorld().addObject(p28, 12, 16);
this.getWorld().addObject(this,12, 16);
P1 p29 = new P1();
this.getWorld().addObject(p29, 11, 16);
this.getWorld().addObject(this,11, 16);
P1 p30 = new P1();
this.getWorld().addObject(p30, 11, 11);
this.getWorld().addObject(this,11, 11);
P1 p31 = new P1();
this.getWorld().addObject(p31, 11, 12);
this.getWorld().addObject(this,11, 12);
P1 p32 = new P1();
this.getWorld().addObject(p32, 11, 13);
this.getWorld().addObject(this,11, 13);
P1 p34 = new P1();
this.getWorld().addObject(p34, 11, 14);
this.getWorld().addObject(this,11, 14);
P1 p35 = new P1();
this.getWorld().addObject(p35, 11, 15);
this.getWorld().addObject(this,11, 15);
P1 p36 = new P1();
this.getWorld().addObject(p36, 12, 11);
this.getWorld().addObject(this,12, 11);
P1 p37 = new P1();
this.getWorld().addObject(p37, 12, 15);
this.getWorld().addObject(this,12, 15);
P1 p40 = new P1();
this.getWorld().addObject(p40, 13, 11);
this.getWorld().addObject(this,13, 11);
P1 p41 = new P1();
this.getWorld().addObject(p41, 13, 12);
this.getWorld().addObject(this,11, 12);
P1 p42 = new P1();
this.getWorld().addObject(p42, 13, 13);
this.getWorld().addObject(this,11, 13);
P1 p43 = new P1();
this.getWorld().addObject(p43, 13, 14);
this.getWorld().addObject(this,11, 14);
P1 p44 = new P1();
this.getWorld().addObject(p44, 13, 15);
this.getWorld().addObject(this,11, 15);
P2 i1 = new P2();
this.getWorld().addObject(i1, 12, 12);
this.getWorld().addObject(this,12, 12);
P2 i2 = new P2();
this.getWorld().addObject(i2, 12, 13);
this.getWorld().addObject(this,12, 13);
P2 i3 = new P2();
this.getWorld().addObject(i3, 12, 14);
this.getWorld().addObject(this,12, 14);
}
if(punkte==2)
{
getWorld().removeObjects(getWorld().getObjects(P1.class));
getWorld().removeObjects(getWorld().getObjects(P2.class));
}
if(jägerAufFeld())
{
Affe aktAffe = (Affe)this.getOneObjectAtOffset(0, 0, Affe.class);
if(aktAffe != null)
{
setLocation(65,40);
this.getWorld().removeObject(aktAffe);
setImage("GameOver.jpg");
}
}
}
} public boolean bananeAufFeld()
{
if (this.getOneObjectAtOffset(0, 0, Banane.class)!= null)
{
return true;
}
else
{
return false;
}
} public void bananeAufnehmen()
{
Banane aktBanane = (Banane)this.getOneObjectAtOffset(0, 0, Banane.class);
if(aktBanane != null)
{
this.getWorld().removeObject(aktBanane);
}
else
{
System.out.println("Hier ist keine Banane!");
}
}