ld31-space-diggers/src/hud.coffee

61 lines
1.5 KiB
CoffeeScript
Raw Normal View History

2014-12-06 12:55:43 +01:00
app.game.hud =
2014-12-07 00:15:16 +01:00
start: ->
resTypes = (k for own k of app.game.resources)
2014-12-07 00:17:16 +01:00
@position = x: 45, y: 103
2014-12-07 00:15:16 +01:00
@resources = []
for restype, i in resTypes
@resources[restype] = new Tilelayer(
type: restype,
depth: i
)
2014-12-06 13:14:15 +01:00
render: ->
2014-12-07 00:17:16 +01:00
app.layer.drawImage app.images.hud, 0, 11*8
2014-12-07 00:15:16 +01:00
i = 0
2014-12-06 14:14:32 +01:00
for type, amount of app.game.resources
if amount > 0
2014-12-07 00:15:16 +01:00
#console.log @resources[type]
tileLayer = @resources[type]
spritePosition = {
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"
2014-12-07 00:46:38 +01:00
color = "#0f0" if e == amountLeft
2014-12-07 00:15:16 +01:00
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++