-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTruck.java
52 lines (46 loc) · 1.35 KB
/
Truck.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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
/**
* The tow truck subclass
*/
public class Truck extends Vehicle
{
public Truck(VehicleSpawner origin){
super (origin); // call the superclass' constructor first
//Set up values for Bus
maxSpeed = 1.5 + ((Math.random() * 10)/5);
speed = maxSpeed;
// because the Bus graphic is tall, offset it a up (this may result in some collision check issues)
// yOffset = 15;
}
/**
* Act - do whatever the Bus wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
Vehicle ahead = (Vehicle) getOneObjectAtOffset (
direction * (int)(speed + getImage().getWidth()/2 + 3), 0, Vehicle.class);
if(detectCrash(ahead) && !towed){
tow(ahead);
}
super.act();
}
public boolean checkHitPedestrian () {
// currently empty
return false;
}
/**
* Detect if the vehicle in front is crashed
*/
public boolean detectCrash(Vehicle ahead) {
if (ahead != null){
return true;
}
return false;
}
public void tow(Vehicle ahead) {
towing = true;
ahead.getTowed(this);
}
}