« get me outta code hell

Interactivity - csb-game - Pixelly spin-off of the Command Synergy Battle system used in Final Fantasy XIII
summary refs log tree commit diff
path: root/index.js
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2018-08-09 18:47:02 -0300
committerFlorrie <towerofnix@gmail.com>2018-08-09 18:47:02 -0300
commit25a5879419cc1d6b2f93ca60d08fccb5759271c8 (patch)
tree8ca30949ef9a8e064baa6b1b9529c36cf4138ad9 /index.js
parent2bccb6c55da3997483054e0bbea89d01841955fe (diff)
Interactivity
Diffstat (limited to 'index.js')
-rw-r--r--index.js24
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)