Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
8adc7d0002
2 changed files with 41 additions and 4 deletions
|
@ -29,10 +29,29 @@ class Tile extends BaseEntity
|
||||||
moveOut: ->
|
moveOut: ->
|
||||||
@isActive = false
|
@isActive = false
|
||||||
|
|
||||||
|
select: ->
|
||||||
|
@isSelected = true
|
||||||
|
|
||||||
|
deselect: ->
|
||||||
|
@isSelected = false
|
||||||
|
|
||||||
|
attachMiner: (miner) ->
|
||||||
|
if !@currentMiner
|
||||||
|
@currentMiner = miner
|
||||||
|
|
||||||
|
detachMiner: ->
|
||||||
|
@currentMiner = null
|
||||||
|
|
||||||
render: (x, y)->
|
render: (x, y)->
|
||||||
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 @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
|
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