2014-12-06 21:36:19 +01:00
|
|
|
class Tile
|
2014-12-07 14:07:13 +01:00
|
|
|
constructor: (position)->
|
|
|
|
@position = position
|
2014-12-06 14:28:58 +01:00
|
|
|
@layers = []
|
2014-12-06 22:07:28 +01:00
|
|
|
for restype, i in allResourceTypes()
|
2014-12-06 17:17:30 +01:00
|
|
|
@layers.push new Tilelayer(
|
|
|
|
type: restype,
|
|
|
|
depth: i,
|
2014-12-07 15:47:42 +01:00
|
|
|
amount: Math.round(Math.random()*app.game.maxTileAmount)+1
|
2014-12-06 17:17:30 +01:00
|
|
|
)
|
2014-12-06 14:55:33 +01:00
|
|
|
|
2014-12-06 16:35:05 +01:00
|
|
|
@currentLayer = 0
|
2014-12-06 22:07:28 +01:00
|
|
|
@entity = null
|
2014-12-06 16:35:05 +01:00
|
|
|
@isActive = false
|
2014-12-07 15:47:42 +01:00
|
|
|
@isBuildable = !(Math.round(Math.random()*10) == 5)
|
|
|
|
@randomSeed = Math.round(Math.random()*10)
|
2014-12-06 15:57:02 +01:00
|
|
|
|
|
|
|
click: (button)->
|
2014-12-06 22:07:28 +01:00
|
|
|
if button == "left"
|
2014-12-07 12:55:08 +01:00
|
|
|
if (app.game.availableSiloStorage() - app.game.usedSiloStorage()) > 0
|
|
|
|
if @layers[@currentLayer].collect()
|
|
|
|
name = app.layerIndexToName(@currentLayer)
|
|
|
|
app.game.resources[name] += 1
|
|
|
|
else
|
|
|
|
@currentLayer += 1
|
|
|
|
# If we reach the bottom, the entity on top dies.
|
|
|
|
@entity = null if @currentLayer == allResourceTypes().length-1
|
2014-12-06 21:08:46 +01:00
|
|
|
|
2014-12-06 19:49:57 +01:00
|
|
|
tick: ->
|
2014-12-06 22:07:28 +01:00
|
|
|
@entity.tick @ if @entity
|
2014-12-06 19:49:57 +01:00
|
|
|
|
2014-12-06 15:57:02 +01:00
|
|
|
moveIn: ->
|
2014-12-06 16:35:05 +01:00
|
|
|
@isActive = true
|
2014-12-06 15:57:02 +01:00
|
|
|
|
|
|
|
moveOut: ->
|
2014-12-06 16:35:05 +01:00
|
|
|
@isActive = false
|
2014-12-06 17:58:03 +01:00
|
|
|
|
|
|
|
select: ->
|
|
|
|
@isSelected = true
|
|
|
|
|
|
|
|
deselect: ->
|
|
|
|
@isSelected = false
|
|
|
|
|
2014-12-07 01:08:39 +01:00
|
|
|
getCurrentLayer: ->
|
|
|
|
@layers[@currentLayer]
|
|
|
|
|
2014-12-06 12:37:57 +01:00
|
|
|
render: (x, y)->
|
2014-12-07 01:08:39 +01:00
|
|
|
tileLayer = @getCurrentLayer()
|
2014-12-06 16:35:05 +01:00
|
|
|
app.layer.drawRegion app.images.layers, tileLayer.sprite, x*8, y*8
|
2014-12-06 16:52:53 +01:00
|
|
|
|
2014-12-07 15:47:42 +01:00
|
|
|
unless @isBuildable
|
|
|
|
app.layer.drawRegion app.images.deadtiles, [8*@randomSeed, 0, 8, 8], x*8, y*8
|
|
|
|
return
|
|
|
|
|
2014-12-06 22:07:28 +01:00
|
|
|
if @entity
|
2014-12-07 00:19:22 +01:00
|
|
|
app.layer.drawRegion app.images.entities, @entity.sprite(), x*8, y*8
|
2014-12-06 17:58:03 +01:00
|
|
|
|
2014-12-07 00:28:16 +01:00
|
|
|
if (@entity and @entity.isMoveable()) or @isActive
|
2014-12-06 21:47:58 +01:00
|
|
|
# Draw the status indicator.
|
2014-12-07 00:19:22 +01:00
|
|
|
app.layer.drawImage app.images.progress, x*8, y*8
|
2014-12-06 21:47:58 +01:00
|
|
|
numPercent = Math.floor((tileLayer.amount*6)/app.game.maxTileAmount)
|
|
|
|
for i in [0..numPercent]
|
|
|
|
color = ["#f00", "#a00", "#f60", "#aa0", "#0a0", "#0a0"][numPercent]
|
|
|
|
color = ["#f00", "#f00", "#f80", "#ff0", "#0f0", "#0f0"][numPercent] if i == numPercent
|
|
|
|
app.layer.setPixel(color, x*8+1+i, y*8+6)
|
2014-12-06 17:58:03 +01:00
|
|
|
|
2014-12-06 17:32:37 +01:00
|
|
|
if @isActive
|
2014-12-06 16:35:05 +01:00
|
|
|
app.layer.drawImage app.images.active, x*8, y*8
|
2014-12-06 17:32:37 +01:00
|
|
|
|
2014-12-07 01:08:39 +01:00
|
|
|
if @isSelected
|
|
|
|
app.layer.drawImage app.images.selected, x*8, y*8
|
|
|
|
|
2014-12-06 18:12:38 +01:00
|
|
|
|