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 | |
parent | 2bccb6c55da3997483054e0bbea89d01841955fe (diff) |
Interactivity
-rw-r--r-- | index.html | 2 | ||||
-rw-r--r-- | index.js | 24 |
2 files changed, 25 insertions, 1 deletions
diff --git a/index.html b/index.html index 61618d9..5c636b0 100644 --- a/index.html +++ b/index.html @@ -16,5 +16,5 @@ canvas { } </style> Nice. -<canvas id="canvas"></canvas> +<canvas id="canvas" tabindex="1"></canvas> <script src="index.js"></script> 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) |