Added ability to sell towers (right click)

This commit is contained in:
Taizo 'Tsa6' Simpson 2017-08-21 14:19:37 -04:00
parent 038a287e96
commit efa6939d05
1 changed files with 19 additions and 1 deletions

View File

@ -33,7 +33,8 @@ window.onload = function () {
pace: 1, pace: 1,
wave: 0, wave: 0,
waveTimer: 0, waveTimer: 0,
tower: 'simple' tower: 'simple',
sellRatio: .8
} }
/** /**
@ -533,6 +534,16 @@ window.onload = function () {
}, tower)) }, 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) { function update (dt) {
fpsCount++ fpsCount++
fpsCount %= 20 fpsCount %= 20
@ -729,6 +740,13 @@ window.onload = function () {
clickBtn() clickBtn()
}) })
canvas.addEventListener('contextmenu', (e) => {
if (Game.state === 2 && mX < Maps.width && mY < Maps.height &&
sellTower(mX, mY)) {
e.preventDefault()
}
})
canvas.addEventListener('mousemove', (e) => { canvas.addEventListener('mousemove', (e) => {
if (e.changedTouches) { if (e.changedTouches) {