I need help with an error message I'm getting. I'm new to greenfoot and understand it a little bit right now Im trying to write a code where the rocket is able to shoot photon torpedos by pressing the letter p...and the photon torpedo completely destroy just one asteroid. Im trying to work on the first command and Im getting an error message that says "cannot find symbol - method fire Boolean....I know I have to declare fire but when I do I still get the same error message.
This is what I have so far:
/**
* A rocket that can be controlled by the arrowkeys: up, left, right.
* The gun is fired by hitting the 'space' key. 'z' releases a proton wave.
*
* @author Poul Henriksen
* @author Michael Kolling
*
* @version 1.0
*/
public class Rocket extends SmoothMover
{
public int torpedoCount = 10;
public int torpedoDamage = 10;
private static final int gunReloadTime = 5; // The minimum delay between firing the gun.
private static final int protonReloadTime = 500; // The minimum delay between proton wave bursts.
private int reloadDelayCount; // How long ago we fired the gun the last time.
private int protonDelayCount; // How long ago we fired the proton wave the last time.
private GreenfootImage rocket = new GreenfootImage("rocket.png");
private GreenfootImage rocketWithThrust = new GreenfootImage("rocketWithThrust.png");
/**
* Initilise this rocket.
*/
public Rocket()
{
reloadDelayCount = 10;
protonDelayCount = 10;
addForce(new Vector(13, 0.3)); // initially slowly drifting
}
/**
* 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++;
protonDelayCount++;
}
/**
* Check whether there are any key pressed and react to them.
*/
private void checkKeys()
{
ignite(Greenfoot.isKeyDown("up"));
if (Greenfoot.isKeyDown("left"))
{
setRotation(getRotation() - 5);
}
if (Greenfoot.isKeyDown("right"))
{
setRotation(getRotation() + 5);
}
if (Greenfoot.isKeyDown("z"))
{
fire();
}
if (Greenfoot.isKeyDown("u"))//
{
startProtonWave();
}
if( Greenfoot.isKeyDown("space") || Greenfoot.isKeyDown("c") ) {
((Space)getWorld()).fire(false);
}
if( Greenfoot.isKeyDown("p") ) {
((Space)getWorld()).fire(true);
}
if (Greenfoot.isKeyDown("s"))//JC.....When letter s is pressed rocket stops
{
Greenfoot.stop(); //JC......line satisfies R4 requirement.
}
}
/**
* third and final firing method, linked from the world which is linked from buttonFirePhaser and buttonFireTorpedo
*/
public void fire ( boolean isTorpedo )
{
if ( isTorpedo ) {
if( torpedoCount >0 ) {
if (reloadDelayCount >= reloadTime) {
Torpedo torpedo = new Torpedo(torpedoDamage);
getWorld().addObject(torpedo, getX(), getY());
torpedo.setRotation(getRotation());
reloadDelayCount = 0;
torpedoCount--;
counterTorpedo.setValue(torpedoCount);
Greenfoot.playSound("Torpedo.mp3");
}
}
}
else {
if (phaserDelayCount >= phaserReloadTime) {
Phaser phaser = new Phaser(phaserDamage);
getWorld().addObject(phaser, getX(), getY());
phaser.setRotation(getRotation());
phaserDelayCount = 0;
Greenfoot.playSound("Phaser.wav");
}
}
}
/**
* Check whether we are colliding with an asteroid.
*/
private void checkCollision()
{
Actor a = getOneIntersectingObject(Asteroid.class);
if (a != null)
{
Space space = (Space) getWorld();
space.addObject(new Explosion(), getX(), getY());
space.removeObject(this);
space.gameOver();
}
}
/**
* Should the rocket be ignited?
*/
private void ignite(boolean boosterOn)
{
if (boosterOn)
{
setImage (rocketWithThrust);
addForce (new Vector(getRotation(), 0.3));
}
else
{
setImage(rocket);
}
}
/**
* Fire a bullet if the gun is ready.
*/
private void fire()
{
if (reloadDelayCount >= gunReloadTime)
{
Bullet bullet = new Bullet (getMovement().copy(), getRotation());
getWorld().addObject (bullet, getX(), getY());
bullet.move ();
reloadDelayCount = 0;
}
}
/**
* Release a proton wave (if it is loaded).
*/
private void startProtonWave()
{
if (protonDelayCount >= protonReloadTime)
{
ProtonWave wave = new ProtonWave();
getWorld().addObject (wave, getX(), getY());
protonDelayCount = 10;//JC
}
}
}

