resource collection

This commit is contained in:
Aaron Mueller 2014-12-06 17:17:30 +01:00
parent 9f863f232d
commit 00cfb0cc84
3 changed files with 21 additions and 7 deletions

View File

@ -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

View File

@ -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

View File

@ -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]
)