Hi,
i´m making a greenfoot game for school. The actors have to eat objects, if they ate enough they win the game.
I won´t the actor woh is controlled by the KI to try to go automatically to the objects, it should eat.
Thank you!
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Biene here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class SchweinchenBopps extends Troll
{
private int timer = 0;
private Counter2 counter2;
private int stunTimer;
public SchweinchenBopps (Counter2 pointCounter2)
{
counter2 = pointCounter2;
}
public void act()
{
if (stunTimer > 0)
{
stunTimer--;
return; // this forces an immediate exit from the method so no further code within the method is executed
}
checkKeypress();
lookForRobbe();
shoot();
lookForBulletH();
if (getY() < 80) setLocation(getX(), 80);
}
public void lookForBulletH ()
{
if ( canSee(BulletH.class))
stunTimer = 250;
}
private void checkKeypress()
{
if (Greenfoot.isKeyDown("left"))
{
turn(-4);
}
if (Greenfoot.isKeyDown("right"))
{
turn(4);
}
if (Greenfoot.isKeyDown("up"))
{
move(4);
}
if (Greenfoot.isKeyDown("down"))
{
move(-4);
}
}
public void lookForRobbe ()
{
if ( canSee(Robbe.class) )
{
eat(Robbe.class);
counter2.add(5);
}
}
public void shoot ()
{
if(timer>0)timer--;
if(timer==0 && Greenfoot.isKeyDown("space"))
{
BulletS bullets= new BulletS();
getWorld().addObject(bullets, getX()+25, getY());
timer=60;
bullets.setRotation(getRotation());
}
}
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Biene here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class SharkEins extends Troll
{
private int RobbenEaten;
private int timer=0;
public void act()
{
move();
turnAtEdge();
randomTurn();
shoot();
lookForRobbe();
}
public void move()
{
move (5);
}
public void lookForRobbe ()
{
if ( canSee(Robbe.class) )
{
eat(Robbe.class);
}
}
public void shoot ()
{
if(timer>0)timer--;
if(timer==0)
{
BulletH bulleth= new BulletH();
getWorld().addObject(bulleth, getX()+25, getY());
timer=60;
bulleth.setRotation(getRotation());
}
}
public void randomTurn()
{
if ( Greenfoot.getRandomNumber(100) < 10 )
{
turn( Greenfoot.getRandomNumber(40)-20 );
}
}
public void turnAtEdge()
{
if (atWorldEdge())
{
turn(7);
}
}
}