diff --git a/.gitignore b/.gitignore index 5749d69..69906bf 100644 --- a/.gitignore +++ b/.gitignore @@ -42,4 +42,5 @@ Network Trash Folder Temporary Items .apdisk public/songs +public/api taiko.db \ No newline at end of file diff --git a/public/index.html b/public/index.html index 6c7a8eb..7444d09 100644 --- a/public/index.html +++ b/public/index.html @@ -45,6 +45,7 @@ + diff --git a/public/src/js/bufferedloop.js b/public/src/js/bufferedloop.js index 926efb2..4c8e405 100644 --- a/public/src/js/bufferedloop.js +++ b/public/src/js/bufferedloop.js @@ -81,10 +81,12 @@ class BufferedLoop{ },100) } pause(){ + var self=this clearInterval(this.interval) this.sources.forEach(function(sourceObject){ sourceObject.source.stop(0) clearTimeout(sourceObject.timeout) + self.sources.delete(sourceObject) }) } } diff --git a/public/src/js/controller.js b/public/src/js/controller.js index f0bc6ac..9ac7fce 100644 --- a/public/src/js/controller.js +++ b/public/src/js/controller.js @@ -1,4 +1,4 @@ -function Controller(selectedSong, songData){ +function Controller(selectedSong, songData, autoPlayEnabled){ var _this = this; var _backgroundURL = "/songs/"+selectedSong.folder+"/bg.png"; @@ -8,6 +8,7 @@ function Controller(selectedSong, songData){ var _game = new Game(this, selectedSong, _songData); var _view = new View(this, _backgroundURL, selectedSong.title, selectedSong.difficulty); + var _mekadon = new Mekadon(this, _game); var _keyboard = new Keyboard(this); var _mainLoop; var _pauseMenu = false; @@ -124,7 +125,7 @@ function Controller(selectedSong, songData){ assets.sounds["main-music"].currentTime=0; clearInterval(_mainLoop); $("#screen").load("/src/views/game.html", function(){ - var taikoGame = new Controller(selectedSong, songData); + var taikoGame = new Controller(selectedSong, songData, autoPlayEnabled); taikoGame.run(); }); } @@ -165,6 +166,10 @@ function Controller(selectedSong, songData){ return _keyboard.getKeys(); } + this.setKey = function(keyCode, down){ + return _keyboard.setKey(keyCode, down); + } + this.getSongData = function(){ return _game.getSongData(); } @@ -209,4 +214,13 @@ function Controller(selectedSong, songData){ _game.updateGlobalScore(score); } + this.autoPlay = function(circle){ + if(autoPlayEnabled){ + if(circle && circle.getStatus() == 450){ + _mekadon.play(circle) + } + return true + } + } + } \ No newline at end of file diff --git a/public/src/js/game.js b/public/src/js/game.js index daa8c04..10f1e5c 100644 --- a/public/src/js/game.js +++ b/public/src/js/game.js @@ -118,6 +118,10 @@ function Game(controller, selectedSong, songData){ if(circle){ + if(controller.autoPlay(circle)){ + return + } + if(controller.getKeys()[86]){ if(!circle.getPlayed() && !controller.isWaitingForKeyup(86, "score") && circle.getStatus()!=-1){ var score = _this.checkScore(circle); diff --git a/public/src/js/keyboard.js b/public/src/js/keyboard.js index cac5bc5..a846934 100644 --- a/public/src/js/keyboard.js +++ b/public/src/js/keyboard.js @@ -8,35 +8,54 @@ function Keyboard(controller){ $(document).keydown(function(e){ - if (e.which === 8 && !$(e.target).is("input, textarea"))//disable back navigation when pressing backspace + if (e.which === 8 && !$(e.target).is("input, textarea")) + // Disable back navigation when pressing backspace e.preventDefault(); - _keys[e.which]=true; + if(_this.buttonEnabled(e.which)){ + _this.setKey(e.which, true); + } }); $(document).keyup(function(e){ - delete _keys[e.which]; - delete _waitKeyupScore[e.which]; - delete _waitKeyupSound[e.which]; - delete _waitKeyupMenu[e.which]; + if(_this.buttonEnabled(e.which)){ + _this.setKey(e.which, false); + } }); + this.buttonEnabled = function(keyCode){ + if(controller.autoPlay()){ + switch(keyCode){ + case 86: + case 66: + case 67: + case 78: + return false + } + } + return true + } + this.checkGameKeys = function(){ - if(_keys[86] && !_this.isWaitingForKeyup(86, "sound")){//if press v, play 'don' sound + if(_keys[86] && !_this.isWaitingForKeyup(86, "sound")){ + // V, play 'don' sound controller.playSound('note_don'); _this.waitForKeyup(86, "sound"); } - if(_keys[66] && !_this.isWaitingForKeyup(66, "sound")){//if press b, play 'don' sound + if(_keys[66] && !_this.isWaitingForKeyup(66, "sound")){ + // B, play 'don' sound controller.playSound('note_don'); _this.waitForKeyup(66, "sound"); } - if(_keys[67] && !_this.isWaitingForKeyup(67, "sound")){//if press c, play 'ka' sound + if(_keys[67] && !_this.isWaitingForKeyup(67, "sound")){ + // C, play 'ka' sound controller.playSound('note_ka'); _this.waitForKeyup(67, "sound"); } - if(_keys[78] && !_this.isWaitingForKeyup(78, "sound")){//if press n, play 'ka' sound + if(_keys[78] && !_this.isWaitingForKeyup(78, "sound")){ + // N, play 'ka' sound controller.playSound('note_ka'); _this.waitForKeyup(78, "sound"); } @@ -45,12 +64,14 @@ function Keyboard(controller){ this.checkMenuKeys = function(){ - if(_keys[8] && !_this.isWaitingForKeyup(8, "menu")){//If press return key, go back to song selection + if(_keys[8] && !_this.isWaitingForKeyup(8, "menu")){ + // Backspace, go back to song selection _this.waitForKeyup(8, "menu"); controller.pauseSound("main-music", true); controller.songSelection(); } - if(_keys[81] && !_this.isWaitingForKeyup(81, "menu")){//if press p key, pause the game + if(_keys[81] && !_this.isWaitingForKeyup(81, "menu")){ + // Q, pause the game _this.waitForKeyup(81, "menu"); controller.togglePauseMenu(); } @@ -61,6 +82,17 @@ function Keyboard(controller){ return _keys; } + this.setKey=function(keyCode, down){ + if(down){ + _keys[keyCode]=true; + }else{ + delete _keys[keyCode]; + delete _waitKeyupScore[keyCode]; + delete _waitKeyupSound[keyCode]; + delete _waitKeyupMenu[keyCode]; + } + } + this.isWaitingForKeyup = function(key, type){ var isWaiting; if(type == "score") isWaiting = _waitKeyupScore[key]; diff --git a/public/src/js/loadsong.js b/public/src/js/loadsong.js index 64834be..af9dc0b 100644 --- a/public/src/js/loadsong.js +++ b/public/src/js/loadsong.js @@ -1,4 +1,4 @@ -function loadSong(selectedSong){ +function loadSong(selectedSong, autoPlayEnabled){ var _this = this; var _selectedSong=selectedSong; @@ -46,7 +46,7 @@ function loadSong(selectedSong){ this.checkIfEverythingLoaded = function(){ if(_musicLoaded && _songDataLoaded && _bgLoaded){ $("#screen").load("/src/views/game.html", function(){ - var taikoGame = new Controller(_selectedSong, _songData); + var taikoGame = new Controller(_selectedSong, _songData, autoPlayEnabled); taikoGame.run(); }); } diff --git a/public/src/js/mekadon.js b/public/src/js/mekadon.js new file mode 100644 index 0000000..475e180 --- /dev/null +++ b/public/src/js/mekadon.js @@ -0,0 +1,43 @@ +class Mekadon{ + constructor(controller, game){ + this.controller = controller + this.game = game + this.lr = false + this.keys = {} + } + play(circle){ + if(circle.getType() == "don"){ + this.setKey(this.lr ? 86 : 66) + this.lr = !this.lr + }else if(circle.getType() == "daiDon"){ + this.setKey(86) + this.setKey(66) + this.lr = false + }else if(circle.getType() == "ka"){ + this.setKey(this.lr ? 67 : 78) + this.lr = !this.lr + }else if(circle.getType() == "daiKa"){ + this.setKey(67) + this.setKey(78) + this.lr = false + } + var score = this.game.checkScore(circle); + circle.played(score); + this.game.updateCurrentCircle(); + } + setKey(keyCode){ + var self = this + if(this.keys[keyCode]){ + clearTimeout(this.keys[keyCode]) + self.clearKey(keyCode) + } + this.controller.setKey(keyCode, true) + this.keys[keyCode] = setTimeout(function(){ + self.clearKey(keyCode) + },100) + } + clearKey(keyCode){ + this.controller.setKey(keyCode, false) + delete this.keys[keyCode] + } +} diff --git a/public/src/js/songselect.js b/public/src/js/songselect.js index 86d41d3..e46972b 100644 --- a/public/src/js/songselect.js +++ b/public/src/js/songselect.js @@ -62,7 +62,7 @@ function SongSelect(){ _selectedSong.folder = songID; bgm.pause(); - new loadSong(_selectedSong); + new loadSong(_selectedSong, e.shiftKey); }); $(".song").hover(function(){ diff --git a/public/src/js/soundsystem.js b/public/src/js/soundsystem.js index 295de8d..bf7e097 100644 --- a/public/src/js/soundsystem.js +++ b/public/src/js/soundsystem.js @@ -29,6 +29,10 @@ function soundSystem(controller){ } } + + this.pauseSound = function(){ + _sounds["main-music"].pause(); + } this.fadeOutMusic = function(){