can't click on dead tiles

This commit is contained in:
Aaron Mueller 2014-12-07 16:27:44 +01:00
parent 656547aacd
commit b510790ef8
2 changed files with 9 additions and 3 deletions

View file

@ -6,7 +6,6 @@ app.game =
@mouseX = 0 @mouseX = 0
@mouseY = 0 @mouseY = 0
@currentHoveredTile = new Tile(-1) @currentHoveredTile = new Tile(-1)
@currentSelectedTile = null @currentSelectedTile = null
@ -23,10 +22,14 @@ app.game =
@speechbubble.render() @speechbubble.render()
mousedown: (event)-> mousedown: (event)->
tile = posToTile(Math.floor(event.x/8), Math.floor(event.y/8))
# Can't click on dead tiles
return unless tile and tile.isBuildable
if @isMouseInView event.x/8, event.y/8 if @isMouseInView event.x/8, event.y/8
switch event.button switch event.button
when 'left' when 'left'
tile = posToTile(Math.floor(event.x/8), Math.floor(event.y/8))
tile.click(event.button) tile.click(event.button)
@currentSelectedTile.deselect() if @currentSelectedTile @currentSelectedTile.deselect() if @currentSelectedTile

View file

@ -16,6 +16,9 @@ class Tile
@randomSeed = Math.round(Math.random()*10) @randomSeed = Math.round(Math.random()*10)
click: (button)-> click: (button)->
# Some tiles are not buildable
return unless @isBuildable
if button == "left" if button == "left"
if (app.game.availableSiloStorage() - app.game.usedSiloStorage()) > 0 if (app.game.availableSiloStorage() - app.game.usedSiloStorage()) > 0
if @layers[@currentLayer].collect() if @layers[@currentLayer].collect()