public class Airplane extends AnimBase
{
GreenfootSound Bullet = new GreenfootSound ("Bullet.wav");//plays the music that i saved in the sound file
GreenfootSound Grenade = new GreenfootSound ("Grenade.wav");//plays the music that i saved in the sound file
GreenfootSound GameOver = new GreenfootSound ("GameOver.wav");//plays the music that i saved in the sound file
GreenfootSound backgroundMusic = new GreenfootSound("Background.wav");//plays the music that i saved in the sound file
int bulletStep=0;
protected int Score = 0;
protected int Point = 0;
/**
* 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 stopped ()
{
Point = 0;
Score = 0;
}
public void act()
{
Point = 0;
Score = 0;
move (2);//keeps going forward by 2
Actor Ok = getOneIntersectingObject(Ok.class);
if(Ok!= null && Greenfoot.isKeyDown("Left"))//control structure
// if it is touching the class named Ok and the left key is being pressed
{
move (+10);//moves 10 so it can not go behind Ok class.
}
bombDetect();
{
catchKey();
}
stopped();
}
public void moveLeft()
{
setLocation(getX()-5, getY());
}
private void catchKey()
{
catchKeyMove();
catchKeyShoot();
}
private void catchKeyMove()
{
if (Greenfoot.isKeyDown("left"))//control structure
{
moveLeft ();//abstraction
}
if (Greenfoot.isKeyDown("right"))//control structure
{
setLocation(getX()+5, getY());
}
if (Greenfoot.isKeyDown("Up"))//control structure
{
setLocation(getX(), getY()-3);
}
if (Greenfoot.isKeyDown("Down"))//control structure
{
setLocation(getX(), getY()+3);
}
}
private void catchKeyShoot()
{
if(Greenfoot.isKeyDown("space"))//control structure
{
Bullet.play ();
bulletStep = 0;
bulletStep++;
if(bulletStep==10)//control structure
{
Bullets b = new Bullets();
int posX = getX()+Math.floorDiv(getImage().getWidth(),2)+Math.floorDiv(b.getImage().getWidth(),2);
getWorld().addObject(b, posX, getY());
bulletStep=0;
}
}
}
public void bombDetect()
{
GameOver gameover = new GameOver();
if (isTouching ( Bomb.class))//control structure
{
Grenade.play ();
Greenfoot.setWorld(gameover);
backgroundMusic.stop ();
GameOver.play ();
}
}
}

