app.game = start: -> for i in [0..20*15-1] @map[i] = new Tile @miners = [] @currentHoveredTile = new Tile @currentSelectedTile = new Tile render: -> for tile, i in @map y = Math.floor(i/20) x = i-(y*20) tile.render(x, y) @hud.render() step: -> mousedown: (event)-> 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) if tile if tile != @currentHoveredTile tile.moveIn() @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)*20) + Math.floor(x/8) @map[pos] map: [] maxTileAmount: 15 resources: stardust: 0 bedrock: 0 lubinit: 0 oxodum: 0 notch: 0