2018-08-28 07:56:31 +08:00
|
|
|
class Mekadon{
|
2022-02-11 22:28:22 +08:00
|
|
|
constructor(...args){
|
|
|
|
this.init(...args)
|
|
|
|
}
|
|
|
|
init(controller, game){
|
2018-09-15 22:34:53 +08:00
|
|
|
this.controller = controller
|
|
|
|
this.game = game
|
|
|
|
this.lr = false
|
|
|
|
this.lastHit = -Infinity
|
2020-12-04 18:52:35 +08:00
|
|
|
this.delay = controller.audioLatency
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
|
|
|
play(circle){
|
2019-02-18 00:26:46 +08:00
|
|
|
var type = circle.type
|
|
|
|
if((type === "balloon" || type === "drumroll" || type === "daiDrumroll") && this.getMS() > circle.endTime){
|
2019-02-21 04:48:21 +08:00
|
|
|
if(circle.section && circle.timesHit === 0){
|
|
|
|
this.game.resetSection()
|
|
|
|
}
|
2018-09-27 23:31:57 +08:00
|
|
|
circle.played(-1, false)
|
2018-09-21 02:30:49 +08:00
|
|
|
this.game.updateCurrentCircle()
|
|
|
|
}
|
2019-02-18 00:26:46 +08:00
|
|
|
type = circle.type
|
2018-09-21 02:30:49 +08:00
|
|
|
if(type === "balloon"){
|
2019-02-24 20:04:14 +08:00
|
|
|
return this.playDrumrollAt(circle, 0, 30)
|
2018-09-21 02:30:49 +08:00
|
|
|
}else if(type === "drumroll" || type === "daiDrumroll"){
|
2019-02-24 20:04:14 +08:00
|
|
|
return this.playDrumrollAt(circle, 0, 60)
|
2018-09-15 22:34:53 +08:00
|
|
|
}else{
|
2019-02-24 20:04:14 +08:00
|
|
|
return this.playAt(circle, 0, 450)
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
|
|
|
}
|
2018-11-13 12:36:15 +08:00
|
|
|
playAt(circle, ms, score, dai, reverse){
|
2020-12-04 18:52:35 +08:00
|
|
|
var currentMs = circle.ms - this.getMS() + this.delay
|
2018-09-15 22:34:53 +08:00
|
|
|
if(ms > currentMs - 10){
|
2018-11-13 12:36:15 +08:00
|
|
|
return this.playNow(circle, score, dai, reverse)
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
|
|
|
}
|
2018-11-13 12:36:15 +08:00
|
|
|
playDrumrollAt(circle, ms, pace, kaAmount){
|
2018-09-15 22:34:53 +08:00
|
|
|
if(pace && this.getMS() >= this.lastHit + pace){
|
2018-11-13 12:36:15 +08:00
|
|
|
var score = 1
|
|
|
|
if(kaAmount > 0){
|
|
|
|
score = Math.random() > kaAmount ? 1 : 2
|
|
|
|
}
|
2019-02-24 20:04:14 +08:00
|
|
|
return this.playAt(circle, ms, score)
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
miss(circle){
|
2019-02-18 00:26:46 +08:00
|
|
|
var currentMs = circle.ms - this.getMS()
|
2018-09-15 22:34:53 +08:00
|
|
|
if(0 >= currentMs - 10){
|
|
|
|
this.controller.displayScore(0, true)
|
|
|
|
this.game.updateCurrentCircle()
|
|
|
|
this.game.updateCombo(0)
|
2018-09-20 07:20:26 +08:00
|
|
|
this.game.updateGlobalScore(0, 1, circle.gogoTime)
|
2019-02-18 00:26:46 +08:00
|
|
|
this.game.sectionNotes.push(0)
|
2018-09-15 22:34:53 +08:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
2018-11-13 12:36:15 +08:00
|
|
|
playNow(circle, score, dai, reverse){
|
2019-02-18 00:26:46 +08:00
|
|
|
var type = circle.type
|
2018-09-19 01:33:18 +08:00
|
|
|
var keyDai = false
|
|
|
|
var playDai = !dai || dai === 2
|
2018-09-22 04:31:35 +08:00
|
|
|
var drumrollNotes = type === "balloon" || type === "drumroll" || type === "daiDrumroll"
|
|
|
|
|
|
|
|
if(drumrollNotes){
|
|
|
|
var ms = this.getMS()
|
|
|
|
}else{
|
2019-02-18 00:26:46 +08:00
|
|
|
var ms = circle.ms
|
2018-09-22 04:31:35 +08:00
|
|
|
}
|
|
|
|
|
2018-11-13 12:36:15 +08:00
|
|
|
if(reverse){
|
|
|
|
if(type === "don" || type === "daiDon"){
|
|
|
|
type = "ka"
|
|
|
|
}else if(type === "ka" || type === "daiKa"){
|
|
|
|
type = "don"
|
|
|
|
}
|
|
|
|
}
|
2019-03-16 05:34:48 +08:00
|
|
|
if(type === "daiDon" && playDai){
|
2019-04-17 02:06:41 +08:00
|
|
|
this.setKey("don_l", ms)
|
|
|
|
this.setKey("don_r", ms)
|
2018-09-15 22:34:53 +08:00
|
|
|
this.lr = false
|
2018-09-19 01:33:18 +08:00
|
|
|
keyDai = true
|
2019-03-16 05:34:48 +08:00
|
|
|
}else if(type === "don" || type === "daiDon" || drumrollNotes && score !== 2){
|
2019-04-17 02:06:41 +08:00
|
|
|
this.setKey(this.lr ? "don_l" : "don_r", ms)
|
2018-09-15 22:34:53 +08:00
|
|
|
this.lr = !this.lr
|
2019-03-16 05:34:48 +08:00
|
|
|
}else if(type === "daiKa" && playDai){
|
2019-04-17 02:06:41 +08:00
|
|
|
this.setKey("ka_l", ms)
|
|
|
|
this.setKey("ka_r", ms)
|
2018-09-15 22:34:53 +08:00
|
|
|
this.lr = false
|
2018-09-19 01:33:18 +08:00
|
|
|
keyDai = true
|
2019-03-16 05:34:48 +08:00
|
|
|
}else if(type === "ka" || type === "daiKa" || drumrollNotes){
|
2019-04-17 02:06:41 +08:00
|
|
|
this.setKey(this.lr ? "ka_l" : "ka_r", ms)
|
2018-09-19 01:33:18 +08:00
|
|
|
this.lr = !this.lr
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
2018-09-21 02:30:49 +08:00
|
|
|
if(type === "balloon"){
|
2019-03-16 05:34:48 +08:00
|
|
|
if(circle.requiredHits === 1){
|
2019-02-04 17:14:42 +08:00
|
|
|
assets.sounds["se_balloon"].play()
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
|
|
|
this.game.checkBalloon(circle)
|
2018-09-21 02:30:49 +08:00
|
|
|
}else if(type === "drumroll" || type === "daiDrumroll"){
|
2018-11-13 12:36:15 +08:00
|
|
|
this.game.checkDrumroll(circle, score === 2)
|
2018-09-15 22:34:53 +08:00
|
|
|
}else{
|
2018-11-15 16:42:22 +08:00
|
|
|
this.controller.displayScore(score, false, keyDai)
|
2018-09-22 04:31:35 +08:00
|
|
|
this.game.updateCombo(score)
|
|
|
|
this.game.updateGlobalScore(score, keyDai ? 2 : 1, circle.gogoTime)
|
|
|
|
this.game.updateCurrentCircle()
|
2018-09-19 01:33:18 +08:00
|
|
|
circle.played(score, keyDai)
|
2019-02-21 04:48:21 +08:00
|
|
|
if(circle.section){
|
|
|
|
this.game.resetSection()
|
|
|
|
}
|
2019-02-18 00:26:46 +08:00
|
|
|
this.game.sectionNotes.push(score === 450 ? 1 : (score === 230 ? 0.5 : 0))
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
2018-09-22 04:31:35 +08:00
|
|
|
this.lastHit = ms
|
2018-09-15 22:34:53 +08:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
getMS(){
|
2018-10-03 17:48:18 +08:00
|
|
|
return this.controller.getElapsedTime()
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
2019-04-17 02:06:41 +08:00
|
|
|
setKey(name, ms){
|
|
|
|
this.controller.setKey(true, name, ms)
|
2018-09-15 22:34:53 +08:00
|
|
|
}
|
2018-08-28 07:56:31 +08:00
|
|
|
}
|