-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControlledVehicle.pde
More file actions
45 lines (35 loc) · 955 Bytes
/
ControlledVehicle.pde
File metadata and controls
45 lines (35 loc) · 955 Bytes
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
class ControlledVehicle extends Vehicle {
// ----- Fields
private final TrafficLight trafficLight;
private float baseSpeed;
// ----- Constructors
public ControlledVehicle(TrafficLight trafficLight, Consumer<Vehicle> onDestroyed) {
super(onDestroyed);
this.trafficLight = trafficLight;
}
// ----- Methods
@Override
public void initAndEnable(Vec2Int movementDir, float minSpeed, float maxSpeed) {
super.initAndEnable(movementDir, minSpeed, maxSpeed);
baseSpeed = speed;
}
@Override
public void draw() {
super.draw();
if (position.y < 150)
speed = baseSpeed;
switch (trafficLight.getState()) {
case GREEN:
speed = baseSpeed;
break;
case YELLOW:
if (position.y >= 150)
speed = baseSpeed / 2f;
break;
case RED:
if (position.y >= 150 && position.y <= 250)
speed = 0f;
break;
}
}
}