-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnemy.java
46 lines (42 loc) · 1023 Bytes
/
Enemy.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Enemy
*
* @author Barry Al-Jawari, Betim Goxhuli, Edi Imamovic, James Lay
*
*/
public class Enemy extends Enemies
{
private SimpleTimer timer = new SimpleTimer();
public void act()
{
move(-4);
Delete();
fire();
if(Greenfoot.getRandomNumber(500)>5)
{
turn(10);
}
if(Greenfoot.getRandomNumber(500)>5)
{
turn(-10);
}
}
public void Delete()
{
if(atWorldEdge() && this!=null){
World world = getWorld();
world.removeObject(this);
}
}
public void fire()
{
if (timer.millisElapsed() > 1500 && this!=null);
{
if(Greenfoot.getRandomNumber(500)<2)
{
getWorld().addObject(new EnemyFire(getRotation()), getX(), getY());
}
}
}
}