« get me outta code hell

Grayscale entire UI after win - csb-game - Pixelly spin-off of the Command Synergy Battle system used in Final Fantasy XIII
summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2018-08-12 14:37:43 -0300
committerFlorrie <towerofnix@gmail.com>2018-08-12 14:37:43 -0300
commit02a7a799e2206ecc09dd84e1d6c595475871fad2 (patch)
tree22b6112ad5f8a7cccc2a2f0385938ee1b2e58dee
parentd0dbe2c0548cf6fc539dcb34df3416dc2cdf5db1 (diff)
Grayscale entire UI after win
-rw-r--r--index.js14
1 files changed, 10 insertions, 4 deletions
diff --git a/index.js b/index.js
index c9cc7a9..7665129 100644
--- a/index.js
+++ b/index.js
@@ -528,7 +528,7 @@ class Battle {
 
     // State
 
-    this.gameState = 'battle' // battle, pre-win
+    this.gameState = 'battle' // battle, pre-win, win
 
     this.currentMenu = this.actionMenu
     this.changeMenuAnim = {time: 1, direction: 1, old: null}
@@ -586,8 +586,8 @@ class Battle {
     y -= oldOffset + (targetOffset - oldOffset) * (this.changeMenuAnim ? 1 - this.changeMenuAnim.time : 1)
     y -= 2
     ctx.save()
-    if (this.preWinAnim) {
-      const { time } = this.preWinAnim
+    if (this.preWinAnim || this.gameState === 'win') {
+      const { time } = this.preWinAnim || {time: 0}
       ctx.translate(0, Math.floor(-20 * (time - 1)))
       ctx.filter = `opacity(${time * 100}%)`
     }
@@ -643,7 +643,8 @@ class Battle {
   preWinUpdate(dt) {
     this.preWinAnim.time -= dt * 3
     if (this.preWinAnim.time <= 0) {
-      this.preWinAnim.time = null
+      this.preWinAnim = null
+      this.gameState = 'win'
     }
   }
 
@@ -744,6 +745,11 @@ function drawLoop() {
   ctx.fillRect(0, 0, canvas.width, canvas.height)
 
   battle.draw()
+  if (battle.preWinAnim) {
+    ctx.filter = `grayscale(${(1 - battle.preWinAnim.time) * 100}%)`
+  } else if (battle.gameState === 'win') {
+    ctx.filter = 'grayscale(100%)'
+  }
   ctx.drawImage(battle.canvas, 0, 0)
 
   requestAnimationFrame(drawLoop)