-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgameControl.js
More file actions
82 lines (79 loc) · 2.3 KB
/
gameControl.js
File metadata and controls
82 lines (79 loc) · 2.3 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
class gameControl {
constructor() {
//this.generateScaleArray();
this.sprite = new Sprite();
this.sprite.collider = 'none';
this.sprite.x = 0;
this.sprite.y = 0;
this.sprite.width = 50;
this.sprite.height = 50;
this.gameOver=false;
this.savedScore=false;
this.sprite.draw=()=>{
if(this.gameOver)
{
push();
translate(width / 2, height / 2);
rectMode(CENTER);
noStroke();
fill([200, 50, 50,100]);
tint(255,0);
rect(0, 0, 600, 400);
var highscore=localStorage.getItem("chickenRunHighscore");
if(highscore===null)
{
highscore=0;
}
if(scoreCtrl.score>highscore)
{
highscore=scoreCtrl.score;
if(!this.savedScore)
{
localStorage.setItem("chickenRunHighscore",highscore);
this.savedScore=true;
}
}
if(this.savedScore)
{
fill('white');
text("NEW HIGHSCORE!!!!", -200, -100);
text("Score:" + scoreCtrl.score, -200, 0);
text("Press ENTER to restart!", -200, 100);;
}
else
{
fill('white');
text("Your score: " + scoreCtrl.score, -200, -100);
text("Highscore: " + highscore, -200, 0);
text("Press ENTER to restart!", -200, 100);;
}
pop();
}
}
}
getDifficulty()
{
var diff=(frameCount/60);//number of seconds since the start
diff=map(diff,0,240,0,100);
if(diff>100)
{
diff=100;
}
return diff;
}
reset()
{
frameCount=0;
this.gameOver=false;
this.savedScore=false;
player.reset();
buildingCtrl.reset();
scoreCtrl.reset();
backgroundCtrl1.reset();
backgroundCtrl2.reset();
}
endGame()
{
this.gameOver=true;
}
}