From 1ce34f347270e8cdff34926de270d1abdec7495c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ruben=20M=C3=BCller?= Date: Sun, 7 Dec 2014 13:42:45 +0100 Subject: [PATCH] Work on HUD --- src/game.coffee | 15 ++++++---- src/hud.coffee | 78 ++++++++++++++++++++++++++----------------------- 2 files changed, 52 insertions(+), 41 deletions(-) diff --git a/src/game.coffee b/src/game.coffee index 94a6324..f0f9c24 100644 --- a/src/game.coffee +++ b/src/game.coffee @@ -22,12 +22,17 @@ app.game = mousedown: (event)-> if @isMouseInView event.x, event.y - tile = posToTile(event.x, event.y) - tile.click(event.button) + switch event.button + when 'left' + tile = posToTile(event.x, event.y) + tile.click(event.button) - @currentSelectedTile.deselect() if @currentSelectedTile - tile.select() - @currentSelectedTile = tile + @currentSelectedTile.deselect() if @currentSelectedTile + tile.select() + @currentSelectedTile = tile + when 'right' + @currentSelectedTile.deselect() if @currentSelectedTile + @currentSelectedTile = null mousemove: (event)-> if @isMouseInView event.x, event.y diff --git a/src/hud.coffee b/src/hud.coffee index b1dbe71..b059f05 100644 --- a/src/hud.coffee +++ b/src/hud.coffee @@ -12,6 +12,8 @@ app.game.hud = ) render: -> + panelusage = 'resources' + app.layer.drawImage app.images.hud, 0, 11*8 currentSelectedTile = app.game.currentSelectedTile @@ -19,11 +21,11 @@ app.game.hud = app.layer.drawRegion app.images.layers, currentSelectedTile.getCurrentLayer().sprite, 15, 100 if currentSelectedTile.entity + panelusage = 'entity' app.layer.drawRegion app.images.entities, currentSelectedTile.entity.sprite(), 15, 100 # silo capacity usedSiloStoragePercent = (100 / app.game.availableSiloStorage()) * app.game.usedSiloStorage() - for f in [0..100] color = "#333" color = "#fff" if f < usedSiloStoragePercent @@ -33,47 +35,51 @@ app.game.hud = app.layer.setPixel(color, x, y) - # resources - i = 0 - for type, amount of app.game.resources - if amount > 0 - tileLayer = @resources[type] + switch panelusage + when 'entity' + app.layer.drawRegion app.images.entities, currentSelectedTile.entity.sprite(), 44, 102 + when 'resources' + # resources + i = 0 + for type, amount of app.game.resources + if amount > 0 + tileLayer = @resources[type] - spritePosition = { - x: i*9+@position.x - y: @position.y - } + spritePosition = { + x: i*9+@position.x + 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) - amountLeft = amount - amountByTwenty*20 - for e in [0..amountLeft] - color = "#0a0" - color = "#0f0" if e == amountLeft + amountByTwenty = Math.floor(amount/20) + amountLeft = amount - amountByTwenty*20 + for e in [0..amountLeft] + color = "#0a0" + color = "#0f0" if e == amountLeft - 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 + 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) + app.layer.setPixel(color, x, y) - for f in [0..amountByTwenty] - if f > 0 - color = "#0000ff" + for f in [0..amountByTwenty] + if f > 0 + color = "#0000ff" - x = spritePosition.x-2+f - y = spritePosition.y+7 + x = spritePosition.x-2+f + y = spritePosition.y+7 - app.layer.setPixel(color, x, y) + app.layer.setPixel(color, x, y) - i++ + i++