-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
55 lines (40 loc) · 1.13 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
(function () {
const lattos = document.getElementsByClassName('latto');
const score = document.getElementById('score');
const sound = document.getElementById('sound');
const arena = document.querySelector('.arena');
let speed = 8;
let rotate = 10;
let isPlay = false;
let scoreValue = 0;
arena.onclick = function () {
if (isPlay) {
rotate = 10;
scoreValue = 0;
UpdatePosition();
sound.pause();
} else {
sound.play();
}
isPlay = !isPlay;
}
function UpdateScore() {
score.innerHTML = `Score : ${scoreValue}`;
}
function UpdatePosition() {
lattos[0].style.cssText = `transform: translate(40px,0) rotate(${rotate}deg);`;
lattos[1].style.cssText = `transform: translate(-40px,0) rotate(-${rotate}deg);`;
}
function UpdateGame() {
if (isPlay) {
rotate += speed;
scoreValue += 1;
UpdatePosition();
UpdateScore();
}
}
//intial call function
UpdatePosition();
setInterval(UpdateGame, 10);
}())
//