I'm trying to make it so the asteroid (my enemy ship for rn) shoots down a bomb at my ship. I've already put in place the damage that it does and where it's supposed to come from, but there's some problems.
1. I don't know an If statement that will make the bomb shoot every few seconds instead of every time it hits the edge.
2. I don't know how to make the bomb shoot down instead of to the right/left
3. Side note: If you could also help, I don't know how to make my ship bounce back and forth across the top without changing the rotation so it messes up the image and the direction of the shot.
Enemy:
Enemy Beam:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Enemy here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Enemy extends Actor
{
/**
* Act - do whatever the Asteriod wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
private GreenfootImage image1;
private GreenfootImage image2;
EnemyBeam enemybeam = new EnemyBeam();
MyWorld world = (MyWorld) getWorld();
public void act()
{
move(1);
image1 = new GreenfootImage("rock.png");
image2 = new GreenfootImage("explosion.jpg");
setImage(image1);
if (isAtEdge()) {
turn(180);
World myWorld = getWorld();
myWorld.addObject(enemybeam,0,0);
enemybeam.setLocation(getX(), getY());
}
}
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class EnemyBeam here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class EnemyBeam extends Actor
{
/**
* Act - do whatever the EnemyBeam wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move(10);
Actor ship = getOneIntersectingObject(CopyOfShip.class);
if(ship!=null)
{
World myWorld = getWorld();
MyWorld world = (MyWorld) getWorld();
Lives lives = world.getLives();
lives.loseLife();
myWorld.removeObject(this);
}
else if(isAtEdge())
{
World myWorld = getWorld();
Actor mySelf = this;
myWorld.removeObject(mySelf);
}
}
}

