-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExplosion.java
More file actions
76 lines (70 loc) · 1.89 KB
/
Explosion.java
File metadata and controls
76 lines (70 loc) · 1.89 KB
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
66
67
68
69
70
71
72
73
74
75
76
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.ArrayList;
/**
* Superclass of every explosion effect.
* Explosion radius defined by image size.
* Remove all vehicles and pedestrians in radius.
*
* @author Adrian Lee
* @version 20240317
*/
public abstract class Explosion extends Actor
{
protected GreenfootImage img;
protected GreenfootSound sfx;
private VehicleWorld vw;
protected int countdown = 60;
protected int actCount;
protected int playing = 0;
private int radius;
public Explosion(){
img = new GreenfootImage("images/explode_low.png");
sfx = new GreenfootSound("sounds/explode.mp3");
}
public void addedToWorld(World w){
vw = (VehicleWorld) w;
this.sfx = sfx;
playing = 0;
sfx.play();
setImage(img);
}
public void act()
{
// Add your action code here.
explode();
}
/**
* Play explode effect with default settings
*/
public void explode(){
actCount ++;
if (playing == 0) {
sfx.play();
playing = 1;
}
if (actCount > countdown && getWorld() != null) {
actCount = 0;
getWorld().removeObject(this);
}
}
/**
* Play explode effect by a custom period of time
* and volume
*
* @param countdown The length of time the effect stays on screen in acts.
* @param volume The amplitude of sound. (0-100)
*/
public void explode(int countdown, int volume){
this.countdown = countdown;
sfx.setVolume(volume);
actCount ++;
if (playing == 0) {
sfx.play();
playing = 1;
}
if (actCount > countdown && getWorld() != null) {
actCount = 0;
getWorld().removeObject(this);
}
}
}