From 78c245d3e1604549ee5e4df1939f151f84d3aa13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ruben=20M=C3=BCller?= Date: Sun, 7 Dec 2014 17:08:31 +0100 Subject: [PATCH] HUD update --- src/hud.coffee | 75 +++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/src/hud.coffee b/src/hud.coffee index b6c1544..a791ea7 100644 --- a/src/hud.coffee +++ b/src/hud.coffee @@ -43,52 +43,57 @@ app.game.hud = app.layer.setPixel(resourcePanelColor, x, y) switch panelusage + when 'tile' + @showResources() when 'entity' #app.layer.drawRegion app.images.entities, currentSelectedTile.entity.sprite(), 44, 102 if currentSelectedTile.entity.isMoveable() app.layer.drawRegion @itemArrow.image, @itemArrow.sprite(), 44, 102 when 'resources' - # resources - i = 0 - for type, amount of app.game.resources - if amount > 0 - tileLayer = @resources[type] + @showResources() - spritePosition = { - x: i*9+@position.x - y: @position.y - } + showResources: -> + # resources + i = 0 + for type, amount of app.game.resources + if amount > 0 + tileLayer = @resources[type] - app.layer.drawRegion app.images.layers, tileLayer.hudSprite, spritePosition.x, spritePosition.y + spritePosition = { + x: i*9+@position.x + y: @position.y + } - amountByTwenty = Math.floor(amount/20) - amountLeft = amount - amountByTwenty*20 - for e in [0..amountLeft] - color = "#0a0" - color = "#0f0" if e == amountLeft + app.layer.drawRegion app.images.layers, tileLayer.hudSprite, spritePosition.x, spritePosition.y - 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 + amountByTwenty = Math.floor(amount/20) + amountLeft = amount - amountByTwenty*20 + for e in [0..amountLeft] + color = "#0a0" + color = "#0f0" if e == amountLeft - app.layer.setPixel(color, x, y) + 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 - for f in [0..amountByTwenty] - if f > 0 - color = "#0000ff" + app.layer.setPixel(color, x, y) - x = spritePosition.x-2+f - y = spritePosition.y+7 + for f in [0..amountByTwenty] + if f > 0 + color = "#0000ff" - app.layer.setPixel(color, x, y) + x = spritePosition.x-2+f + y = spritePosition.y+7 - i++ + app.layer.setPixel(color, x, y) + + i++