Add autoplay badge, change game timing to new Date with fallback

This commit is contained in:
LoveEevee 2018-10-03 17:22:40 +03:00
parent d6350a900c
commit 3e84c40184
5 changed files with 41 additions and 15 deletions

View File

@ -38,7 +38,8 @@ var assets = {
"bg_genre_6.png", "bg_genre_6.png",
"bg_genre_7.png", "bg_genre_7.png",
"bg_score_p1.png", "bg_score_p1.png",
"bg_score_p2.png" "bg_score_p2.png",
"badge_auto.png"
], ],
"audioSfx": [ "audioSfx": [
"don.wav", "don.wav",
@ -66,8 +67,7 @@ var assets = {
"title.ogg", "title.ogg",
"pause.wav", "pause.wav",
"cancel.wav", "cancel.wav",
"results.ogg", "results.ogg"
"diffsel.wav"
], ],
"audioSfxLR": [ "audioSfxLR": [
"note_don.ogg", "note_don.ogg",
@ -101,6 +101,9 @@ var assets = {
"results_crown.ogg", "results_crown.ogg",
"results_countup.wav" "results_countup.wav"
], ],
"audioSfxLoud": [
"diffsel.wav"
],
"audioMusic": [ "audioMusic": [
"bgm_songsel.ogg", "bgm_songsel.ogg",
"bgm_result.ogg", "bgm_result.ogg",

View File

@ -25,7 +25,6 @@ class Game{
this.paused = false this.paused = false
this.started = false this.started = false
this.mainMusicPlaying = false this.mainMusicPlaying = false
this.elapsedTimeSincePause = 0
this.musicFadeOut = 0 this.musicFadeOut = 0
this.fadeOutStarted = false this.fadeOutStarted = false
this.currentTimingPoint = 0 this.currentTimingPoint = 0
@ -45,7 +44,7 @@ class Game{
var offsetTime = Math.max(0, this.timeForDistanceCircle - this.songData.circles[0].ms) |0 var offsetTime = Math.max(0, this.timeForDistanceCircle - this.songData.circles[0].ms) |0
this.elapsedTime = -offsetTime this.elapsedTime = -offsetTime
// The real start for the game will start when chrono will reach 0 // The real start for the game will start when chrono will reach 0
this.startDate = snd.buffer.getTime() * 1000 + offsetTime this.startDate = +(new Date) + offsetTime
} }
update(){ update(){
// Main operations // Main operations
@ -317,14 +316,15 @@ class Game{
if(!this.paused){ if(!this.paused){
assets.sounds["pause"].play() assets.sounds["pause"].play()
this.paused = true this.paused = true
this.latestDate = snd.buffer.getTime() * 1000 this.latestDate = +new Date
this.mainAsset.stop() this.mainAsset.stop()
this.mainMusicPlaying = false this.mainMusicPlaying = false
}else{ }else{
assets.sounds["cancel"].play() assets.sounds["cancel"].play()
this.paused = false this.paused = false
var currentDate = snd.buffer.getTime() * 1000 var currentDate = +new Date
this.elapsedTimeSincePause = this.elapsedTimeSincePause + currentDate - this.latestDate this.startDate += currentDate - this.latestDate
this.sndTime = currentDate - snd.buffer.getTime() * 1000
} }
} }
isPaused(){ isPaused(){
@ -334,20 +334,26 @@ class Game{
// Refreshed date // Refreshed date
var ms = this.elapsedTime var ms = this.elapsedTime
if(ms >= 0 && !this.started){ if(ms >= 0 && !this.started){
this.startDate = snd.buffer.getTime() * 1000 this.startDate = +new Date
this.elapsedTimeSincePause = 0
this.elapsedTime = this.getAccurateTime() this.elapsedTime = this.getAccurateTime()
this.started = true this.started = true
this.sndTime = this.startDate - snd.buffer.getTime() * 1000
}else if(ms < 0 || ms >= 0 && this.started){ }else if(ms < 0 || ms >= 0 && this.started){
this.elapsedTime = this.getAccurateTime() this.elapsedTime = this.getAccurateTime(ms >= 0)
} }
} }
getAccurateTime(){ getAccurateTime(){
if(this.isPaused()){ if(this.isPaused()){
return this.elapsedTime return this.elapsedTime
}else{ }else{
var currentDate = snd.buffer.getTime() * 1000 var currentDate = +new Date
return currentDate - this.startDate - this.elapsedTimeSincePause var sndTime = currentDate - snd.buffer.getTime() * 1000
var lag = sndTime - this.sndTime
if(Math.abs(lag) >= 50){
this.startDate += lag
this.sndTime = sndTime
}
return currentDate - this.startDate
} }
} }
getCircles(){ getCircles(){

View File

@ -39,11 +39,13 @@ class Loader{
snd.previewGain = snd.buffer.createGain() snd.previewGain = snd.buffer.createGain()
snd.sfxGainL = snd.buffer.createGain("left") snd.sfxGainL = snd.buffer.createGain("left")
snd.sfxGainR = snd.buffer.createGain("right") snd.sfxGainR = snd.buffer.createGain("right")
snd.sfxLoudGain = snd.buffer.createGain()
snd.buffer.setCrossfade( snd.buffer.setCrossfade(
[snd.musicGain, snd.previewGain], [snd.musicGain, snd.previewGain],
[snd.sfxGain, snd.sfxGainL, snd.sfxGainR], [snd.sfxGain, snd.sfxGainL, snd.sfxGainR],
0.5 0.5
) )
snd.sfxLoudGain.setVolume(1.2)
assets.audioSfx.forEach(name => { assets.audioSfx.forEach(name => {
this.promises.push(this.loadSound(name, snd.sfxGain)) this.promises.push(this.loadSound(name, snd.sfxGain))
@ -58,6 +60,9 @@ class Loader{
assets.sounds[id + "_p2"] = assets.sounds[id].copy(snd.sfxGainR) assets.sounds[id + "_p2"] = assets.sounds[id].copy(snd.sfxGainR)
})) }))
}) })
assets.audioSfxLoud.forEach(name => {
this.promises.push(this.loadSound(name, snd.sfxLoudGain))
})
p2 = new P2Connection() p2 = new P2Connection()

View File

@ -270,6 +270,12 @@ class Scoresheet{
276, 150, imgScale * 176, imgScale * 120 276, 150, imgScale * 176, imgScale * 120
) )
if(this.controller.autoPlayEnabled){
ctx.drawImage(assets.image["badge_auto"],
431, 311, 34, 34
)
}
this.draw.roundedRect({ this.draw.roundedRect({
ctx: ctx, ctx: ctx,
x: 532, x: 532,
@ -439,7 +445,7 @@ class Scoresheet{
} }
if(this.state.screen === "fadeIn" && elapsed >= 1200 && !this.state["fullcomboPlayed" + p]){ if(this.state.screen === "fadeIn" && elapsed >= 1200 && !this.state["fullcomboPlayed" + p]){
this.state["fullcomboPlayed" + p] = true this.state["fullcomboPlayed" + p] = true
if(crownType === "gold" && !this.controller.autoPlayEnabled){ if(crownType === "gold"){
this.playSound("results_fullcombo" + (p === 1 ? "2" : ""), p) this.playSound("results_fullcombo" + (p === 1 ? "2" : ""), p)
} }
} }
@ -473,7 +479,7 @@ class Scoresheet{
var lastTime = 0 var lastTime = 0
for(var p = 0; p < players; p++){ for(var p = 0; p < players; p++){
var results = p === 0 ? this.results : p2.results var results = p === 0 ? this.results : p2.results
var currentTime = 3100 + results.points.length * 30 * this.frame + 1000 var currentTime = 3100 + results.points.length * 30 * this.frame
if(currentTime > lastTime){ if(currentTime > lastTime){
lastTime = currentTime lastTime = currentTime
} }

View File

@ -619,6 +619,12 @@ class View{
this.diffX, this.diffY, this.diffX, this.diffY,
this.diffW, this.diffH this.diffW, this.diffH
) )
if(this.controller.autoPlayEnabled){
this.ctx.drawImage(assets.image["badge_auto"],
this.diffX + this.diffW * 0.71, this.diffY + this.diffH * 0.01,
this.diffH * 0.3, this.diffH * 0.3
)
}
this.ctx.drawImage(assets.image.taiko, this.ctx.drawImage(assets.image.taiko,
this.taikoX, this.taikoY, this.taikoX, this.taikoY,
this.taikoW, this.taikoH this.taikoW, this.taikoH