Merge remote-tracking branch 'origin/master'

This commit is contained in:
Jonas1989 2014-12-06 18:58:27 +01:00
commit 8adc7d0002
2 changed files with 41 additions and 4 deletions

View file

@ -29,10 +29,29 @@ class Tile extends BaseEntity
moveOut: ->
@isActive = false
select: ->
@isSelected = true
deselect: ->
@isSelected = false
attachMiner: (miner) ->
if !@currentMiner
@currentMiner = miner
detachMiner: ->
@currentMiner = null
render: (x, y)->
tileLayer = @layers[@currentLayer]
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
app.layer.drawImage app.images.active, x*8, y*8

View file

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