My code for Sonnekind:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Sonnekind here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Sonnekind extends Actor
{
private int energy = 30;
private int Teletubbieseaten = 0;
private int checkNextLevel;
private GreenfootImage Image3;
private GreenfootImage Image4;
private int Teletubby1;
public Sonnekind()
{
Image3 = new GreenfootImage("sbkklein1.png");
Image4 = new GreenfootImage("sbkklein2.png");
setImage(Image3);
}
public void switchImage()
{
if (getImage() == Image3)
{
setImage(Image4);
}
else
{
setImage(Image3);
}
}
public void act()
{
if (Greenfoot.isKeyDown("left"))
{
setRotation(180);
bewegen();
}
if (Greenfoot.isKeyDown("right"))
{
setRotation(0);
bewegen();
}
if (Greenfoot.isKeyDown("up"))
{
setRotation(270);
bewegen();
}
if (Greenfoot.isKeyDown("down"))
{
setRotation(90);
bewegen();
}
Actor Teletubby1;
Teletubby1 = getOneObjectAtOffset(0, 0, Teletubby1.class);
if (Teletubby1 !=null)
{
eatTeletubby1();
}
Actor Teletubby2;
Teletubby2 = getOneObjectAtOffset(0, 0, Teletubby2.class);
if (Teletubby2 !=null)
{
eatTeletubby2();
}
switchImage();
NextWorld();
}
public void eatTeletubby1()
{
Actor Teletubby1 = this.getOneObjectAtOffset(0, 0, Teletubby1.class);
if(Teletubby1 != null)
{ Teletubbieseaten = Teletubbieseaten + 1;
Greenfoot.playSound("winke.mp3");
energy = energy + 10;
getWorld().removeObject(Teletubby1);
((Teletubbieswelt)getWorld()).Teletubby1Hinzufügen() ;
}
}
public void eatTeletubby2()
{
Actor Teletubby2 = this.getOneObjectAtOffset(0, 0, Teletubby2.class);
if(Teletubby2 != null)
{ Teletubbieseaten = Teletubbieseaten + 1;
Greenfoot.playSound("winke.mp3");
energy = energy + 10;
getWorld().removeObject(Teletubby2);
((Teletubbieswelt2)getWorld()).Teletubby2Hinzufügen() ;
}
}
public void bewegen()
{
if(energy >=1)
{
move(1);
energy = energy - 1;
}
else
{
((Teletubbieswelt)getWorld()).removeObjekte() ;
}
}
public int getEnergy()
{
return energy;
}
private void NextWorld()
{
if (energy >= 40)
{
Teletubbieswelt2 ttw2 = new Teletubbieswelt2();
Greenfoot.setWorld(ttw2);
}
}
}
my code for Teletubby1
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Teletubby1 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Teletubby1 extends Actor
{
private GreenfootImage Image1;
private GreenfootImage Image2;
private int checkNextLevel;
private int energy = 30;
public Teletubby1()
{
Image1 = new GreenfootImage("po1klein.png");
Image2 = new GreenfootImage("po2klein.png");
setImage(Image1);
}
/**
* Act - do whatever the Teletubby1 wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
switchImage();
moveAround();
NextWorld();
}
public void switchImage()
{
if (getImage() == Image1)
{
setImage(Image2);
}
else
{
setImage(Image1);
}
}
public void moveAround()
{
move(1);
if (getX() <=5 || getX() >= getWorld().getWidth() -5)
{
turn(75);
}
if (getY() <=5 || getY() >= getWorld().getHeight() -5)
{
turn(75);
}
}
private void NextWorld()
{
if (energy >= 40)
{
Teletubbieswelt2 ttw2 = new Teletubbieswelt2();
Greenfoot.setWorld(ttw2);
}
}
}
