I'm trying to make a ant simulation. I have some code that add's leaves for the ants too eat. but it just pauses the program. How can I add leaves were the mouse is? Here is my code:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Ant_1 here. * * @author (your name) * @version (a version number or a date) */ public class Ant_1 extends Actor { /** * Act - do whatever the Ant_1 wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { move(3); int Food = 100; World world; world = getWorld(); Actor ant_food; ant_food = getOneObjectAtOffset(0, 0, ant_food.class); int mouseX = getX(); int mouseY = getY(); if (Greenfoot.getRandomNumber(100) < 10) { turn(Greenfoot.getRandomNumber(90) - 45); } if (getX() <= 5 || getX() >= getWorld().getWidth() - 5) { turn(180); } if (getY() <= 5 || getY() >= getWorld().getHeight() - 5) { turn(180); } if (Greenfoot.mouseClicked(world)) { world.addObject(ant_food, mouseX, mouseY ); } if ( ant_food != null) { world.removeObject(ant_food); Food ++; } } }