-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUltimateBulldozer.java
More file actions
53 lines (49 loc) · 1.54 KB
/
UltimateBulldozer.java
File metadata and controls
53 lines (49 loc) · 1.54 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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.ArrayList;
/**
* Write a description of class UltimateBulldozer here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class UltimateBulldozer extends Actor
{
public static final Color TRANSPARENT_RED = new Color (255, 0, 0, 128);
private GreenfootImage image;
protected boolean visible;
protected VehicleSpawner origin;
protected int height;
protected int width;
protected int y;
protected int cooldown = 5;
public UltimateBulldozer(VehicleSpawner origin) {
this.origin = origin;
}
protected void addedToWorld(World world){
VehicleWorld vw = (VehicleWorld)world;
height = origin.getHeight();
width = world.getWidth();
y = vw.getLaneY(origin.getLaneNumber());
if (origin.facesRightward()) {
setLocation(10,y);
} else {
setLocation(vw.getWidth()-10, y);
}
image = new GreenfootImage(width, height);
image.setColor(TRANSPARENT_RED);
image.fillRect(0, 0, width, height);
setImage(image);
boom();
}
/**
* Removes all touching vehicle and play explode effects on them
*/
public void boom(){
ArrayList<Vehicle> vehTouching = (ArrayList<Vehicle>)getIntersectingObjects(Vehicle.class);
for (Vehicle v : vehTouching){
v.explode();
getWorld().removeObject(v);
}
getWorld().removeObject(this);
}
}