app.game = start: -> for i in [0..20*15-1] @map[i] = new Tile @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 "c" then @cheatah() when "space" @currentSelectedTile.deselect() if @currentSelectedTile @currentSelectedTile = null createMiner: -> if @currentSelectedTile and @checkRessources 'lubinit', 30, true newMiner = new Miner @miners.push = newMiner @currentSelectedTile.attachMiner newMiner @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) -> if @resources[type] >= amount @resources[type] -= amount if drain return true false cheatah: -> for type, amount of @resources @resources[type] = 100 map: [] miners: [] maxTileAmount: 15 resources: stardust: 0 bedrock: 0 lubinit: 0 oxodum: 0 notch: 0