From 3f8e517a2d495689f5e4137b4cdc761dc7d53f18 Mon Sep 17 00:00:00 2001 From: Evert Date: Tue, 22 Aug 2017 11:09:55 +0300 Subject: [PATCH] sell text --- index.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 1a3e4f2..0cca728 100644 --- a/index.js +++ b/index.js @@ -26,6 +26,7 @@ window.onload = function () { enemies: [], towers: [], particles: [], + selltext: [], map: null, health: 100, money: 100, @@ -448,6 +449,19 @@ window.onload = function () { } } + function tickSellText () { + for (let i in Game.selltext) { + let txt = Game.selltext[i] + txt.tick++ + txt.tick %= 30 + if (txt.tick === 0) { + Game.selltext.splice(i, 1) + } + + txt.y -= 0.05 + } + } + // Total enemy spawn count is used to determine that the round is over // Local (in-function) determines how many there are left to spawn as ordered by the function call function addEnemies (cnt, type) { @@ -537,7 +551,14 @@ window.onload = function () { function sellTower (x, y) { var tower = getTowerAt(x, y) if(tower) { - Game.money += tower.cost * Game.sellRatio + let amount = tower.cost * Game.sellRatio + Game.money += amount + Game.selltext.push({ + x: x, + y: y, + amount: amount, + tick: 0 + }) return Game.towers.splice(Game.towers.indexOf(tower), 1) }else{ return null @@ -554,6 +575,7 @@ window.onload = function () { tickTowers() updateEnemyMovements() tickParticles() + tickSellText() for (let i in Components) { let btn = Components[i] @@ -660,6 +682,13 @@ window.onload = function () { } } + for (let i in Game.selltext) { + let txt = Game.selltext[i] + ctx.font = '12px Helvetica' + ctx.fillStyle = '#0f0' + ctx.fillText('+ $' + txt.amount, txt.x * mt, txt.y * mt) + } + ctx.fillStyle = '#996633' ctx.fillRect(640, 0, 240, 640)