-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameend.js
49 lines (45 loc) · 1.48 KB
/
gameend.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
function gameEndRender() {
var win = typeof wpm != "undefined"
ctx.globalAlpha = 0.4
if (win) {
ctx.drawImage(loadAndGrabImage("assets/img/green.png"), 0,0,width,height)
} else {
ctx.drawImage(loadAndGrabImage("assets/img/red.png"), 0,0,width,height)
}
ctx.globalAlpha = 1
s = 240
if (win) { s = s - 51.5}
ctx.font = "54px " + font
ctx.fillStyle = "#fff"
centerText("you " + (win ? "WIN" : "LOSE"), s )
ctx.font = "18px " + font
centerText("score", s + 50)
ctx.font = "72px " + font
centerText(Math.floor(game.score), s + 120)
ctx.font = "14px " + font
centerText("highest streAk", s + 150)
ctx.font = "54px " + font
centerText(game.highestStreak, s + 200)
ctx.font = "14px " + font
centerText("AccurAcy", s + 230)
ctx.font = "54px " + font
centerText(Math.floor((game.correct / (game.wrong + game.correct)) * 100) + "%", s + 280)
if (win) {
ctx.font = "14px " + font
centerText("wpm", s + 310)
ctx.font = "54px " + font
centerText(Math.floor(wpm), s + 360)
s = s + 80
}
s = s + 360
renderBtn(s-50,154,52,"Menu")
}
window.addEventListener("mousedown", function() {
if (screen == gameEndRender) {
var mouseover = calculateBtnBounds(s-37,150,48)
if (mouseover) {
game = Object.assign({}, defaultGame);
screen = renderMainMenu
}
}
})