-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.js
85 lines (77 loc) · 2.51 KB
/
Game.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
let player=document.getElementById('player');
let object=document.getElementById('object');
let box=document.getElementById('box');
let score=document.getElementById('score');
let text=document.getElementById('text');
let ndcontainer=document.getElementById('ndcontainer');
let button=document.getElementById('button');
let container=document.getElementById('container');
let fast=document.getElementById('fast');
let medium=document.getElementById('medium');
let slow=document.getElementById('slow');
let song=document.getElementById('song');
const sound=new Audio();
sound.src='sound.mp3';
const whistle=new Audio();
whistle.src='whistle.mp3';
let value;
let seconds;
song.onclick=function (){
whistle.play();
song.style.display='none';
}
fast.onclick=function(){
value=500;
setInterval( animation,value);
seconds=0.5 +'s';
fast.style.display='none';
medium.style.display='none';
slow.style.display='none';
song.style.display='none';
}
medium.onclick=function(){
value=700;
setInterval( animation,value);
seconds=0.7 +'s';
fast.style.display='none';
medium.style.display='none';
slow.style.display='none';
song.style.display='none';
}
slow.onclick=function(){
value=900;
setInterval( animation,value);
seconds=0.9 +'s';
fast.style.display='none';
medium.style.display='none';
slow.style.display='none';
song.style.display='none';
}
function animation(){
var x=Math.random() * 480;
object.style.left=x + 'px';
object.style.animation='animation '+ seconds +' infinite';
var interval= setInterval(move,10);
score.innerText++;
function move(){
var playerLeft=parseInt(window.getComputedStyle(player).getPropertyValue('left'));
var objectTop=parseInt(window.getComputedStyle(object).getPropertyValue('top'));
var objectLeft=parseInt(window.getComputedStyle(object).getPropertyValue('left'));
if(objectTop<-15&& playerLeft + 50>objectLeft && playerLeft<objectLeft + 25){
sound.play();
object.style.display='none';
score.style.display='none';
ndcontainer.style.display='block';
text.innerText='☾ you got ' + score.innerText + ' Moonpoints ☽';
button.onclick=function(){
ndcontainer.style.display='none';
location.reload();
}
}
}
}
box.addEventListener('mousemove', (e)=>{
if(e.offsetX>0 && e.offsetX<440){
player.style.left=e.offsetX +'px';
}
})