« get me outta code hell

Misc. tweaks - 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-23 21:39:39 -0300
committerFlorrie <towerofnix@gmail.com>2018-08-23 21:39:39 -0300
commitbe012d6f2664d52e47d222877eb22f7ab221d02f (patch)
treec8cbc896620ce3cc4defe1ab9ddd098613c64935 /index.js
parentbb8ef46f885fafa97b1d3ab8c2bf890dc9748a8e (diff)
Misc. tweaks
Diffstat (limited to 'index.js')
-rw-r--r--index.js31
1 files changed, 22 insertions, 9 deletions
diff --git a/index.js b/index.js
index da94468..30e17cc 100644
--- a/index.js
+++ b/index.js
@@ -759,7 +759,7 @@ class BattleCharacter extends Sprite {
     }
 
     if (this.targetCharacter) {
-      this.battle.animationEntities.push(new MagicProjectile(this, this.targetCharacter, action))
+      this.battle.miscSprites.push(new MagicProjectile(this, this.targetCharacter, action))
     }
   }
 
@@ -879,7 +879,7 @@ class Battle {
 
     this.slideacrossMessage = new SlideacrossMessage()
 
-    this.animationEntities = []
+    this.miscSprites = []
 
     this.canvas = document.createElement('canvas')
 
@@ -926,8 +926,13 @@ class Battle {
       }
     }
 
+    const allSprites = [this.backdrop, ...this.getAllBattleCharacters(), ...this.miscSprites]
+    allSprites.sort((a, b) => {
+      return a.z < b.z ? 1 : a.z > b.z ? -1 : 0
+    })
+
     const spriteData = []
-    for (const sprite of [this.backdrop, ...this.getAllBattleCharacters(), ...this.animationEntities]) {
+    for (const sprite of allSprites) {
       sprite.draw()
 
       const cameraOffsetX = sprite.x - camera.x
@@ -1131,11 +1136,11 @@ class Battle {
       }
     }
 
-    for (const entity of this.animationEntities) {
+    for (const entity of this.miscSprites) {
       entity.update(dt)
     }
 
-    this.animationEntities = this.animationEntities.filter(e => !e.discarded)
+    this.miscSprites = this.miscSprites.filter(e => !e.discarded)
 
     this.slideacrossMessage.update(dt)
 
@@ -1452,11 +1457,11 @@ const basicAI = function() {
 const battle = new Battle({
   teamData: [
     {characterData: [
-      {x: 0, y: 0, name: 'Ren', hp: 400, maxHP: 400, knownActions: ['fire', 'fira', 'firaga', 'blizz', 'blizzara', 'cure'], determineChain: basicAI},
-      {x: -100, y: 0, name: 'Fie', hp: 375, maxHP: 375, knownActions: ['fire', 'blizz', 'blizzara', 'blizzaga', 'aqua', 'aquara', 'curasa'], determineChain: basicAI}
+      {x: -50, y: 30, name: 'Ren', hp: 400, maxHP: 400, knownActions: ['fire', 'fira', 'firaga', 'blizz', 'blizzara', 'cure'], determineChain: basicAI},
+      {x: -75, y: 30, name: 'Fie', hp: 375, maxHP: 375, knownActions: ['fire', 'blizz', 'blizzara', 'blizzaga', 'aqua', 'aquara', 'curasa'], determineChain: basicAI}
     ]},
     {characterData: [
-      {x: 0, y: -100, name: 'Manasvin Warmech', hp: 1200, maxHP: 1200, knownActions: ['aqua', 'aquaga', 'manasvinSwipe', 'manasvinRecover'], determineChain: basicAI, knockbackMultiplier: 0}
+      {x: 75, y: 40, name: 'Manasvin Warmech', hp: 1200, maxHP: 1200, knownActions: ['aqua', 'aquaga', 'manasvinSwipe', 'manasvinRecover'], determineChain: basicAI, knockbackMultiplier: 0}
     ]}
   ]
 })
@@ -1473,10 +1478,18 @@ camera.x = 0
 camera.y = 0
 camera.z = 0
 
+for (let i = 0; i < 5 + 10 * Math.random(); i++) {
+  const sprite = new Sprite()
+  sprite.x = (Math.random() - 0.5) * 200
+  sprite.z = (Math.random() - 0.5) * 20
+  sprite.image.src = `img/bbbush${(i % 2) + 1}.png`
+  battle.miscSprites.push(sprite)
+}
+
 battle.canvas.width = canvas.width
 battle.canvas.height = canvas.height
 
-battle.backdrop.y = 0
+battle.backdrop.z = 80
 
 let lastTime = Date.now()