From 25a5879419cc1d6b2f93ca60d08fccb5759271c8 Mon Sep 17 00:00:00 2001 From: Florrie Date: Thu, 9 Aug 2018 18:47:02 -0300 Subject: Interactivity --- index.html | 2 +- index.js | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 61618d9..5c636b0 100644 --- a/index.html +++ b/index.html @@ -16,5 +16,5 @@ canvas { } Nice. - + 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) -- cgit 1.3.0-6-gf8a5