diff --git a/src/entities/tile.coffee b/src/entities/tile.coffee index cba6637..28c53db 100644 --- a/src/entities/tile.coffee +++ b/src/entities/tile.coffee @@ -6,14 +6,21 @@ class Tile extends BaseEntity @layers = [] for restype, i in resTypes - @layers.push new Tilelayer(type: restype, depth: i) + @layers.push new Tilelayer( + type: restype, + depth: i, + amount: Math.random(5)+10 + ) @currentLayer = 0 @isActive = false click: (button)-> - # console.log button - @isSelected = true + @isSelected = true + if button == "left" and @layers[@currentLayer].collect() + name = app.layerIndexToName(@currentLayer) + console.log(name) + app.game.resources[name] += 1 moveIn: -> @isActive = true diff --git a/src/entities/tilelayer.coffee b/src/entities/tilelayer.coffee index 5d951d2..a22da6c 100644 --- a/src/entities/tilelayer.coffee +++ b/src/entities/tilelayer.coffee @@ -1,5 +1,9 @@ class Tilelayer extends BaseEntity - constructor: (options) -> + constructor: (options)-> {@type, @depth, @amount} = options @randomFactor = getRandomInt 0, 4 @sprite = [@randomFactor*8, @depth*8, 8, 8] + + collect: -> + return false if @amount == 0 + @amount -= 1 diff --git a/src/main.coffee b/src/main.coffee index 68890a4..3260965 100644 --- a/src/main.coffee +++ b/src/main.coffee @@ -1,4 +1,4 @@ -app = playground({ +app = playground( width: 8*20*5, height: 8*15*5, scaleToFit: true, @@ -31,5 +31,8 @@ app = playground({ posToTile: (x, y)-> pos = (Math.floor(y/8/5)*20) + Math.floor(x/8/5) @game.map[pos] - - }) + + layerIndexToName: (index)-> + resTypes = (k for own k of @game.resources) + resTypes[index] +)