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 17:21:58 +01:00
|
|
|
@buildinfo = false
|
2014-12-07 00:15:16 +01:00
|
|
|
|
2014-12-07 15:13:19 +01:00
|
|
|
@itemArrow = new AnimatedItem maxFrames: 10, image: app.images.actions, speed: 50
|
2014-12-07 14:02:42 +01:00
|
|
|
|
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 13:42:45 +01:00
|
|
|
panelusage = 'resources'
|
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
|
|
|
|
2014-12-07 18:53:30 +01:00
|
|
|
app.layer.drawImage app.images.info, 143, 95
|
|
|
|
|
2014-12-07 18:12:47 +01:00
|
|
|
# cursor
|
2014-12-07 18:14:12 +01:00
|
|
|
# app.layer.drawImage app.images.cursor, app.game.mouseX, app.game.mouseY
|
2014-12-07 18:12:47 +01:00
|
|
|
|
2014-12-07 17:21:58 +01:00
|
|
|
if @buildinfo
|
|
|
|
app.layer.drawRegion app.images.buildinfo, [0, 0, 106, 10], 1, 1
|
|
|
|
app.layer.drawRegion app.images.buildinfo, [0, 10, 106, 10], 1, 12
|
|
|
|
app.layer.drawRegion app.images.buildinfo, [0, 20, 106, 10], 1, 23
|
2014-12-07 17:57:33 +01:00
|
|
|
app.layer.drawRegion app.images.buildinfo, [0, 30, 106, 10], 1, 34
|
2014-12-07 17:21:58 +01:00
|
|
|
|
2014-12-07 13:32:10 +01:00
|
|
|
currentSelectedTile = app.game.currentSelectedTile
|
|
|
|
if currentSelectedTile != null
|
2014-12-07 15:13:19 +01:00
|
|
|
panelusage = 'tile'
|
|
|
|
|
2014-12-07 13:32:10 +01:00
|
|
|
if currentSelectedTile.entity
|
2014-12-07 13:42:45 +01:00
|
|
|
panelusage = 'entity'
|
2014-12-07 17:04:40 +01:00
|
|
|
app.layer.drawRegion app.images.entitydetails, currentSelectedTile.entity.spritedetail(), 12, 95
|
|
|
|
else
|
|
|
|
app.layer.drawRegion app.images.layerdetails, currentSelectedTile.getCurrentLayer().spritedetail, 12, 95
|
2014-12-07 01:08:39 +01:00
|
|
|
|
|
|
|
# silo capacity
|
2014-12-07 15:13:19 +01:00
|
|
|
usedSiloStoragePercent = Math.round((100 / app.game.availableSiloStorage()) * app.game.usedSiloStorage())
|
2014-12-07 01:08:39 +01:00
|
|
|
for f in [0..100]
|
2014-12-07 15:13:19 +01:00
|
|
|
resourcePanelColor = "#333"
|
|
|
|
|
|
|
|
if f <= usedSiloStoragePercent
|
|
|
|
colorStep = Math.round((usedSiloStoragePercent/100)*5)
|
|
|
|
resourcePanelColor = ["#0a0", "#0a0", "#aa0", "#f60", "#a00", "#f00"][colorStep]
|
2014-12-07 01:08:39 +01:00
|
|
|
|
|
|
|
x = 44+f
|
|
|
|
y = 112
|
2014-12-07 15:13:19 +01:00
|
|
|
app.layer.setPixel(resourcePanelColor, x, y)
|
2014-12-07 01:08:39 +01:00
|
|
|
|
2014-12-07 18:37:04 +01:00
|
|
|
# Energy production (47)
|
|
|
|
|
2014-12-07 18:39:37 +01:00
|
|
|
length = Math.round(((25*app.game.solarpanelCount())*45)/100)
|
2014-12-07 18:37:04 +01:00
|
|
|
for i in [0..length]
|
|
|
|
app.layer.setPixel("#228ca5", 49+i, 91)
|
|
|
|
app.layer.setPixel("#8ddaed", 50+i, 92)
|
|
|
|
app.layer.setPixel("#228ca5", 49+i, 93)
|
|
|
|
|
2014-12-07 13:42:45 +01:00
|
|
|
switch panelusage
|
2014-12-07 17:08:31 +01:00
|
|
|
when 'tile'
|
|
|
|
@showResources()
|
2014-12-07 13:42:45 +01:00
|
|
|
when 'entity'
|
2014-12-07 14:02:42 +01:00
|
|
|
#app.layer.drawRegion app.images.entities, currentSelectedTile.entity.sprite(), 44, 102
|
2014-12-07 15:13:19 +01:00
|
|
|
if currentSelectedTile.entity.isMoveable()
|
|
|
|
app.layer.drawRegion @itemArrow.image, @itemArrow.sprite(), 44, 102
|
2014-12-07 13:42:45 +01:00
|
|
|
when 'resources'
|
2014-12-07 17:08:31 +01:00
|
|
|
@showResources()
|
|
|
|
|
2014-12-07 17:21:58 +01:00
|
|
|
showBuildInfo: ->
|
|
|
|
clearTimeout(@timeout) if @timeout
|
|
|
|
@buildinfo = true
|
2014-12-07 17:41:21 +01:00
|
|
|
@timeout = window.setTimeout @hideBuildInfo, 4000
|
2014-12-07 17:21:58 +01:00
|
|
|
|
|
|
|
hideBuildInfo: ->
|
|
|
|
app.game.hud.buildinfo = false
|
|
|
|
|
2014-12-07 17:08:31 +01:00
|
|
|
showResources: ->
|
|
|
|
# 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
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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++
|