-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
62 lines (61 loc) · 1.18 KB
/
main.js
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
var block;
var score = 0, button;
function setup(){
c = createCanvas(windowWidth, windowHeight);
c.position(0, 0);
button = createButton("Replay");
button.position(width/2-40, height/2+20);
button.mouseClicked(restart);
button.hide();
block = new Block;
}
function draw(){
background(0);
drawScore();
block.display();
block.move();
}
function drawScore(){
textSize(30);
fill(255);
text("Score: " + score, 10, 30);
}
class Block{
constructor(){
this.x = width/2-20;
this.y = 0;
this.w = 40;
this.dy = 2;
}
display(){
fill(255, 40, 70);
rect(this.x, this.y, this.w, this.w);
}
move(){
if(this.y+40 >= height){
this.dy = 0;
textSize(50);
fill(255, 0, 0);
text('Game Over', width/2 - 120, height/2-20);
button.show();
noLoop();
}
else{
this.y += this.dy;
}
}
}
function mousePressed(){
block.dy = 0;
score++;
}
function mouseReleased(){
block.dy = 5;
}
function restart(){
score = 0;
block.y = 0;
block.dy = 2;
button.hide();
loop();
}