There was no syntax errors and I tried to compile it again, it didn't work. I tried to create new world, that didn't work. Also, I restarted it, no luck :(. Help!
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class TowerDefenceWorld here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class TowerDefenseWorld extends World
{
int level=0;
/**
* Constructor for objects of class TowerDefenceWorld.
*
*/
public TowerDefenseWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 600, 1, false);
prepare();
}
public void level()
{
if(level==0)
{
GreenfootImage background = getBackground();
setBackground("bluerock.jpg");
background.fill();
}
}
/**
* Prepare the world for the start of the program. That is: create the initial
* objects and add them to the world.
*/
int UL=0;
int MUL=0;
int SL=0;
int TSL=0;
private void prepare()
{
while(UL<18)
{
Tile1 tile1 = new Tile1();
addObject(tile1, 105, UL*30+90);
UL=UL+1;
}
while(MUL<15)
{
Tile1 tile1 = new Tile1();
addObject(tile1, 225, MUL*30+90);
Tile1 tile140 = new Tile1();
addObject(tile140, 315, MUL*30+90);
MUL=MUL+1;
}
while(SL<4)
{
Tile1 tile119 = new Tile1();
addObject(tile119, SL*30+135, 90);
Tile1 tile130 = new Tile1();
addObject(tile130, SL*30+375, 90);
SL=SL+1;
}
while(TSL<3)
{
Tile1 tile139 = new Tile1();
addObject(tile139, SL*30+225, 510);
TSL=TSL+1;
}
}
}
As Davin says, there may be a bug in the Tile1 constructor. But also: you do try to add one object just out side the world (though I think you should see an exception thrown if that was the problem). When UL reaches 17, you'll try and add an object with Y coordinate being UL*30+90, which is 17*30+90, which is 600. Since your world is 600 high, the Y coordinates stretch from 0 to 599, so 600 is actually just outside the world. You'll need to adjust your formula slightly.
And finally: in your last while-loop you use SL to calculate the X position, I suspect you wanted TSL there instead. But that doesn't relate to this issue.
tylers, exact same problem = exact same solution :p
... but please start a new discussion to post your code to avoid getting things mixed up in this one.