This is my longshot class (my projectile) at the end i have a code to make the projectile disappear at the world's edge but when i typed it in and went to run my game the projectile just appeared by the gun and disappeared right away (not even staying on screen for one second) I know that there probably is a problem with the code that i am using at the end to make the longshot(projectile) disappear at the world's edge, but i am unaware on how to fix it, thanks for your time.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class longshot here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Longshot extends Mover
{ private int life = Greenfoot.getRandomNumber(2) + 8;
/**
* Act - do whatever the Longshot wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
moveAndTurn();
disappear();
}
public void moveAndTurn()
{
move(3.0);
Actor Fly;
Fly = getOneObjectAtOffset(0, 0, Fly.class);
if (Fly != null)
{
World world;
world = getWorld();
world.removeObject(Fly);
}
Actor Bee;
Bee = getOneObjectAtOffset(0, 0, Bee.class);
if (Bee != null)
{
World world;
world = getWorld();
world.removeObject(Bee);
}
Actor Warrior;
Warrior = getOneObjectAtOffset(0, 0, Warrior.class);
if (Warrior != null)
{
World world;
world = getWorld();
world.removeObject(Warrior);
}
}
/**
* atWorldEdge() method that checks if the Longshot is at the end of the world, if it is, return true, otherwise false
*/
public void disappear()
{
if (this.atWorldEdge())
{World world;
world = getWorld();
world.removeObject(this);
}
}
}
