-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVillain.java
65 lines (61 loc) · 1.83 KB
/
Villain.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Villain here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Villain extends Actor
{
/**
* Act - do whatever the Villain wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public int health = 100;
public int timer = 27;
public int fireTimer = 150;
public void act()
{
// Add your action code here.
timer--;
fireTimer--;
if (timer <= 0) {
timer = 27;
if (((Elmos_World)getWorld()).me.getX() <= getX()) {
setLocation(getX() - 2, getY());
}
else {
setLocation(getX() + 2, getY());
}
if (((Elmos_World)getWorld()).me.getY() <= getY()) {
setLocation(getX(), getY() - 2);
}
else {
setLocation(getX(), getY() + 2);
}
}
if (fireTimer <= 0) {
Fireball f = new Fireball();
// if (((Elmos_World)getWorld()).me.getX() <= getX()) {
// f.dx = -2;
// }
// else {
// f.dx = 2;
// }
// if (((Elmos_World)getWorld()).me.getY() <= getY()) {
// f.dy = -2;
// }
// else {
// f.dy = 2;
// }
((Elmos_World)getWorld()).addObject(f, getX(), getY());
f.rawr();
fireTimer = 150;
}
if (health <= 0) {
Key k = new Key();
((Elmos_World)getWorld()).addObject(k, getX(), getY());
((Elmos_World)getWorld()).removeObject(this);
}
}
}