From 323333172238878514ce130eec43ecfb71364516 Mon Sep 17 00:00:00 2001 From: Taizo 'Tsa6' Simpson Date: Mon, 21 Aug 2017 16:12:20 -0400 Subject: [PATCH 1/4] Fix overlap in the "tower placement restriction visualization" by drawing it for each tile, instead of for each tower --- index.js | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/index.js b/index.js index e3b580e..122eeeb 100644 --- a/index.js +++ b/index.js @@ -575,7 +575,7 @@ window.onload = function () { let index = parseInt(i) let y = Math.floor(index / Maps.width) let x = Math.floor(index % Maps.height) - + if (tile === 1) { ctx.fillStyle = '#fdd' } else if (tile === 2) { @@ -587,6 +587,11 @@ window.onload = function () { } ctx.fillRect(x * mt, y * mt, mt, mt) + + if(tile != 1 && !getTowerAt(x, y) && !canPlaceTowerAt(x, y)) { + ctx.fillStyle = 'rgba(255, 0, 0, 0.45)' + ctx.fillRect(x * mt, y * mt, mt, mt) + } } /* for (let i in Game.map.pathgen) { @@ -599,28 +604,6 @@ window.onload = function () { let tower = Game.towers[i] ctx.fillStyle = tower.icon ctx.fillRect(tower.x * mt + 2, tower.y * mt + 2, 28, 28) - - if (Game.state === 2 && Game.tower) { - // tower placement restriction visualization - for (let i = 0; i < 4; i++) { - let ax = tower.x - let ay = tower.y - if (i == 0) { - ax -= 1 - } else if (i == 1) { - ax += 1 - } else if (i == 2) { - ay -= 1 - } else if (i == 3) { - ay += 1 - } - - if (ax < 0 || ay < 0 || ay > Maps.height || ax > Maps.width) continue - if (getTileIn(Game.map.tiles, ax, ay) !== 0) continue - ctx.fillStyle = 'rgba(255, 0, 0, 0.45)' - ctx.fillRect(ax * mt, ay * mt, mt, mt) - } - } } for (let i in Game.enemies) { From efa6939d054adf9b7ffa20e7725982ec183cfd6d Mon Sep 17 00:00:00 2001 From: Taizo 'Tsa6' Simpson Date: Mon, 21 Aug 2017 14:19:37 -0400 Subject: [PATCH 2/4] 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) { From dcf51a74ae461012f992f903c31c7aa61d22fccf Mon Sep 17 00:00:00 2001 From: Taizo 'Tsa6' Simpson Date: Mon, 21 Aug 2017 17:02:21 -0400 Subject: [PATCH 3/4] Hide tower restriction visualization when not in build phase --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 122eeeb..d983944 100644 --- a/index.js +++ b/index.js @@ -588,7 +588,7 @@ window.onload = function () { ctx.fillRect(x * mt, y * mt, mt, mt) - if(tile != 1 && !getTowerAt(x, y) && !canPlaceTowerAt(x, y)) { + if(Game.state == 2 && tile != 1 && !getTowerAt(x, y) && !canPlaceTowerAt(x, y)) { ctx.fillStyle = 'rgba(255, 0, 0, 0.45)' ctx.fillRect(x * mt, y * mt, mt, mt) } From c66fcf217e930c98ec9d565d7321de94619e5290 Mon Sep 17 00:00:00 2001 From: Taizo 'Tsa6' Simpson Date: Mon, 21 Aug 2017 17:07:46 -0400 Subject: [PATCH 4/4] Fixed visualization showing on some non-grass tiles --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index d983944..dc4fe6a 100644 --- a/index.js +++ b/index.js @@ -588,7 +588,7 @@ window.onload = function () { ctx.fillRect(x * mt, y * mt, mt, mt) - if(Game.state == 2 && tile != 1 && !getTowerAt(x, y) && !canPlaceTowerAt(x, y)) { + if(Game.state == 2 && tile == 0 && !getTowerAt(x, y) && !canPlaceTowerAt(x, y)) { ctx.fillStyle = 'rgba(255, 0, 0, 0.45)' ctx.fillRect(x * mt, y * mt, mt, mt) }