Change note timing

This commit is contained in:
LoveEevee
2018-09-21 23:31:35 +03:00
parent cd694b39c2
commit 01d0a8104f
11 changed files with 161 additions and 120 deletions

View File

@@ -1,6 +1,8 @@
class Keyboard{
constructor(controller){
this.controller = controller
this.game = this.controller.game
this.kbd = {
"don_l": 86, // V
"don_r": 66, // B
@@ -19,12 +21,13 @@ class Keyboard{
}
this.gamepad = new Gamepad(this)
pageEvents.keyAdd(this, "all", "both", event => {
if (event.keyCode === 8){
if(event.keyCode === 8){
// Disable back navigation when pressing backspace
event.preventDefault()
}
if(this.buttonEnabled(event.keyCode)){
this.setKey(event.keyCode, event.type === "keydown")
if(!event.repeat && this.buttonEnabled(event.keyCode)){
var ms = this.game.getAccurateTime()
this.setKey(event.keyCode, event.type === "keydown", ms)
}
})
}
@@ -69,21 +72,20 @@ class Keyboard{
})
}
}
checkKey(keyCode, keyup, callback){
if(this.keys[keyCode] && !this.isWaiting(keyCode, keyup)){
this.waitForKeyup(keyCode, keyup)
checkKey(keyCode, type, callback){
if(this.keys[keyCode] && !this.isWaiting(keyCode, type)){
this.waitForKeyup(keyCode, type)
callback()
}
}
checkKeySound(keyCode, sound){
this.checkKey(keyCode, "sound", () => {
var circles = this.controller.parsedSongData.circles
var circle = circles[this.controller.game.getCurrentCircle()]
var circles = this.controller.getCircles()
var circle = circles[this.controller.getCurrentCircle()]
if(
(keyCode === this.kbd["don_l"] || keyCode === this.kbd["don_r"])
&& circle
&& !circle.getPlayed()
&& circle.getStatus() !== -1
&& circle.getType() === "balloon"
&& circle.requiredHits - circle.timesHit <= 1
){
@@ -91,40 +93,39 @@ class Keyboard{
}else{
assets.sounds["note_" + sound].play()
}
var ms = this.controller.getElapsedTime().ms
this.keyTime[keyCode] = ms
this.keyTime[sound] = ms
this.keyTime[sound] = this.keyTime[keyCode]
})
}
getKeys(){
return this.keys
}
setKey(keyCode, down){
setKey(keyCode, down, ms){
if(down){
this.keys[keyCode] = true
this.keyTime[keyCode] = ms
}else{
delete this.keys[keyCode]
delete this.waitKeyupScore[keyCode]
delete this.waitKeyupSound[keyCode]
delete this.waitKeyupMenu[keyCode]
this.keys[keyCode] = false
this.waitKeyupScore[keyCode] = false
this.waitKeyupSound[keyCode] = false
this.waitKeyupMenu[keyCode] = false
}
}
isWaiting(key, type){
isWaiting(keyCode, type){
if(type === "score"){
return this.waitKeyupScore[key]
return this.waitKeyupScore[keyCode]
}else if(type === "sound"){
return this.waitKeyupSound[key]
return this.waitKeyupSound[keyCode]
}else if(type === "menu"){
return this.waitKeyupMenu[key]
return this.waitKeyupMenu[keyCode]
}
}
waitForKeyup(key, type){
waitForKeyup(keyCode, type){
if(type === "score"){
this.waitKeyupScore[key] = true
this.waitKeyupScore[keyCode] = true
}else if(type === "sound"){
this.waitKeyupSound[key] = true
this.waitKeyupSound[keyCode] = true
}else if(type === "menu"){
this.waitKeyupMenu[key] = true
this.waitKeyupMenu[keyCode] = true
}
}
getKeyTime(){