I've made a game where when you shoot depending on the enemy they are either removed from my world or they spawn somewhere else. But every time I use the space bar to shoot when I run the game, my game gets paused when bullets hit edge or enemies except the skull. IDK how to fix this everything else works
Here's my code:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Shoot here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Shoot extends Mover
{
/**
* Act - do whatever the Shoot wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move(10);
if (hitTheEdge() !=null)
{
World myWorld = getWorld();
myWorld.removeObject(this);
}
shootRobots();
shootSkulls();
}
public void shootRobots()
{
Actor dolphin = getOneIntersectingObject(Dolphin.class);
if(dolphin != null)
{
World myWorld = getWorld();
myWorld.removeObject (dolphin);
myWorld.removeObject(this);
}
}
public void shootSkulls()
{
Actor baby = getOneIntersectingObject(Baby.class);
if(baby != null)
{
World myWorld = getWorld();
myWorld.removeObject (baby);
myWorld.removeObject(this);
int randomX = (int)(Math.random() * myWorld.getWidth());
int randomY = (int)(Math.random() * myWorld.getHeight());
myWorld.addObject(baby, randomX, randomY);
}
}
public String hitTheEdge()
{
int x = getX();
int y = getY();
World myWorld = getWorld();
int rightSide = myWorld.getWidth() - 1;
int bottomSide = myWorld.getHeight() - 1;
if (y == 0)
{
return "top";
} else if (x == 0)
{
return "left";
}else if (x == rightSide)
{
return "right";
}else if (y == bottomSide)
{
return "bottom";
} else {
return null;
}
}
}

