35 lines
898 B
Java
35 lines
898 B
Java
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
|
|
|
/**
|
|
* Write a description of class PlayerProjectile here.
|
|
*
|
|
* @author (your name)
|
|
* @version (a version number or a date)
|
|
*/
|
|
public class PlayerProjectile extends Actor
|
|
{
|
|
/**
|
|
* Act - do whatever the PlayerProjectile wants to do. This method is called whenever
|
|
* the 'Act' or 'Run' button gets pressed in the environment.
|
|
*/
|
|
public void act()
|
|
{
|
|
move(7);
|
|
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().getHeight()-1){
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
}
|