sell text
This commit is contained in:
parent
700adb228c
commit
3f8e517a2d
31
index.js
31
index.js
@ -26,6 +26,7 @@ window.onload = function () {
|
|||||||
enemies: [],
|
enemies: [],
|
||||||
towers: [],
|
towers: [],
|
||||||
particles: [],
|
particles: [],
|
||||||
|
selltext: [],
|
||||||
map: null,
|
map: null,
|
||||||
health: 100,
|
health: 100,
|
||||||
money: 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
|
// 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
|
// Local (in-function) determines how many there are left to spawn as ordered by the function call
|
||||||
function addEnemies (cnt, type) {
|
function addEnemies (cnt, type) {
|
||||||
@ -537,7 +551,14 @@ window.onload = function () {
|
|||||||
function sellTower (x, y) {
|
function sellTower (x, y) {
|
||||||
var tower = getTowerAt(x, y)
|
var tower = getTowerAt(x, y)
|
||||||
if(tower) {
|
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)
|
return Game.towers.splice(Game.towers.indexOf(tower), 1)
|
||||||
}else{
|
}else{
|
||||||
return null
|
return null
|
||||||
@ -554,6 +575,7 @@ window.onload = function () {
|
|||||||
tickTowers()
|
tickTowers()
|
||||||
updateEnemyMovements()
|
updateEnemyMovements()
|
||||||
tickParticles()
|
tickParticles()
|
||||||
|
tickSellText()
|
||||||
|
|
||||||
for (let i in Components) {
|
for (let i in Components) {
|
||||||
let btn = Components[i]
|
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.fillStyle = '#996633'
|
||||||
ctx.fillRect(640, 0, 240, 640)
|
ctx.fillRect(640, 0, 240, 640)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user