Miners can be set
This commit is contained in:
parent
eecacde582
commit
2b6fa18b02
2 changed files with 39 additions and 6 deletions
|
@ -16,7 +16,6 @@ class Tile extends BaseEntity
|
||||||
@isActive = false
|
@isActive = false
|
||||||
|
|
||||||
click: (button)->
|
click: (button)->
|
||||||
#@isSelected = true
|
|
||||||
if button == "left"
|
if button == "left"
|
||||||
if @layers[@currentLayer].collect()
|
if @layers[@currentLayer].collect()
|
||||||
name = app.layerIndexToName(@currentLayer)
|
name = app.layerIndexToName(@currentLayer)
|
||||||
|
@ -24,13 +23,25 @@ class Tile extends BaseEntity
|
||||||
else
|
else
|
||||||
@currentLayer += 1
|
@currentLayer += 1
|
||||||
|
|
||||||
|
|
||||||
moveIn: ->
|
moveIn: ->
|
||||||
@isActive = true
|
@isActive = true
|
||||||
|
|
||||||
moveOut: ->
|
moveOut: ->
|
||||||
@isActive = false
|
@isActive = false
|
||||||
|
|
||||||
|
select: ->
|
||||||
|
@isSelected = true
|
||||||
|
|
||||||
|
deselect: ->
|
||||||
|
@isSelected = false
|
||||||
|
|
||||||
|
attachMiner: (miner) ->
|
||||||
|
if !@currentMiner
|
||||||
|
@currentMiner = miner
|
||||||
|
|
||||||
|
detachMiner: ->
|
||||||
|
@currentMiner = null
|
||||||
|
|
||||||
tick: (delta) ->
|
tick: (delta) ->
|
||||||
# TODO: digging deeper?
|
# TODO: digging deeper?
|
||||||
|
|
||||||
|
@ -38,8 +49,12 @@ class Tile extends BaseEntity
|
||||||
tileLayer = @layers[@currentLayer]
|
tileLayer = @layers[@currentLayer]
|
||||||
app.layer.drawRegion app.images.layers, tileLayer.sprite, x*8, y*8
|
app.layer.drawRegion app.images.layers, tileLayer.sprite, x*8, y*8
|
||||||
|
|
||||||
#if @isSelected
|
if @currentMiner
|
||||||
# app.layer.drawImage app.images.selected, x*8, y*8
|
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
|
if @isActive
|
||||||
app.layer.drawImage app.images.active, x*8, y*8
|
app.layer.drawImage app.images.active, x*8, y*8
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,9 @@ app.game =
|
||||||
@map[i] = new Tile
|
@map[i] = new Tile
|
||||||
|
|
||||||
@miners = []
|
@miners = []
|
||||||
@miners.push = new Miner
|
|
||||||
|
|
||||||
@currentHoveredTile = new Tile
|
@currentHoveredTile = new Tile
|
||||||
|
@currentSelectedTile = new Tile
|
||||||
|
|
||||||
render: ->
|
render: ->
|
||||||
app.layer.save().scale(5, 5)
|
app.layer.save().scale(5, 5)
|
||||||
|
@ -23,7 +23,12 @@ app.game =
|
||||||
step: ->
|
step: ->
|
||||||
|
|
||||||
mousedown: (event)->
|
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)->
|
mousemove: (event)->
|
||||||
tile = @posToTile(event.x, event.y)
|
tile = @posToTile(event.x, event.y)
|
||||||
|
@ -34,6 +39,19 @@ app.game =
|
||||||
@currentHoveredTile.moveOut()
|
@currentHoveredTile.moveOut()
|
||||||
@currentHoveredTile = tile
|
@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)->
|
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)
|
||||||
@map[pos]
|
@map[pos]
|
||||||
|
|
Loading…
Reference in a new issue