forked from Ezharjan/Web-basedRacerGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscore.js
110 lines (96 loc) · 2.1 KB
/
score.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
function Score() {
this.initialize = function () {
this.highScore = 0;
this.currentScore = 0;
this.showScore = false;
this.alpha = 0.0;
this.alphaText = 0.0;
};
this.resetScore = function () {
this.currentScore = 0;
this.alpha = 0.0;
this.alphaText = 0.0;
};
this.draw = function (context, pointsPar) {
this.currentScore = pointsPar;
Util.drawTextWithShadow(context, "SCORE", 660, 50, "white", 2, 2, "red");
Util.drawTextWithShadow(
context,
this.currentScore,
660,
90,
"yellow",
2,
2,
"red"
);
Util.drawTextWithShadow(context, "HIGH", 660, 180, "white", 2, 2, "red");
Util.drawTextWithShadow(context, "SCORE", 660, 210, "white", 2, 2, "red");
Util.drawTextWithShadow(
context,
this.highScore,
660,
250,
"yellow",
2,
2,
"red"
);
};
this.drawGameOverScreen = function (context) {
context.save();
// Show score slowly
this.alpha = this.alpha >= 0.6 ? this.alpha : this.alpha + 0.01;
context.globalAlpha = this.alpha;
context.fillRect(0, 0, Game.canvasWidth, Game.canvasHeight);
context.fillRect(150, 200, 500, Game.canvasHeight / 3);
// Show score slowly
this.alphaText = this.alphaText >= 1 ? 1 : this.alphaText + 0.01;
context.globalAlpha = this.alphaText;
context.font = "bold 50px Arial";
Util.drawTextWithShadow(
context,
"GAME OVER",
250,
260,
"red",
2,
2,
"yellow"
);
context.font = "46px Arial";
Util.drawTextWithShadow(context, "SCORE", 237, 320, "white", 2, 2, "red");
Util.drawTextWithShadow(
context,
this.currentScore,
410,
320,
"yellow",
2,
2,
"red"
);
context.font = "30px Arial";
Util.drawTextWithShadow(
context,
"HIGH SCORE",
210,
380,
"white",
2,
2,
"red"
);
Util.drawTextWithShadow(
context,
this.highScore,
410,
380,
"yellow",
2,
2,
"red"
);
context.restore();
};
}