Add autoplay mode

This commit is contained in:
LoveEevee 2018-08-28 02:56:31 +03:00
parent 97eee0e27a
commit 2f717614fb
9 changed files with 100 additions and 16 deletions

1
.gitignore vendored
View File

@ -42,4 +42,5 @@ Network Trash Folder
Temporary Items Temporary Items
.apdisk .apdisk
public/songs public/songs
public/api
taiko.db taiko.db

View File

@ -45,6 +45,7 @@
<script type='application/javascript' src='/src/js/main.js'></script> <script type='application/javascript' src='/src/js/main.js'></script>
<script type='application/javascript' src='/src/js/view.js'></script> <script type='application/javascript' src='/src/js/view.js'></script>
<script type='application/javascript' src='/src/js/bufferedloop.js'></script> <script type='application/javascript' src='/src/js/bufferedloop.js'></script>
<script type='application/javascript' src='/src/js/mekadon.js'></script>
</head> </head>
<body> <body>

View File

@ -81,10 +81,12 @@ class BufferedLoop{
},100) },100)
} }
pause(){ pause(){
var self=this
clearInterval(this.interval) clearInterval(this.interval)
this.sources.forEach(function(sourceObject){ this.sources.forEach(function(sourceObject){
sourceObject.source.stop(0) sourceObject.source.stop(0)
clearTimeout(sourceObject.timeout) clearTimeout(sourceObject.timeout)
self.sources.delete(sourceObject)
}) })
} }
} }

View File

@ -1,4 +1,4 @@
function Controller(selectedSong, songData){ function Controller(selectedSong, songData, autoPlayEnabled){
var _this = this; var _this = this;
var _backgroundURL = "/songs/"+selectedSong.folder+"/bg.png"; var _backgroundURL = "/songs/"+selectedSong.folder+"/bg.png";
@ -8,6 +8,7 @@ function Controller(selectedSong, songData){
var _game = new Game(this, selectedSong, _songData); var _game = new Game(this, selectedSong, _songData);
var _view = new View(this, _backgroundURL, selectedSong.title, selectedSong.difficulty); var _view = new View(this, _backgroundURL, selectedSong.title, selectedSong.difficulty);
var _mekadon = new Mekadon(this, _game);
var _keyboard = new Keyboard(this); var _keyboard = new Keyboard(this);
var _mainLoop; var _mainLoop;
var _pauseMenu = false; var _pauseMenu = false;
@ -165,6 +166,10 @@ function Controller(selectedSong, songData){
return _keyboard.getKeys(); return _keyboard.getKeys();
} }
this.setKey = function(keyCode, down){
return _keyboard.setKey(keyCode, down);
}
this.getSongData = function(){ this.getSongData = function(){
return _game.getSongData(); return _game.getSongData();
} }
@ -209,4 +214,13 @@ function Controller(selectedSong, songData){
_game.updateGlobalScore(score); _game.updateGlobalScore(score);
} }
this.autoPlay = function(circle){
if(autoPlayEnabled){
if(circle && circle.getStatus() == 450){
_mekadon.play(circle)
}
return true
}
}
} }

View File

@ -118,6 +118,10 @@ function Game(controller, selectedSong, songData){
if(circle){ if(circle){
if(controller.autoPlay(circle)){
return
}
if(controller.getKeys()[86]){ if(controller.getKeys()[86]){
if(!circle.getPlayed() && !controller.isWaitingForKeyup(86, "score") && circle.getStatus()!=-1){ if(!circle.getPlayed() && !controller.isWaitingForKeyup(86, "score") && circle.getStatus()!=-1){
var score = _this.checkScore(circle); var score = _this.checkScore(circle);

View File

@ -8,35 +8,41 @@ function Keyboard(controller){
$(document).keydown(function(e){ $(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(); e.preventDefault();
_keys[e.which]=true; if(!controller.autoPlay()){
_this.setKey(e.which, true);
}
}); });
$(document).keyup(function(e){ $(document).keyup(function(e){
delete _keys[e.which]; if(!controller.autoPlay()){
delete _waitKeyupScore[e.which]; _this.setKey(e.which, false);
delete _waitKeyupSound[e.which]; }
delete _waitKeyupMenu[e.which];
}); });
this.checkGameKeys = function(){ 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'); controller.playSound('note_don');
_this.waitForKeyup(86, "sound"); _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'); controller.playSound('note_don');
_this.waitForKeyup(66, "sound"); _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'); controller.playSound('note_ka');
_this.waitForKeyup(67, "sound"); _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'); controller.playSound('note_ka');
_this.waitForKeyup(78, "sound"); _this.waitForKeyup(78, "sound");
} }
@ -45,12 +51,14 @@ function Keyboard(controller){
this.checkMenuKeys = function(){ 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"); _this.waitForKeyup(8, "menu");
controller.pauseSound("main-music", true); controller.pauseSound("main-music", true);
controller.songSelection(); controller.songSelection();
} }
if(_keys[81] && !_this.isWaitingForKeyup(81, "menu")){//if press p key, pause the game if(_keys[81] && !_this.isWaitingForKeyup(81, "menu")){
// P, pause the game
_this.waitForKeyup(81, "menu"); _this.waitForKeyup(81, "menu");
controller.togglePauseMenu(); controller.togglePauseMenu();
} }
@ -61,6 +69,17 @@ function Keyboard(controller){
return _keys; 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){ this.isWaitingForKeyup = function(key, type){
var isWaiting; var isWaiting;
if(type == "score") isWaiting = _waitKeyupScore[key]; if(type == "score") isWaiting = _waitKeyupScore[key];

View File

@ -1,4 +1,4 @@
function loadSong(selectedSong){ function loadSong(selectedSong, autoPlayEnabled){
var _this = this; var _this = this;
var _selectedSong=selectedSong; var _selectedSong=selectedSong;
@ -46,7 +46,7 @@ function loadSong(selectedSong){
this.checkIfEverythingLoaded = function(){ this.checkIfEverythingLoaded = function(){
if(_musicLoaded && _songDataLoaded && _bgLoaded){ if(_musicLoaded && _songDataLoaded && _bgLoaded){
$("#screen").load("/src/views/game.html", function(){ $("#screen").load("/src/views/game.html", function(){
var taikoGame = new Controller(_selectedSong, _songData); var taikoGame = new Controller(_selectedSong, _songData, autoPlayEnabled);
taikoGame.run(); taikoGame.run();
}); });
} }

43
public/src/js/mekadon.js Normal file
View File

@ -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]
}
}

View File

@ -62,7 +62,7 @@ function SongSelect(){
_selectedSong.folder = songID; _selectedSong.folder = songID;
bgm.pause(); bgm.pause();
new loadSong(_selectedSong); new loadSong(_selectedSong, e.shiftKey);
}); });
$(".song").hover(function(){ $(".song").hover(function(){