Work on HUD

This commit is contained in:
Ruben Müller 2014-12-07 13:42:45 +01:00
parent 3f8532a830
commit 1ce34f3472
2 changed files with 52 additions and 41 deletions

View file

@ -22,12 +22,17 @@ app.game =
mousedown: (event)-> mousedown: (event)->
if @isMouseInView event.x, event.y if @isMouseInView event.x, event.y
tile = posToTile(event.x, event.y) switch event.button
tile.click(event.button) when 'left'
tile = posToTile(event.x, event.y)
tile.click(event.button)
@currentSelectedTile.deselect() if @currentSelectedTile @currentSelectedTile.deselect() if @currentSelectedTile
tile.select() tile.select()
@currentSelectedTile = tile @currentSelectedTile = tile
when 'right'
@currentSelectedTile.deselect() if @currentSelectedTile
@currentSelectedTile = null
mousemove: (event)-> mousemove: (event)->
if @isMouseInView event.x, event.y if @isMouseInView event.x, event.y

View file

@ -12,6 +12,8 @@ app.game.hud =
) )
render: -> render: ->
panelusage = 'resources'
app.layer.drawImage app.images.hud, 0, 11*8 app.layer.drawImage app.images.hud, 0, 11*8
currentSelectedTile = app.game.currentSelectedTile currentSelectedTile = app.game.currentSelectedTile
@ -19,11 +21,11 @@ app.game.hud =
app.layer.drawRegion app.images.layers, currentSelectedTile.getCurrentLayer().sprite, 15, 100 app.layer.drawRegion app.images.layers, currentSelectedTile.getCurrentLayer().sprite, 15, 100
if currentSelectedTile.entity if currentSelectedTile.entity
panelusage = 'entity'
app.layer.drawRegion app.images.entities, currentSelectedTile.entity.sprite(), 15, 100 app.layer.drawRegion app.images.entities, currentSelectedTile.entity.sprite(), 15, 100
# silo capacity # silo capacity
usedSiloStoragePercent = (100 / app.game.availableSiloStorage()) * app.game.usedSiloStorage() usedSiloStoragePercent = (100 / app.game.availableSiloStorage()) * app.game.usedSiloStorage()
for f in [0..100] for f in [0..100]
color = "#333" color = "#333"
color = "#fff" if f < usedSiloStoragePercent color = "#fff" if f < usedSiloStoragePercent
@ -33,47 +35,51 @@ app.game.hud =
app.layer.setPixel(color, x, y) app.layer.setPixel(color, x, y)
# resources switch panelusage
i = 0 when 'entity'
for type, amount of app.game.resources app.layer.drawRegion app.images.entities, currentSelectedTile.entity.sprite(), 44, 102
if amount > 0 when 'resources'
tileLayer = @resources[type] # resources
i = 0
for type, amount of app.game.resources
if amount > 0
tileLayer = @resources[type]
spritePosition = { spritePosition = {
x: i*9+@position.x x: i*9+@position.x
y: @position.y y: @position.y
} }
app.layer.drawRegion app.images.layers, tileLayer.hudSprite, spritePosition.x, spritePosition.y app.layer.drawRegion app.images.layers, tileLayer.hudSprite, spritePosition.x, spritePosition.y
amountByTwenty = Math.floor(amount/20) amountByTwenty = Math.floor(amount/20)
amountLeft = amount - amountByTwenty*20 amountLeft = amount - amountByTwenty*20
for e in [0..amountLeft] for e in [0..amountLeft]
color = "#0a0" color = "#0a0"
color = "#0f0" if e == amountLeft color = "#0f0" if e == amountLeft
if e < 6 if e < 6
x = spritePosition.x-1+e x = spritePosition.x-1+e
y = spritePosition.y-1 y = spritePosition.y-1
else if e < 10 else if e < 10
x = spritePosition.x+4 x = spritePosition.x+4
y = spritePosition.y-1+e-5 y = spritePosition.y-1+e-5
else if e < 15 else if e < 15
x = spritePosition.x+14-e x = spritePosition.x+14-e
y = spritePosition.y+4 y = spritePosition.y+4
else else
x = spritePosition.x-1 x = spritePosition.x-1
y = spritePosition.y+19-e y = spritePosition.y+19-e
app.layer.setPixel(color, x, y) app.layer.setPixel(color, x, y)
for f in [0..amountByTwenty] for f in [0..amountByTwenty]
if f > 0 if f > 0
color = "#0000ff" color = "#0000ff"
x = spritePosition.x-2+f x = spritePosition.x-2+f
y = spritePosition.y+7 y = spritePosition.y+7
app.layer.setPixel(color, x, y) app.layer.setPixel(color, x, y)
i++ i++