-
Notifications
You must be signed in to change notification settings - Fork 0
/
Course.pde
49 lines (43 loc) · 939 Bytes
/
Course.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
48
49
import java.util.LinkedList;
import java.util.Random;
class Course{
//counter for generating pipes
int frequency, count;
Bird b;
Random r;
LinkedList<Pipe> arr;
//pipe generation
int gap, variability;
Course(Bird b, int frequency, int gap, int variability){
this.frequency = frequency;
this.b = b;
this.gap = gap;
this.variability = variability;
arr = new LinkedList<Pipe>();
r = new Random();
generate();
}
boolean update(){
if(arr.get(0).location < 0){
arr.removeFirst();
}
if(count >= frequency){
generate();
count = 0;
}
count++;
for(Pipe p : arr){
if(p.hit(b)) return true;
}
return false;
}
void generate(){
int x = r.nextInt(variability);
arr.add(new Pipe(x, 2, true));
arr.add(new Pipe(r.nextInt(abs(height-x-gap)), 2, false));
}
void display(){
for(Pipe p: arr)
p.display();
}
}