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)->
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

View file

@ -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++