Alright, before I write anything I want to make clear I am really new to programming, or kind of new. So i started out greenfoot and made a small game with a Lobster eating babies. I wanted to add an enemy, so I added an Ant. I want the ant to remove the Lobster when he touches it. The player plays as the Lobster. I tried this code but it did not work.
Thats my ant. Look at the last paragraph and you will understand what i am trying to do. I used the same method as when I made the lobster eat babies.
Thanks for any help, Fulman.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class ant here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class ant extends Actor
{
/**
* Act - do whatever the ant wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
moveAround();
}
public void moveAround()
{
move(3);
if (Greenfoot.getRandomNumber(100) < 10)
{
turn(Greenfoot.getRandomNumber(90) - 45);
}
}
public void eat()
{
Actor Lobster;
Lobster = getOneObjectAtOffset(0, 0, Lobster.class);
if(Lobster != null)
{
World world;
world = getWorld();
world.removeObject(Lobster);
Greenfoot.playSound("eating.wav");
}
}
}