Help... I'm trying to make an ant mania like game but when the spiders move they move all at once and you can't even see it moving
This is in the myWorld class where it adds the spider
and here is the spider code
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class MyWorld here. * * @author (your name) * @version (a version number or a date) */ public class MyWorld extends World { int spiderX; int spiderY; /** * Constructor for objects of class MyWorld. * */ public MyWorld() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(600, 400, 1); Ant ant = new Ant(); addObject(ant,getWidth()/2,getHeight()/2); Food food = new Food(); addObject(food,Greenfoot.getRandomNumber(600),Greenfoot.getRandomNumber(400)); } public void addSpider() { if (Greenfoot.getRandomNumber(2) == 1) { spiderX = 0; spiderY = Greenfoot.getRandomNumber(400); } else { spiderX = Greenfoot.getRandomNumber(600); spiderY = 0; } Spider spider = new Spider(); addObject(new Spider(),spiderX,spiderY); } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Spider here. * * @author (your name) * @version (a version number or a date) */ public class Spider extends Actor { /** * Act - do whatever the Spider wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if (getX() == 0) { setRotation(0); for (int i = 0; i < 600; i++) { move(1); } setRotation(180); for (int i = 0; i < 600; i++) { move(1); } } else { if (getY() == 0) { setRotation(-90); for (int i = 0; i < 400; i++) { move(1); } setRotation(90); for (int i = 0; i < 400; i++) { move(1); } } } } }