Will somebody help me sort this out please.
I need it so it does not shoot when it is at the edge of the world
ENEMYLASER code
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Enemylaser here.
*
*/
public class Enemylaser extends Mover
{
private int life;
/**
* Act - do whatever the Enemylaser wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move(20.0);
ifAtWorldEdge();
eat();
life--;
if (life == 0)
{
getWorld().removeObject(this);
}
}
public void ifAtWorldEdge()
{
if (atWorldEdge())
{
getWorld().removeObject(this);
}
}
public void eat()
{
Actor Ship;
Ship = getOneObjectAtOffset(0, 0, Ship.class);
if (Ship != null)
{
World world;
world = getWorld();
world.removeObject(Ship);
}
}
}
ENEMYSHIP code
import greenfoot.*;
public class Miniship extends Actor
{
private int timer = 0;
public void act()
{
move(4);
fire();
reduceTime();
randomTurn();
turnAtEdge();
}
public void fire()
{
if (timer == 0)
{
getWorld().addObject(new Enemylaser(), getX(), getY());
Actor laser = getOneObjectAtOffset(0,0,Enemylaser.class);
laser.setRotation(getRotation());
timer = 100;
Greenfoot.playSound("laser.wav");
}
}
public void reduceTime()
{
if (timer > 0)
timer--;
}
/**
* With a 10% probability, turn a bit right or left.
*/
public void randomTurn()
{
if ( Greenfoot.getRandomNumber(100) < 10 )
{
turn( Greenfoot.getRandomNumber(40)-20 );
}
}
/**
* If we reach the edge of the world, turn a little bit.
*/
public void turnAtEdge()
{
if (atWorldEdge())
{
turn(7);
}
}
public boolean atWorldEdge()
{
if(getX() < 10 || getX() > getWorld().getWidth() - 10)
return true;
if(getY() < 10 || getY() > getWorld().getHeight() - 10)
return true;
else
return false;
}
}
Thanx if you can help

