-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathBloon.java
executable file
·50 lines (43 loc) · 1.58 KB
/
Bloon.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
import greenfoot.*;
/**
* An abstract class for a generic Bloon. (Yes the miss-spelling is intentional to stay true to the original)
*
* @author Will Franzen
* @version 1.0.0
*/
public abstract class Bloon extends ActorThatDoesntSuck
{
// Path to follow
private PathIterator it;
// Constructor that takes a path to follow
public Bloon(Path path) {
it = new PathIterator(path);
}
// Constructor that takes a path iterator to continue
public Bloon(PathIterator pathit) {
it = pathit;
}
// Act method
public void act()
{
Point next = it.next(); // Get the next point
if(next == null) {
((BloonsWorld) getWorld()).decreaseLives(numInnerBloons() + 1); // delete yourself and decrease lives
getWorld().removeObject(this);
} else {
moveTo(next); // Move to the point
}
}
// Called when this Bloon is hit with a dart
public void pop() {
for(int i=0; i<numInnerBloons(); i++) { // Spawn a new RedBloon for every "innerBloon"
PathIterator subIterator = it.clone(); // Clone the iterator to follow
for(int j=0; j<i*10; j++) // Set them all slightly apart by advancing some more than others
subIterator.next();
getWorld().addObject(new RedBloon(subIterator), getX(), getY()); // Add the new Bloons
};
getWorld().removeObject(this); // Remove yourself
}
// Get the number of bloons to release when popped
public abstract int numInnerBloons();
}