taiko-web/public/src/js/mekadon.js

110 lines
3.0 KiB
JavaScript
Raw Normal View History

2018-08-28 01:56:31 +02:00
class Mekadon{
2018-09-15 16:34:53 +02:00
constructor(controller, game){
this.controller = controller
this.game = game
this.lr = false
this.lastHit = -Infinity
}
play(circle){
var type = circle.getType()
if((type === "balloon" || type === "drumroll" || type === "daiDrumroll") && this.getMS() > circle.getEndTime()){
2018-09-27 17:31:57 +02:00
circle.played(-1, false)
this.game.updateCurrentCircle()
}
type = circle.getType()
if(type === "balloon"){
2018-09-15 16:34:53 +02:00
this.playDrumrollAt(circle, 0, 30)
}else if(type === "drumroll" || type === "daiDrumroll"){
2018-09-15 16:34:53 +02:00
this.playDrumrollAt(circle, 0, 60)
}else{
this.playAt(circle, 0, 450)
}
}
2018-11-13 05:36:15 +01:00
playAt(circle, ms, score, dai, reverse){
2018-09-15 16:34:53 +02:00
var currentMs = circle.getMS() - this.getMS()
if(ms > currentMs - 10){
2018-11-13 05:36:15 +01:00
return this.playNow(circle, score, dai, reverse)
2018-09-15 16:34:53 +02:00
}
}
2018-11-13 05:36:15 +01:00
playDrumrollAt(circle, ms, pace, kaAmount){
2018-09-15 16:34:53 +02:00
if(pace && this.getMS() >= this.lastHit + pace){
2018-11-13 05:36:15 +01:00
var score = 1
if(kaAmount > 0){
score = Math.random() > kaAmount ? 1 : 2
}
this.playAt(circle, ms, score)
2018-09-15 16:34:53 +02:00
}
}
miss(circle){
var currentMs = circle.getMS() - this.getMS()
if(0 >= currentMs - 10){
this.controller.displayScore(0, true)
this.game.updateCurrentCircle()
this.game.updateCombo(0)
2018-09-20 01:20:26 +02:00
this.game.updateGlobalScore(0, 1, circle.gogoTime)
2018-09-15 16:34:53 +02:00
return true
}
}
2018-11-13 05:36:15 +01:00
playNow(circle, score, dai, reverse){
2018-09-15 16:34:53 +02:00
var kbd = this.controller.getBindings()
var type = circle.getType()
var keyDai = false
var playDai = !dai || dai === 2
2018-09-21 22:31:35 +02:00
var drumrollNotes = type === "balloon" || type === "drumroll" || type === "daiDrumroll"
if(drumrollNotes){
var ms = this.getMS()
}else{
var ms = circle.getMS()
}
2018-11-13 05:36:15 +01:00
if(reverse){
if(type === "don" || type === "daiDon"){
type = "ka"
}else if(type === "ka" || type === "daiKa"){
type = "don"
}
}
if(type == "daiDon" && playDai){
2018-09-21 22:31:35 +02:00
this.setKey(kbd["don_l"], ms)
this.setKey(kbd["don_r"], ms)
2018-09-15 16:34:53 +02:00
this.lr = false
keyDai = true
2018-11-13 05:36:15 +01:00
}else if(type == "don" || type == "daiDon" || drumrollNotes && score !== 2){
2018-09-21 22:31:35 +02:00
this.setKey(this.lr ? kbd["don_l"] : kbd["don_r"], ms)
2018-09-15 16:34:53 +02:00
this.lr = !this.lr
}else if(type == "daiKa" && playDai){
2018-09-21 22:31:35 +02:00
this.setKey(kbd["ka_l"], ms)
this.setKey(kbd["ka_r"], ms)
2018-09-15 16:34:53 +02:00
this.lr = false
keyDai = true
2018-11-13 05:36:15 +01:00
}else if(type == "ka" || type == "daiKa" || drumrollNotes){
2018-09-21 22:31:35 +02:00
this.setKey(this.lr ? kbd["ka_l"] : kbd["ka_r"], ms)
this.lr = !this.lr
2018-09-15 16:34:53 +02:00
}
if(type === "balloon"){
2018-09-15 16:34:53 +02:00
if(circle.requiredHits == 1){
2019-02-04 10:14:42 +01:00
assets.sounds["se_balloon"].play()
2018-09-15 16:34:53 +02:00
}
this.game.checkBalloon(circle)
}else if(type === "drumroll" || type === "daiDrumroll"){
2018-11-13 05:36:15 +01:00
this.game.checkDrumroll(circle, score === 2)
2018-09-15 16:34:53 +02:00
}else{
2018-11-15 09:42:22 +01:00
this.controller.displayScore(score, false, keyDai)
2018-09-21 22:31:35 +02:00
this.game.updateCombo(score)
this.game.updateGlobalScore(score, keyDai ? 2 : 1, circle.gogoTime)
this.game.updateCurrentCircle()
circle.played(score, keyDai)
2018-09-15 16:34:53 +02:00
}
2018-09-21 22:31:35 +02:00
this.lastHit = ms
2018-09-15 16:34:53 +02:00
return true
}
getMS(){
2018-10-03 11:48:18 +02:00
return this.controller.getElapsedTime()
2018-09-15 16:34:53 +02:00
}
2018-09-21 22:31:35 +02:00
setKey(keyCode, ms){
2018-09-15 16:34:53 +02:00
this.controller.setKey(keyCode, false)
2018-09-21 22:31:35 +02:00
this.controller.setKey(keyCode, true, ms)
2018-09-15 16:34:53 +02:00
}
2018-08-28 01:56:31 +02:00
}