-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
391 lines (344 loc) · 11 KB
/
index.html
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
---
layout: default
---
<body>
<nav class="navbar is-warning" role="navigation" aria-label="main navigation">
<div class="navbar-brand is-vertical-center">
<h1 class="title is-4" style="margin: 0 12px 0 12px;">
欽ちゃんの仮装大賞パネル 再現アプリ
</h1>
<button id="help" class="button is-primary">
<i class="far fa-question-circle"></i>
</button>
<button id="show-helper-buttons" class="button" style="margin-left: 10px;">
<i class="fas fa-gamepad"></i>
</button>
</div>
</nav>
<section id="progress-section" class="section">
<div class="container is-center">
<div class="is-mobile">
<progress class="progress is-primary" max="100"></progress>
</div>
</div>
</section>
<section id="main-section" class="section">
<div class="container is-center">
<div class="columns is-mobile">
<div class="column" style="position: relative;">
<div style="bottom: 0; position: absolute;"></div>
</div>
<div class="canvas-wrapper">
<canvas id="contentMain" width="160" height="720"></canvas>
<canvas id="contentFrameAnim" width="160" height="720"></canvas>
</div>
<div class="column">
<div id="helper-buttons" class="is-hide">
<div style="margin-bottom: 30px;">
<button id="reset" class="button">リセット</button>
</div>
<div style="margin-bottom: 30px;">
<button id="increment" class="button is-primary">加点</button>
</div>
<div>
<div>音量</div>
<input type="range" min="0" max="10" value="5" class="slider" id="volumeRange" />
</div>
</div>
</div>
</div>
</div>
</section>
<div class="modal">
<div class="modal-background"></div>
<div class="modal-content">
<div class="notification">
操作方法
<br />
加点:A S D Space キー
<br />
リセット:R キー
<br />
v0.0.6
</div>
</div>
</div>
<script>
"use strict"
const WIDTH = 160
const HEIGHT = 720
const DEFAULT_SE_VOLUME = 0.5 // 0.0 ~ 1.0
class PanelManager {
constructor(context, contextFrameAnim) {
this.context = context
this.count = 0
this.frameAnim = {
context: contextFrameAnim,
step: 0,
maxStep: 6,
}
this.failTimer = {
instance: null,
limit: 3000,
}
this.isLoadedSE = false // iPhoneなどリソース読み込みに一部制限があるもの向け
this.imgs = {
bg: {
instance: new Image(),
path: "img/base.png",
},
numbers: [
{ instance: new Image(), path: "img/1.png" },
{ instance: new Image(), path: "img/2.png" },
{ instance: new Image(), path: "img/3.png" },
{ instance: new Image(), path: "img/4.png" },
{ instance: new Image(), path: "img/5.png" },
{ instance: new Image(), path: "img/6.png" },
{ instance: new Image(), path: "img/7.png" },
{ instance: new Image(), path: "img/8.png" },
{ instance: new Image(), path: "img/9.png" },
{ instance: new Image(), path: "img/10.png" },
{ instance: new Image(), path: "img/11.png" },
{ instance: new Image(), path: "img/12.png" },
{ instance: new Image(), path: "img/13.png" },
{ instance: new Image(), path: "img/14.png" },
{ instance: new Image(), path: "img/15.png" },
{ instance: new Image(), path: "img/16.png" },
{ instance: new Image(), path: "img/17.png" },
{ instance: new Image(), path: "img/18.png" },
{ instance: new Image(), path: "img/19.png" },
{ instance: new Image(), path: "img/20.png" },
],
frameAnim: {
instance: new Image(),
path: "img/kira_sprites.png",
},
}
this.se = {
numbers: [
new Audio("se/1.mp3"),
new Audio("se/2.mp3"),
new Audio("se/3.mp3"),
new Audio("se/4.mp3"),
new Audio("se/5.mp3"),
new Audio("se/6.mp3"),
new Audio("se/7.mp3"),
new Audio("se/8.mp3"),
new Audio("se/9.mp3"),
new Audio("se/10.mp3"),
new Audio("se/11.mp3"),
new Audio("se/12.mp3"),
new Audio("se/13.mp3"),
new Audio("se/14.mp3"),
new Audio("se/15.mp3"),
new Audio("se/16.mp3"),
new Audio("se/17.mp3"),
new Audio("se/18.mp3"),
new Audio("se/19.mp3"),
new Audio("se/20.mp3"),
],
clear: new Audio("se/clear.mp3"),
fail: new Audio("se/fail.mp3"),
}
this.changeVolume(DEFAULT_SE_VOLUME)
this.preloadSE()
this.preloadImages()
this.drawBg()
}
preloadImages() {
const drawList = [this.imgs.bg, this.imgs.frameAnim, ...this.imgs.numbers]
let loadedCount = 0
drawList.map((img) => {
img.instance.onload = () => {
loadedCount++
if (loadedCount >= drawList.length) {
this.preloadSuccess()
}
}
img.instance.src = img.path
})
}
preloadSE() {
const seList = [this.se.clear, this.se.fail, ...this.se.numbers]
seList.map((se) => {
se.load()
})
}
preloadSuccess() {
this.showContentDOM()
this.drawBg()
}
showContentDOM() {
document.getElementById("progress-section").classList.add("is-hide")
document.getElementById("main-section").classList.remove("is-hide")
}
clearSE() {
this.se.clear.pause()
this.se.clear.currentTime = 0
this.se.fail.pause()
this.se.fail.currentTime = 0
for (let i; i < this.se.numbers.length; i++) {
this.se.numbers[i].pause()
this.se.numbers[i].currentTime = 0
}
clearTimeout(this.failTimer.instance)
}
reset() {
this.clearSE()
this.clearAllCanvas()
clearInterval(this.frameAnim.instance)
this.count = 0
this.frameAnim.step = 0
this.drawBg()
}
getCount() {
return this.count
}
increment() {
if (this.count >= 20) {
return
}
this.count++
// サウンド再生
this.se.numbers[this.count - 1].play()
// 画像配置
this.drawNowCount()
// 15点以上で合格サウンド
if (this.count == 15) {
this.se.fail.pause()
this.se.fail.currentTime = 0
this.se.clear.play()
this.playFrameAnim()
}
// 残念サウンド
clearTimeout(this.failTimer.instance)
if (this.count < 15) {
this.failTimer.instance = setTimeout(() => {
this.se.fail.play()
}, this.failTimer.limit)
}
}
draw(imgInstance) {
this.context.drawImage(imgInstance, 0, 0, WIDTH, HEIGHT)
}
drawBg() {
this.draw(this.imgs.bg.instance)
}
drawNowCount() {
this.draw(this.imgs.numbers[this.count - 1].instance)
}
drawCount(count) {
this.draw(this.imgs.numbers[count - 1].instance)
}
drawFrameAnim() {
this.frameAnim.context.drawImage(
this.imgs.frameAnim.instance,
WIDTH * this.frameAnim.step,
0,
WIDTH,
HEIGHT,
0,
0,
WIDTH,
HEIGHT
)
}
clearAllCanvas() {
this.clearMainCanvas()
this.clearFrameAnimCanvas()
}
clearMainCanvas() {
this.context.clearRect(0, 0, WIDTH, HEIGHT)
}
clearFrameAnimCanvas() {
this.frameAnim.context.clearRect(0, 0, WIDTH, HEIGHT)
}
playFrameAnim() {
this.frameAnim.instance = setInterval(() => {
this.clearFrameAnimCanvas()
this.drawFrameAnim()
if (this.frameAnim.step >= this.frameAnim.maxStep) {
this.frameAnim.step = 1
} else {
this.frameAnim.step++
}
}, 50)
}
/**
* @param {number} value - 0.0 ~ 1.0
*/
changeVolume(value) {
this.se.numbers.forEach((_, i) => {
this.se.numbers[i].volume = value
})
this.se.clear.volume = value
this.se.fail.volume = value
}
}
window.onload = () => {
const context = document.getElementById("contentMain").getContext("2d")
const contextFrameAnim = document.getElementById("contentFrameAnim").getContext("2d")
const pm = new PanelManager(context, contextFrameAnim)
document.addEventListener("keydown", (e) => {
e.preventDefault()
// key A, S, D
const keys = [65, 83, 68]
switch (e.keyCode) {
case 65: // 'A' key
case 83: // 'S' key
case 68: // 'D' key
case 32: // 'Space' key
pm.increment()
break
case 82: // 'R' key
pm.reset()
break
case 77: // 'M' key
pm.changeVolume(0)
break
default:
break
}
})
// modal
document.getElementById("help").onclick = () => {
document.getElementsByClassName("modal")[0].classList.add("is-active")
}
document.getElementsByClassName("modal-background")[0].onclick = () => {
document.getElementsByClassName("modal")[0].classList.remove("is-active")
}
// show helper buttons
document.getElementById("show-helper-buttons").onclick = () => {
// NOTE: iPhoneはイベント中でしかload, playを受け付けないため、事前load用の処理
if (!pm.isLoadedSE) {
pm.preloadSE()
pm.isLoadedSE = true
}
const hideClassName = "is-hide"
const helperButtons = document.getElementById("helper-buttons")
if (helperButtons.classList.contains(hideClassName)) {
helperButtons.classList.remove(hideClassName)
} else {
helperButtons.classList.add(hideClassName)
}
}
// events.
document.getElementById("increment").onclick = (e) => {
pm.increment()
e.currentTarget.blur()
}
document.getElementById("reset").onclick = (e) => {
pm.reset()
e.currentTarget.blur()
}
document.getElementById("volumeRange").onchange = (e) => {
const volume = e.target.value * 0.1
pm.changeVolume(volume)
}
}
const showContent = () => {
document.getElementById("progress-section").classList.add("is-hide")
document.getElementById("main-section").classList.remove("is-hide")
}
</script>
</body>