import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Rocket here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Rocket extends Helicoptor
{ private int direction, speed;
private int timer = 0;
private int counter = 0;
// this is the explosion made when an enemy and a bullet intersect, the animation is played with timers frame by frame
public Rocket(int dir) {
direction = dir;
speed = 25;
}
/**
* Act - do whatever the Rocket wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
setRotation(direction);
move(speed);
if (isTouching(Enemy.class)) {
removeTouching(Enemy.class);
}
timer ++;
}
}
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 Enemy wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public int shotDelay = 0;
public int deSync = Greenfoot.getRandomNumber(200);
public void act() {
if (shotDelay >= 150 && shotDelay > deSync) {
getWorld().addObject(new Bullet(360), getX(), getY());
shotDelay = 0;
}
shotDelay++;
move(-1);
if (getX() == 0) {
getWorld().removeObject(this);
}
}
}