import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Missile here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Missile extends Actor
{
/**int h = 0;**/
public void act()
{
setLocation(getX() + speed, getY());
checkBoundaries();
if (getWorld() != null) destroyHelicopter();
}
//we add a method "checkBoundaries()" that destroys bullets that are off screen.
public void checkBoundaries()
{
if (isAtEdge()) getWorld().removeObject(this);
}
//"destroyEnemies()" destroys enemies.
public void destroyHelicopter()
{
Actor helicopter = getOneIntersectingObject(Helicopter.class);
if(helicopter != null) {
getWorld().removeObject(helicopter);
Myworld myworld = (Myworld)getWorld();
myworld.addScore(20);
}
}
public void destroyHinder()
{
Actor hinder = getOneIntersectingObject(Hinder.class);
if(hinder != null){
getWorld().removeObject(hinder);
Myworld myworld = (Myworld)getWorld();
myworld.addScore(20);
}
}
private int speed = 10;
private int health = 30;
}
