I want to make rockets fall out of the sky randomly across the X axis but not on the Y axis but nothing spawns.
But it dosen't work here is what is on my Rocket class
public void spawnRocket()
{
if(counter == 20)
{
counter = 0;
addObject(new Rocket(), Greenfoot.getRandomNumber(getWidth()),0);
}
counter++;
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Rocket here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Rocket extends shotManager
{
private int frame = 1;
private int animationCounter = 0;
private int shootingSpeed = 8;
private int counter = 0;
private GreenfootImage Explosion1 = new GreenfootImage ("Explosion.png");
private GreenfootImage Explosion2 = new GreenfootImage ("Explosion2.png");
private GreenfootImage Explosion3 = new GreenfootImage ("Explosion3.png");
/**
* Act - do whatever the Rocket wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
setLocation(getX() + shootingSpeed, getY()+shootingSpeed);
stop();
}
public void stop()
{
if(!getIntersectingObjects(Grounds.class).isEmpty())
{
shootingSpeed=8;
}
else
{
shootingSpeed=0;
animateExplodes();
stopRemove();
}
}
public void stopRemove()
{
if(counter % 16==0)
{
getWorld().removeObject(this);
}
}
public void animateExplodes()
{
if(animationCounter % 4==0)
{
animateExplode();
}
}
public void animateExplode()
{
if(frame == 1)
{
setImage (Explosion1);
}
else if (frame==2)
{
setImage(Explosion2);
}
else if(frame ==3)
{
setImage(Explosion3);
frame = 1;
return;
}
frame++;
}
}
