Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
8adc7d0002
2 changed files with 41 additions and 4 deletions
|
@ -21,22 +21,41 @@ class Tile extends BaseEntity
|
|||
name = app.layerIndexToName(@currentLayer)
|
||||
app.game.resources[name] += 1
|
||||
else
|
||||
@currentLayer += 1
|
||||
@currentLayer += 1
|
||||
|
||||
moveIn: ->
|
||||
@isActive = true
|
||||
|
||||
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
|
||||
|
||||
# Draw the status indicator.
|
||||
# Draw the status indicator.
|
||||
numPercent = Math.floor((tileLayer.amount*6)/app.game.maxTileAmount)
|
||||
for i in [0..numPercent]
|
||||
color = ["#f00", "#a00", "#f60", "#aa0", "#0a0", "#0a0"][numPercent]
|
||||
|
|
|
@ -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