-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
76 lines (55 loc) · 2.1 KB
/
Copy pathscript.js
File metadata and controls
76 lines (55 loc) · 2.1 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
var character = document.getElementById("character");
var block = document.getElementById("block");
var score = document.getElementById("score");
var game = document.getElementById("game");
var instruction = document.getElementById("instruction");
var scoreIncrementer = 0;
function setCharacterImg() {
var firstChild = character.firstChild;
}
function playJump() {
var sound = new Audio('https://themushroomkingdom.net/sounds/wav/smb/smb_coin.wav');
sound.play();
}
function playDie() {
var sound = new Audio('https://themushroomkingdom.net/sounds/wav/smb/smb_mariodie.wav');
sound.play();
}
function playBegin() {
var sound = new Audio('https://themushroomkingdom.net/sounds/wav/smb/smb_stage_clear.wav');
sound.play();
}
function jump() {
playJump();
if (character.classList.contains("animate") == false)
character.classList.add("animate");
setTimeout(function() {
character.classList.remove("animate");
}, 500);
upadateScoreBoard();
}
function upadateScoreBoard() {
if (isDead)
return;
scoreIncrementer = scoreIncrementer + 1;
score.innerText = "Score " + scoreIncrementer;
}
var isDead = false;
var checkDead = setInterval(function() {
var characterTop = parseInt(window.getComputedStyle(character).getPropertyValue("top"));
var blockLeft = parseInt(window.getComputedStyle(block).getPropertyValue("left"));
var characterLeft = parseInt(window.getComputedStyle(character).getPropertyValue("left"));
var characterWidth = parseInt(window.getComputedStyle(character).getPropertyValue("width"));
var totalLeft = characterLeft + characterWidth;
if (blockLeft >= characterLeft && blockLeft <= totalLeft &&
characterTop >= 270) {
isDead = true;
playDie();
score.innerText = "Your highest score was " + scoreIncrementer;
block.style.animation = "none";
block.style.display = "none";
character.style.animation = "none";
character.style.display = "none";
setTimeout(function() { instruction.innerHTML = "Refresh to start again"; }, 1000);
}
}, 10);