resource collection
This commit is contained in:
parent
9f863f232d
commit
00cfb0cc84
3 changed files with 21 additions and 7 deletions
|
@ -6,14 +6,21 @@ class Tile extends BaseEntity
|
||||||
|
|
||||||
@layers = []
|
@layers = []
|
||||||
for restype, i in resTypes
|
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
|
@currentLayer = 0
|
||||||
@isActive = false
|
@isActive = false
|
||||||
|
|
||||||
click: (button)->
|
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: ->
|
moveIn: ->
|
||||||
@isActive = true
|
@isActive = true
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
class Tilelayer extends BaseEntity
|
class Tilelayer extends BaseEntity
|
||||||
constructor: (options) ->
|
constructor: (options)->
|
||||||
{@type, @depth, @amount} = options
|
{@type, @depth, @amount} = options
|
||||||
@randomFactor = getRandomInt 0, 4
|
@randomFactor = getRandomInt 0, 4
|
||||||
@sprite = [@randomFactor*8, @depth*8, 8, 8]
|
@sprite = [@randomFactor*8, @depth*8, 8, 8]
|
||||||
|
|
||||||
|
collect: ->
|
||||||
|
return false if @amount == 0
|
||||||
|
@amount -= 1
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
app = playground({
|
app = playground(
|
||||||
width: 8*20*5,
|
width: 8*20*5,
|
||||||
height: 8*15*5,
|
height: 8*15*5,
|
||||||
scaleToFit: true,
|
scaleToFit: true,
|
||||||
|
@ -31,5 +31,8 @@ app = playground({
|
||||||
posToTile: (x, y)->
|
posToTile: (x, y)->
|
||||||
pos = (Math.floor(y/8/5)*20) + Math.floor(x/8/5)
|
pos = (Math.floor(y/8/5)*20) + Math.floor(x/8/5)
|
||||||
@game.map[pos]
|
@game.map[pos]
|
||||||
|
|
||||||
})
|
layerIndexToName: (index)->
|
||||||
|
resTypes = (k for own k of @game.resources)
|
||||||
|
resTypes[index]
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue