52 lines
1.2 KiB
CoffeeScript
52 lines
1.2 KiB
CoffeeScript
class Tile extends BaseEntity
|
|
constructor: (options) ->
|
|
super options
|
|
|
|
resTypes = (k for own k of app.game.resources)
|
|
|
|
@layers = []
|
|
for restype, i in resTypes
|
|
@layers.push new Tilelayer(
|
|
type: restype,
|
|
depth: i,
|
|
amount: Math.round(Math.random(app.game.maxTileAmount-10)+10)
|
|
)
|
|
|
|
@currentLayer = 0
|
|
@isActive = false
|
|
|
|
click: (button)->
|
|
#@isSelected = true
|
|
if button == "left"
|
|
if @layers[@currentLayer].collect()
|
|
name = app.layerIndexToName(@currentLayer)
|
|
app.game.resources[name] += 1
|
|
else
|
|
@currentLayer += 1
|
|
|
|
moveIn: ->
|
|
@isActive = true
|
|
|
|
moveOut: ->
|
|
@isActive = false
|
|
|
|
tick: (delta) ->
|
|
# TODO: digging deeper?
|
|
|
|
render: (x, y)->
|
|
tileLayer = @layers[@currentLayer]
|
|
app.layer.drawRegion app.images.layers, tileLayer.sprite, x*8, y*8
|
|
|
|
#if @isSelected
|
|
# app.layer.drawImage app.images.selected, x*8, y*8
|
|
if @isActive
|
|
app.layer.drawImage app.images.active, x*8, y*8
|
|
# Draw the status indicator.
|
|
for i in [0..5]
|
|
color = "#0a0"
|
|
color = "#0f0" if i == 5
|
|
app.layer.setPixel(color, x*8+1+i, y*8+6)
|
|
|
|
|
|
|