-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPed1.java
More file actions
50 lines (45 loc) · 1.24 KB
/
Ped1.java
File metadata and controls
50 lines (45 loc) · 1.24 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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.ArrayList;
/**
* Pedestrian 1 chooses a random lane as target and explodes
* when it reaches the Y value of the target lane
*
* @author Adrian Lee
* @version 20240317
*/
public class Ped1 extends Pedestrian
{
VehicleWorld vw;
private double speed;
private double maxSpeed;
private int direction, target, radius;
private boolean awake, targetReached, entering;
public Ped1(int direction){
super(direction);
targetReached = false;
radius = 96;
}
public void addedToWorld(World w){
vw = (VehicleWorld) w;
target = Greenfoot.getRandomNumber(vw.laneCount);
}
public void act()
{
if(getY() == vw.getLaneY(target)){
targetReached = true;
}
if(targetReached){
ArrayList<Vehicle> vNear = (ArrayList<Vehicle>) getObjectsInRange(radius,Vehicle.class);
if(vNear.size() > 0){
explode();
}
}
if(!targetReached){
super.act();
}
}
public void explode(){
vw.addObject(new PedExplosion(),getX(),getY());
vw.removeObject(this);
}
}