This repository was archived by the owner on Feb 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLane.pde
55 lines (50 loc) · 1.4 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
48
49
50
51
52
53
54
55
// Classe que cria as linhas do nível do jogo
class Lane extends Rectangle {
Obstacl[] obst;
color laneColor;
int type;
Lane(int rowNum, color c) {
super(0, rowNum * grid, height, grid);
type = SAFETY;
obst = new Obstacl[0];
laneColor = c;
}
Lane(int rowNum, int t, int obAmount, int len, float spacing, float speed) {
super(0, rowNum * grid, height, grid);
obst = new Obstacl[obAmount];
type = t;
int offset = (int) random(20, 200);
for (int i = 0; i < obAmount; i++) {
obst[i] = new Obstacl(offset + spacing * i, rowNum * grid, grid * len, grid, speed);
}
laneColor = color(100, 0);
}
void run() {
for (int i = 0; i < obst.length; i++) {
obst[i].show(type, levelObst);
obst[i].update();
}
}
void checkPlayer(Player player) {
if (type == CAR) {
for (int i = 0; i < obst.length; i++) {
if (player.intersects(obst[i])) {
resetGame();
}
}
} else if (type == LOG) {
boolean ok = false;
for (int i = 0; i < obst.length; i++) {
if (player.intersects(obst[i])) {
ok = true;
player.attach(obst[i]);
}
}
if (!ok) {
resetGame();
}
} else { // Faz com que o personagem deixe de acompanhar os obstáculos do tipo "Eny"
player.attach(null);
}
}
}