diff options
author | Florrie <towerofnix@gmail.com> | 2018-08-09 18:47:02 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2018-08-09 18:47:02 -0300 |
commit | 25a5879419cc1d6b2f93ca60d08fccb5759271c8 (patch) | |
tree | 8ca30949ef9a8e064baa6b1b9529c36cf4138ad9 /index.js | |
parent | 2bccb6c55da3997483054e0bbea89d01841955fe (diff) |
Interactivity
Diffstat (limited to 'index.js')
-rw-r--r-- | index.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/index.js b/index.js index 7f73c5d..0d00cab 100644 --- a/index.js +++ b/index.js @@ -143,6 +143,22 @@ class ActionMenu { getRectW(level) { return Math.floor((this.canvas.width - 2) / 3 * level) } + + downOption() { + this.currentOptionIndex++ + + if (this.currentOptionIndex >= this.options.length) { + this.currentOptionIndex = 0 + } + } + + upOption() { + this.currentOptionIndex-- + + if (this.currentOptionIndex <= -1) { + this.currentOptionIndex = this.options.length - 1 + } + } } const atbBar = new ATBBar() @@ -171,4 +187,12 @@ function drawLoop() { requestAnimationFrame(drawLoop) } +canvas.addEventListener('keypress', evt => { + if (evt.keyCode === 38) { + actionMenu.upOption() + } else if (evt.keyCode === 40) { + actionMenu.downOption() + } +}) + requestAnimationFrame(drawLoop) |