From efa6939d054adf9b7ffa20e7725982ec183cfd6d Mon Sep 17 00:00:00 2001 From: Taizo 'Tsa6' Simpson Date: Mon, 21 Aug 2017 14:19:37 -0400 Subject: [PATCH] Added ability to sell towers (right click) --- index.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index e3b580e..6521cbe 100644 --- a/index.js +++ b/index.js @@ -33,7 +33,8 @@ window.onload = function () { pace: 1, wave: 0, waveTimer: 0, - tower: 'simple' + tower: 'simple', + sellRatio: .8 } /** @@ -533,6 +534,16 @@ window.onload = function () { }, tower)) } + function sellTower (x, y) { + var tower = getTowerAt(x, y) + if(tower) { + Game.money += tower.cost * Game.sellRatio + return Game.towers.splice(Game.towers.indexOf(tower), 1) + }else{ + return null + } + } + function update (dt) { fpsCount++ fpsCount %= 20 @@ -729,6 +740,13 @@ window.onload = function () { clickBtn() }) + + canvas.addEventListener('contextmenu', (e) => { + if (Game.state === 2 && mX < Maps.width && mY < Maps.height && + sellTower(mX, mY)) { + e.preventDefault() + } + }) canvas.addEventListener('mousemove', (e) => { if (e.changedTouches) {