-
Notifications
You must be signed in to change notification settings - Fork 0
/
Explosion.java
54 lines (48 loc) · 1.32 KB
/
Explosion.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
import greenfoot.*;
import java.util.List;
public class Explosion extends Actor
{
private final static int IMAGE_COUNT = 8;
private static GreenfootImage[] images;
private int imageIndex = 0;
public Explosion()
{
initialiseImages();
setImage(images[0]);
Greenfoot.playSound("Explode.wav");
}
public synchronized static void initialiseImages()
{
if(images == null)
{
images = new GreenfootImage[IMAGE_COUNT];
GreenfootImage baseImage = new GreenfootImage("ShipExplode.png");
for (int i = 0; i < IMAGE_COUNT; i++) {
images[i] = new GreenfootImage(baseImage);
}
}
}
public void act()
{
setImage(images[imageIndex]);
explodeOthers();
imageIndex++;
if(imageIndex >= IMAGE_COUNT)
{
getWorld().removeObject(this);
}
}
private void explodeOthers()
{
List<Actor> explodeEm = getIntersectingObjects(Actor.class);
for (Actor a : explodeEm)
{
if (a instanceof Asteroid0)
{
int x = a.getX();
int y = a.getY();
// Additional logic for when an asteroid is hit can be added here
}
}
}
}