i've been trying it in different places where I think it could be and it doesn't seem to be working
import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot)
/**
* A rocket that can be controlled by the arrowkeys: up, left, right.
* The gun is fired by hitting the 'space' key.
*
* @author Poul Henriksen
* @author Michael Kölling
*
* @version 2.0
*/
public class Rocket extends Mover
{
private int gunReloadTime; // The minimum delay between firing the gun.
private int reloadDelayCount; // How long ago we fired the gun the last time.
private Vector acceleration; // A vector used to accelerate when using booster.
private int shotsFired; // Number of shots fired.
private GreenfootImage rocket = new GreenfootImage("rocket.png");
private GreenfootImage rocketWithThrust = new GreenfootImage("rocketWithThrust.png");
/**
* Initialise this rocket.
*/
public Rocket()
{
gunReloadTime =5;
reloadDelayCount = 0;
acceleration = new Vector(0, 1); // used to accelerate when thrust is on
increaseSpeed(new Vector(0, 0)); // initially slowly drifting
shotsFired = 0;
}
/**
* Do what a rocket's gotta do. (Which is: mostly flying about, and turning,
* accelerating and shooting when the right keys are pressed.)
*/
public void act()
{
move();
checkKeys();
checkCollision();
reloadDelayCount++;
}
/**
* Return the number of shots fired from this rocket.
*/
public int getShotsFired()
{
return shotsFired;
}
/**
* Set the time needed for re-loading the rocket's gun. The shorter this time is,
* the faster the rocket can fire. The (initial) standard time is 20.
*/
public void setGunReloadTime(int reloadTime)
{
gunReloadTime = reloadTime;
}
/**
* Check whether we are colliding with an asteroid.
*/
private void checkCollision()
{
Asteroid a = (Asteroid) getOneIntersectingObject(Asteroid.class);
if (a != null) {
getWorld().addObject(new Explosion(), getX(), getY());
getWorld().removeObject(this);
}
}
/**
* Check whether there are any key pressed and react to them.
*/
private void checkKeys()
{
ignite(Greenfoot.isKeyDown("up"));
if(Greenfoot.isKeyDown("left")) {
turn(-8);
}
if(Greenfoot.isKeyDown("right")) {
turn(8);
}
if(Greenfoot.isKeyDown("space")) {
fire();
}
}
/**
* Should the rocket be ignited?
*/
private void ignite(boolean boosterOn)
{
if (boosterOn) {
setImage(rocketWithThrust);
acceleration.setDirection(getRotation());
increaseSpeed(acceleration);
}
else {
setImage(rocket);
}
}
/**
* Fire a bullet if the gun is ready.
*/
private void fire()
{
if (reloadDelayCount >= gunReloadTime) {
Bullet b = new Bullet(getMovement().copy(), getRotation());
getWorld().addObject(b, getX(), getY());
b.move();
shotsFired++;
reloadDelayCount = 0; // time since last shot fired
}
}
}import greenfoot.*;
/**
* Write a description of class Gohan here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Gohan extends Mover
{
private int gunReloadTime; // The minimum delay between firing the gun.
private int reloadDelayCount;
private int health = 900000; //its over 9000
private int shotsFired;
public void setHealth(int points) {
health += points;
}
public int getHealth() {
return health;
}
private GreenfootImage image1;
private GreenfootImage image2;
private GreenfootImage image3;
private GreenfootImage image4;
private GreenfootImage image5;
private GreenfootImage image6;
private GreenfootImage image7;
private GreenfootImage image8;
public Gohan()
{
image1 = new GreenfootImage("gohan.png");
image2 = new GreenfootImage("gohanstep.png");
image3 = new GreenfootImage("gohanstep2.png");
image4 = new GreenfootImage("powerattack.png");
image5 = new GreenfootImage("gohanpunch.png");
image6 = new GreenfootImage("Gohankick1.png");
image7 = new GreenfootImage("HealthBar.png");
image8 = new GreenfootImage("Gpowerup.png");
setImage(image1);
reloadDelayCount = 1000000;
}
/**
* Return the number of shots fired from this rocket.
*/
public int getShotsFired()
{
return shotsFired;
}
/**
* Set the time needed for re-loading the rocket's gun. The shorter this time is,
* the faster the rocket can fire. The (initial) standard time is 20.
*/
public void setGunReloadTime(int reloadTime)
{
gunReloadTime = reloadTime;
}
/**
* Act - do whatever the Gohan wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
checkKeypress ();
reloadDelayCount++;
}
public void checkKeypress()
{
if (Greenfoot.isKeyDown("left"))
{
move(-30);
if ( getImage() == image1 )
{ setImage(image2);
}
else
{if ( getImage() == image8 ){}
else{ setImage(image1);
}
}
}
if (Greenfoot.isKeyDown("right"))
{ move (30);
if ( getImage() == image1 )
{ setImage(image2);
}
else setImage(image1);
}
if (Greenfoot.isKeyDown("s"))
{
setImage(image3);
hitEnemy();
}
else if ( getImage() == image3)
{
setImage(image1);}
if (Greenfoot.isKeyDown("z"))
{
setImage(image3);
hitEnemy();
}
if (Greenfoot.isKeyDown("x"))
{
setImage(image6);
hitEnemy();
}
else if ( getImage()== image6)
{setImage(image1);}
if (Greenfoot.isKeyDown("a"))
{
setImage(image5);
hitEnemy();
}
else if ( getImage()== image5)
{setImage(image1);}
if (Greenfoot.isKeyDown("space"))
{
setImage(image1);
fire();
}
else if ( getImage() == image4 )
{setImage(image1);}
if (health<=0)
{
Greenfoot.playSound("cellyelling.wav");
getWorld().removeObject(this);
}
}
private void hitEnemy() {
Cell cell = (Cell) getOneObjectAtOffset(0, 0, Cell.class);
if (cell != null) {
cell.setHealth(-1001);
cell.move(30);
}
}
private void fire()
{
if (reloadDelayCount >= gunReloadTime) {
Bullet b = new Bullet(getMovement().copy(), getRotation());
getWorld().addObject(b, getX(), getY());
b.move();
shotsFired++;
reloadDelayCount = 20; // time since last shot fired
}
}
}