35 lines
900 B
Java
35 lines
900 B
Java
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
|
|
|
/**
|
|
* Write a description of class EnemyProjectile here.
|
|
*
|
|
* @author (your name)
|
|
* @version (a version number or a date)
|
|
*/
|
|
public class EnemyProjectile extends Projectile
|
|
{
|
|
/**
|
|
* Act - do whatever the EnemyProjectile wants to do. This method is called whenever
|
|
* the 'Act' or 'Run' button gets pressed in the environment.
|
|
*/
|
|
public void act()
|
|
{
|
|
move(10);
|
|
if (!isProjectileOnScreen()){
|
|
getWorld().removeObject(this);
|
|
}
|
|
}
|
|
|
|
public boolean isProjectileOnScreen(){
|
|
//Check Y-Value
|
|
if (getY() <= 0 || getY() >= getWorld().getHeight()-1){
|
|
return false;
|
|
}
|
|
//Check X-Value
|
|
if (getX() <= 0 || getX() >= getWorld().getWidth()-1){
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
}
|