Miners can be set
This commit is contained in:
parent
eecacde582
commit
2b6fa18b02
2 changed files with 39 additions and 6 deletions
|
@ -16,20 +16,31 @@ class Tile extends BaseEntity
|
|||
@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
|
||||
|
||||
select: ->
|
||||
@isSelected = true
|
||||
|
||||
deselect: ->
|
||||
@isSelected = false
|
||||
|
||||
attachMiner: (miner) ->
|
||||
if !@currentMiner
|
||||
@currentMiner = miner
|
||||
|
||||
detachMiner: ->
|
||||
@currentMiner = null
|
||||
|
||||
tick: (delta) ->
|
||||
# TODO: digging deeper?
|
||||
|
@ -38,8 +49,12 @@ class Tile extends BaseEntity
|
|||
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 @currentMiner
|
||||
app.layer.drawRegion app.images.entities, [8, 0, 8, 8], 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
|
||||
|
||||
|
|
|
@ -4,9 +4,9 @@ app.game =
|
|||
@map[i] = new Tile
|
||||
|
||||
@miners = []
|
||||
@miners.push = new Miner
|
||||
|
||||
@currentHoveredTile = new Tile
|
||||
@currentSelectedTile = new Tile
|
||||
|
||||
render: ->
|
||||
app.layer.save().scale(5, 5)
|
||||
|
@ -23,7 +23,12 @@ app.game =
|
|||
step: ->
|
||||
|
||||
mousedown: (event)->
|
||||
@posToTile(event.x, event.y).click(event.button)
|
||||
tile = @posToTile(event.x, event.y)
|
||||
tile.click(event.button)
|
||||
|
||||
@currentSelectedTile.deselect() if @currentSelectedTile
|
||||
tile.select()
|
||||
@currentSelectedTile = tile
|
||||
|
||||
mousemove: (event)->
|
||||
tile = @posToTile(event.x, event.y)
|
||||
|
@ -34,6 +39,19 @@ app.game =
|
|||
@currentHoveredTile.moveOut()
|
||||
@currentHoveredTile = tile
|
||||
|
||||
keyup: (event) ->
|
||||
switch event.key
|
||||
when "m" then @createMiner()
|
||||
when "space"
|
||||
@currentSelectedTile.deselect() if @currentSelectedTile
|
||||
@currentSelectedTile = null
|
||||
|
||||
createMiner: ->
|
||||
if @currentSelectedTile
|
||||
newMiner = new Miner
|
||||
@miners.push = newMiner
|
||||
@currentSelectedTile.attachMiner newMiner
|
||||
|
||||
posToTile: (x, y)->
|
||||
pos = (Math.floor(y/8/5)*20) + Math.floor(x/8/5)
|
||||
@map[pos]
|
||||
|
|
Loading…
Reference in a new issue