More refactoring work ....

This commit is contained in:
Aaron Mueller 2014-12-06 23:17:58 +01:00
parent 815fa7d2d1
commit cccb2eff5b
2 changed files with 8 additions and 12 deletions

View file

@ -17,10 +17,8 @@ app.game =
@hud.render() @hud.render()
step: ->
mousedown: (event)-> mousedown: (event)->
tile = @posToTile(event.x, event.y) tile = posToTile(event.x, event.y)
tile.click(event.button) tile.click(event.button)
@currentSelectedTile.deselect() if @currentSelectedTile @currentSelectedTile.deselect() if @currentSelectedTile
@ -28,7 +26,7 @@ app.game =
@currentSelectedTile = tile @currentSelectedTile = tile
mousemove: (event)-> mousemove: (event)->
tile = @posToTile(event.x, event.y) tile = posToTile(event.x, event.y)
if tile if tile
if tile != @currentHoveredTile if tile != @currentHoveredTile
@ -50,12 +48,6 @@ app.game =
createMiner: -> createMiner: ->
if @currentSelectedTile and @checkRessources 'lubinit', 30, true if @currentSelectedTile and @checkRessources 'lubinit', 30, true
@currentSelectedTile.entity = new Miner @currentSelectedTile.entity = new Miner
@currentSelectedTile.deselect() if @currentSelectedTile
@currentSelectedTile = null
posToTile: (x, y)->
pos = (Math.floor(y/8)*20) + Math.floor(x/8)
@map[pos]
checkRessources: (type, amount, drain = false) -> checkRessources: (type, amount, drain = false) ->
if @resources[type] >= amount if @resources[type] >= amount

View file

@ -3,3 +3,7 @@ getRandomInt = (min, max) ->
allResourceTypes = -> allResourceTypes = ->
(k for own k of app.game.resources) (k for own k of app.game.resources)
posToTile = (x, y)->
pos = (Math.floor(y/8)*20) + Math.floor(x/8)
app.game.map[pos]