You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
3.7 KiB

app.game.hud =
start: ->
resTypes = (k for own k of app.game.resources)
@position = x: 45, y: 103
@buildinfo = false
@itemArrow = new AnimatedItem maxFrames: 10, image: app.images.actions, speed: 50
@resources = []
for restype, i in resTypes
@resources[restype] = new Tilelayer(
type: restype,
depth: i
)
render: ->
panelusage = 'resources'
app.layer.drawImage app.images.hud, 0, 11*8
app.layer.drawImage app.images.info, 143, 95
# cursor
# app.layer.drawImage app.images.cursor, app.game.mouseX, app.game.mouseY
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
app.layer.drawRegion app.images.buildinfo, [0, 30, 106, 10], 1, 34
currentSelectedTile = app.game.currentSelectedTile
if currentSelectedTile != null
panelusage = 'tile'
if currentSelectedTile.entity
panelusage = 'entity'
app.layer.drawRegion app.images.entitydetails, currentSelectedTile.entity.spritedetail(), 12, 95
else
app.layer.drawRegion app.images.layerdetails, currentSelectedTile.getCurrentLayer().spritedetail, 12, 95
# silo capacity
usedSiloStoragePercent = Math.round((100 / app.game.availableSiloStorage()) * app.game.usedSiloStorage())
for f in [0..100]
resourcePanelColor = "#333"
if f <= usedSiloStoragePercent
colorStep = Math.round((usedSiloStoragePercent/100)*5)
resourcePanelColor = ["#0a0", "#0a0", "#aa0", "#f60", "#a00", "#f00"][colorStep]
x = 44+f
y = 112
app.layer.setPixel(resourcePanelColor, x, y)
# Energy production (47)
length = Math.round(((25*app.game.solarpanelCount())*45)/100)
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)
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'
@showResources()
showBuildInfo: ->
clearTimeout(@timeout) if @timeout
@buildinfo = true
@timeout = window.setTimeout @hideBuildInfo, 6000
hideBuildInfo: ->
app.game.hud.buildinfo = false
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++