Hi,
Whenever, my Player intersects Home (located at 9,9), I want to add ONE lizard to the world and change the location of the Home to (0,0) and when the Player intersects the Home at that point, another ONE lizard is added and the location of Home goes back to (9,9) and so on. Is there a way to do this? My code is shown below but does not work.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class Home extends Actor
{ private int k;
public Home()
{ GreenfootImage img = new GreenfootImage(40,40); setImage(img); } public void act() { Actor player = getOneIntersectingObject(Player.class); if(player!=null) { getWorld().addObject(new Lizard(),Greenfoot.getRandomNumber(10),Greenfoot.getRandomNumber(10)); setLocation(0,0); k=1; } if(k==1) { setLocation(9,9); } } }