ld31-space-diggers/src/entities/tile.coffee

52 lines
1.2 KiB
CoffeeScript
Raw Normal View History

2014-12-06 13:14:15 +01:00
class Tile extends BaseEntity
2014-12-06 09:16:55 +01:00
constructor: (options) ->
super options
2014-12-06 13:54:54 +01:00
resTypes = (k for own k of app.game.resources)
2014-12-06 14:28:58 +01:00
@layers = []
2014-12-06 14:52:03 +01:00
for restype, i in resTypes
2014-12-06 17:17:30 +01:00
@layers.push new Tilelayer(
type: restype,
depth: i,
2014-12-06 17:32:37 +01:00
amount: Math.round(Math.random(app.game.maxTileAmount-10)+10)
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
@isActive = false
click: (button)->
2014-12-06 17:32:37 +01:00
#@isSelected = true
if button == "left"
if @layers[@currentLayer].collect()
name = app.layerIndexToName(@currentLayer)
app.game.resources[name] += 1
else
2014-12-06 17:42:23 +01:00
@currentLayer += 1
moveIn: ->
2014-12-06 16:35:05 +01:00
@isActive = true
moveOut: ->
2014-12-06 16:35:05 +01:00
@isActive = false
2014-12-06 13:54:54 +01:00
2014-12-06 09:16:55 +01:00
tick: (delta) ->
2014-12-06 13:54:54 +01:00
# TODO: digging deeper?
2014-12-06 09:16:55 +01:00
2014-12-06 12:37:57 +01:00
render: (x, y)->
2014-12-06 16:35:05 +01:00
tileLayer = @layers[@currentLayer]
app.layer.drawRegion app.images.layers, tileLayer.sprite, x*8, y*8
2014-12-06 16:52:53 +01:00
2014-12-06 17:32:37 +01:00
#if @isSelected
# app.layer.drawImage app.images.selected, x*8, y*8
if @isActive
2014-12-06 16:35:05 +01:00
app.layer.drawImage app.images.active, x*8, y*8
2014-12-06 17:42:23 +01:00
# 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)
2014-12-06 17:32:37 +01:00