forked from suzuki-nanako/make-santa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.start.js
76 lines (57 loc) · 1.73 KB
/
game.start.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
const snow = document.querySelector('.snow');
const sceneStart = document.querySelector('.scene.start');
const button = document.querySelector('.startbutton');
//
// スタートボタンで隠す
//
const hideStartScene = function() {
sceneStart.classList.add('hidden');
const convertToMS = function(h, m, s) {
return (
(h * 60 * 60 * 1000) +
(m * 60 * 1000) +
(s * 1000)
);
};
window.app.timelimit = Date.now() + convertToMS(0, 0, 40);
window.app.isGameStarted = true;
};
button.ontouchstart = hideStartScene;
button.onmousedown = hideStartScene;
//
// 雪を複製する
//
const snowList = [];
for (let count = 0; count < 10; count += 1) {
const snow = document.createElement('div');
snow.classList.add('snow');
sceneStart.appendChild(snow);
const x = Math.random() * window.innerWidth;
const y = Math.random() * window.innerHeight;
snow.style.left = `${x}px`;
snow.style.top = `${y}px`;
snowList.push(snow);
}
//
// 雪を動かす
//
const animateSnow = function() {
for (let i = 0; i < snowList.length; i++) {
const snow = snowList[i];
let x = parseFloat(snow.style.left);// 'px' を取る
let y = parseFloat(snow.style.top );// 'px' を取る
const xMax = window.innerWidth + 20;
const yMax = window.innerHeight + 20;
y += Math.random() * 5;
if (xMax <= x) {
x -= xMax;
}
if (yMax <= y) {
y -= yMax;
}
snow.style.left = `${x}px`;
snow.style.top = `${y}px`;
}
requestAnimationFrame(animateSnow);
};
requestAnimationFrame(animateSnow);