My plane is supposed to only be able to fire when the countdown is finished, so i added a public variable called countdownfinished, which gets changed to true when the countdown is finished, yet it still doesnt work. heres my countdown code
And heres my plane code
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Countdown here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Countdown extends Actor
{
private GreenfootImage Countdown3 = new GreenfootImage("Countdown3.png");
private GreenfootImage Countdown2 = new GreenfootImage("Countdown2.png");
private GreenfootImage Countdown1 = new GreenfootImage("Countdown1.png");
private GreenfootImage CountdownGo = new GreenfootImage("CountdownGo.png");
private static final int countdowntime = 50;
private int countdowntimer;
public static boolean countdownfinished;
/**
* Act - do whatever the Countdown wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
Countdown3();
}
public void Countdown3()
{
if(countdowntimer > 62)
{
Countdown2();
return;
}
else
{
countdowntimer++;
}
}
public void Countdown2()
{
setImage(Countdown2);
if(countdowntimer > 124)
{
Countdown1();
return;
}
else
{
countdowntimer++;
}
}
public void Countdown1()
{
setImage(Countdown1);
if(countdowntimer > 186)
{
CountdownGo();
return;
}
else
{
countdowntimer++;
}
}
public void CountdownGo()
{
setImage(CountdownGo);
if(countdowntimer > 248)
{
World world;
world=getWorld();
world.removeObject(this);
countdownfinished = true;
}
else
{
countdowntimer++;
}
}
}
import greenfoot.*;
/**
* Write a description of class Airplane here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Airplane extends Actor
{
private static final int max_acts_between_shots = 10;
private int actsBetweenShots = Integer.MAX_VALUE;
private static boolean countdowndone = Countdown.countdownfinished;
/**
* Act - do whatever the Airplane wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
getImage().scale(60,60);
move(2);
if(Greenfoot.isKeyDown("A"))
{
turn(-5);
}
if(Greenfoot.isKeyDown("D"))
{
turn(5);
}
if(countdowndone = true)
{
if(Greenfoot.isKeyDown("SPACE"))
{
if(actsBetweenShots > max_acts_between_shots) {
bullet b = new bullet();
getWorld().addObject(b, getX(), getY());
actsBetweenShots = 0;
b.setRotation(getRotation());
}
actsBetweenShots++;
}
}
}
}
