forked from anufav/GirlScript-GameBooster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CC_031_FlappyBird.pde
62 lines (51 loc) · 1014 Bytes
/
CC_031_FlappyBird.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
56
57
58
59
60
61
62
// Daniel Shiffman
// http://codingtra.in
// http://patreon.com/codingtrain
// Code for: https://youtu.be/cXgA1d_E-jY
Bird b;
int wid = 400;
int rez = 20;
int score = 0;
boolean jumping = false;
PVector gravity = new PVector(0, 0.5);
ArrayList<Pipe> pipes = new ArrayList<Pipe>();
void setup() {
size(400, 800);
b = new Bird();
pipes.add(new Pipe());
}
void draw() {
background(0);
if (frameCount % 75 == 0) {
pipes.add(new Pipe());
}
if (keyPressed) {
PVector up = new PVector(0, -5);
b.applyForce(up);
}
b.update();
b.show();
boolean safe = true;
for (int i = pipes.size() - 1; i >= 0; i--) {
Pipe p = pipes.get(i);
p.update();
if (p.hits(b)) {
p.show(true);
safe = false;
} else {
p.show(false);
}
if (p.x < -p.w) {
pipes.remove(i);
}
}
if (safe) {
score++;
} else {
score -= 50;
}
fill(255, 0, 255);
textSize(64);
text(score, width/2, 50);
score = constrain(score, 0, score);
}