HUD improvements
This commit is contained in:
parent
c4ba7c582b
commit
56396ba979
3 changed files with 58 additions and 7 deletions
|
@ -9,6 +9,8 @@ app.game =
|
||||||
# Start the game tick
|
# Start the game tick
|
||||||
window.setInterval(@tick, 1000)
|
window.setInterval(@tick, 1000)
|
||||||
|
|
||||||
|
@hud.start()
|
||||||
|
|
||||||
render: ->
|
render: ->
|
||||||
for tile, i in @map
|
for tile, i in @map
|
||||||
y = Math.floor(i/20)
|
y = Math.floor(i/20)
|
||||||
|
|
|
@ -1,11 +1,59 @@
|
||||||
app.game.hud =
|
app.game.hud =
|
||||||
|
start: ->
|
||||||
|
resTypes = (k for own k of app.game.resources)
|
||||||
|
|
||||||
|
@position = x: 64, y: 107
|
||||||
|
|
||||||
|
@resources = []
|
||||||
|
for restype, i in resTypes
|
||||||
|
@resources[restype] = new Tilelayer(
|
||||||
|
type: restype,
|
||||||
|
depth: i
|
||||||
|
)
|
||||||
|
|
||||||
render: ->
|
render: ->
|
||||||
app.layer.drawImage app.images.hud, 0, 12*8+2
|
app.layer.drawImage app.images.hud, 0, 12*8+4
|
||||||
posy = 15
|
|
||||||
|
i = 0
|
||||||
for type, amount of app.game.resources
|
for type, amount of app.game.resources
|
||||||
if amount > 0
|
if amount > 0
|
||||||
app.layer
|
#console.log @resources[type]
|
||||||
.fillStyle "#000"
|
tileLayer = @resources[type]
|
||||||
.font "10px Arial"
|
|
||||||
.wrappedText(amount+" x "+type, 5, posy, 800)
|
spritePosition = {
|
||||||
posy += 10
|
x: i*9+@position.x
|
||||||
|
y: @position.y
|
||||||
|
}
|
||||||
|
|
||||||
|
app.layer.drawRegion app.images.layers, tileLayer.hudSprite, spritePosition.x, spritePosition.y
|
||||||
|
|
||||||
|
amountByTwenty = Math.floor(amount/20)
|
||||||
|
amountLeft = amount - amountByTwenty*20
|
||||||
|
for e in [0..amountLeft]
|
||||||
|
color = "#0a0"
|
||||||
|
|
||||||
|
if e < 6
|
||||||
|
x = spritePosition.x-1+e
|
||||||
|
y = spritePosition.y-1
|
||||||
|
else if e < 10
|
||||||
|
x = spritePosition.x+4
|
||||||
|
y = spritePosition.y-1+e-5
|
||||||
|
else if e < 15
|
||||||
|
x = spritePosition.x+14-e
|
||||||
|
y = spritePosition.y+4
|
||||||
|
else
|
||||||
|
x = spritePosition.x-1
|
||||||
|
y = spritePosition.y+19-e
|
||||||
|
|
||||||
|
app.layer.setPixel(color, x, y)
|
||||||
|
|
||||||
|
for f in [0..amountByTwenty]
|
||||||
|
if f > 0
|
||||||
|
color = "#0000ff"
|
||||||
|
|
||||||
|
x = spritePosition.x-2+f
|
||||||
|
y = spritePosition.y+7
|
||||||
|
|
||||||
|
app.layer.setPixel(color, x, y)
|
||||||
|
|
||||||
|
i++
|
||||||
|
|
|
@ -3,6 +3,7 @@ class Tilelayer
|
||||||
{@type, @depth, @amount} = options
|
{@type, @depth, @amount} = options
|
||||||
@randomFactor = getRandomInt 0, 4
|
@randomFactor = getRandomInt 0, 4
|
||||||
@sprite = [@randomFactor*8, @depth*8, 8, 8]
|
@sprite = [@randomFactor*8, @depth*8, 8, 8]
|
||||||
|
@hudSprite = [@randomFactor*8, @depth*8, 4, 4]
|
||||||
|
|
||||||
collect: ->
|
collect: ->
|
||||||
return false if @amount == 0
|
return false if @amount == 0
|
||||||
|
|
Loading…
Reference in a new issue