No syntax error*
I am trying to spawn an actor at the right edge of a 780x360 world 20% of the time or so and thought I was using a method that would work, but nothing spawns no matter how long i run the scenario. I am using a custom method written in my world code and called after the prepare method in the World act method. What am I doing wrong? This is my World 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
{
/**
* Constructor for objects of class MyWorld.
*
*/
public MyWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(780, 360, 1, false);
prepare();
spawnPuffer();
}
/**
* Prepare the world for the start of the program.
* That is: create the initial objects and add them to the world.
*/
private void prepare()
{
// lines for adding the ground as the world scrolls
Actor sand = new Sand();
addObject(sand, 0, getHeight()-sand.getImage().getHeight()/2);
addObject(new Sand(), sand.getImage().getWidth(), sand.getY());
// code for adding big coral
BigCoral bigcoral = new BigCoral();
addObject(bigcoral,141,267);
bigcoral.setLocation(141,291);
bigcoral.setLocation(128,303);
BigCoral bigcoral2 = new BigCoral();
addObject(bigcoral2,692,262);
bigcoral2.setLocation(710,304);
BigCoral bigcoral3 = new BigCoral();
addObject(bigcoral3,430,261);
bigcoral3.setLocation(414,275);
bigcoral2.setLocation(710,309);
bigcoral.setLocation(101,294);
// code for adding little coral
LittleCoral littlecoral = new LittleCoral();
addObject(littlecoral,589,308);
LittleCoral littlecoral2 = new LittleCoral();
addObject(littlecoral2,327,314);
LittleCoral littlecoral3 = new LittleCoral();
addObject(littlecoral3,197,314);
LittleCoral littlecoral4 = new LittleCoral();
addObject(littlecoral4,37,312);
LittleCoral littlecoral5 = new LittleCoral();
addObject(littlecoral5,517,311);
LittleCoral littlecoral6 = new LittleCoral();
addObject(littlecoral6,779,324);
Goldfish goldfish = new Goldfish();
addObject(goldfish,72,153);
}
/**
* Method to spawn Puffer at right edge at a random Y coordinate 50% of the time
*/
public void spawnPuffer()
{
if(Greenfoot.getRandomNumber(100) <20)
{
Puffer puffer = new Puffer();
addObject(new Puffer(),765,(Greenfoot.getRandomNumber(360)));
}
}
}
