Merge branch 'master' into optimize-rendering
This commit is contained in:
commit
04b58c30b4
44
index.js
44
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
|
||||
@ -577,7 +588,7 @@ window.onload = function () {
|
||||
let y = Math.floor(index / Maps.width)
|
||||
let x = Math.floor(index % Maps.height)
|
||||
var draw_tile = true
|
||||
|
||||
|
||||
if (tile === 1) {
|
||||
ctx.fillStyle = '#fdd'
|
||||
} else if (tile === 2) {
|
||||
@ -603,28 +614,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) {
|
||||
@ -733,6 +722,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) {
|
||||
|
Loading…
Reference in New Issue
Block a user