-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lane.pde
47 lines (39 loc) · 1.07 KB
/
Lane.pde
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
public class Lane{
private PVector position;
private ArrayList<Obstacle> obstacles;
private float minDistance = 100;
public Lane(PVector position){
this.position = position;
this.obstacles = new ArrayList<Obstacle>();
}
//main function
public void update(){
for(int i = 0; i < obstacles.size(); i++){
Obstacle o = obstacles.get(i);
o.updatePosition();
if(o.getPosition().y > height + o.getSize().y/2)
despawn(o);
}
for(int i = 0; i < obstacles.size(); i++){
Obstacle o = obstacles.get(i);
o.collisionHandler();
o.display();
}
}
private void despawn(Obstacle obstacle){
obstacles.remove(obstacle);
}
public void setupObstacle(Obstacle obstacle){
obstacle.setPosition(new PVector(position.x, -obstacle.getSize().y, 0));
obstacles.add(obstacle);
}
public PVector getPosition(){
return position;
}
public float getMinDistance(){
return this.minDistance;
}
public void reset(){
obstacles.clear();
}
}