-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsketch.js
More file actions
45 lines (42 loc) · 762 Bytes
/
sketch.js
File metadata and controls
45 lines (42 loc) · 762 Bytes
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
var bird;
var pipes = [];
var score = 0;
var backimg;
function preload() {
backimg = loadImage('background.jpg')
}
function setup() {
createCanvas(600, 500);
bird = new Bird();
pipes.push(new Pipe());
}
function draw() {
background(backimg);
for (var i = pipes.length - 1; i >= 0; i--) { pipes[i].show();
pipes[i].update();
if (pipes[i].hits(bird)) {
noLoop();
background(0, 78, 56);
textSize(56);
text("game over", 78, 78 )
text("score is " + score, 40, 40)
setTimeout(() => {
location.reload();
}, 1000)
}
if(pipes[i].offscreen()) {
pipes.splice(i, 1);
score++
}
}
bird.update();
bird.show();
if (frameCount % 100 == 0) {
pipes.push(new Pipe());
}
}
function keyPressed() {
if (key == ' ') {
bird.up();
}
}