import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class RedPlane here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class RedPlane extends Planes
{
/**
* Act - do whatever the RedPlane wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
private Background bg;
public RedPlane(){
SetAsset("enemy_plane_red.png");
image.rotate(180);
this.health = 50;bg = (Background) getWorld();
this.attSpeed = 1.5f;
}
public void act()
{
bg = (Background) getWorld();
elapsedTime = System.currentTimeMillis() - currentTime;
Move(1);
Death();
if(elapsedTime > 3000/this.attSpeed){
Spawn();
elapsedTime = 0;
currentTime = System.currentTimeMillis();
}
}
private long currentTime = 0;
private long elapsedTime = 0;
private void Spawn () {
// create the item
Projectile_Red projectile = new Projectile_Red();
// add the item to the world
getWorld().addObject(projectile, getX(), getY()+30);
}
public void Death(){
if(this.health <= 0){
bg.GM.destroy--;
getWorld().removeObject(this);
}
}
@Override
public void Move(int moveSpeed){
setLocation(getX(), getY()+moveSpeed);
if(isAtEdge()){
//doesnt increase escaped variable
bg.GM.escaped++;
//both debug works but produce equals number "1" even if there is more than 1 instance that execute the
//code
System.out.println(bg.GM.escaped);
System.out.println("tess");
getWorld().removeObject(this);
}
}
public void TakeDamage(int damage){
this.health-=damage;
}
}

