ld31-space-diggers/src/game.coffee
2014-12-06 17:38:03 +01:00

49 lines
857 B
CoffeeScript

app.game =
start: ->
for i in [0..20*15-1]
@map[i] = new Tile
@miners = []
@miners.push = new Miner
@currentHoveredTile = new Tile
render: ->
app.layer.save().scale(5, 5)
for tile, i in @map
y = Math.floor(i/20)
x = i-(y*20)
tile.render(x, y)
app.layer.restore()
@hud.render()
step: ->
mousedown: (event)->
@posToTile(event.x, event.y).click(event.button)
mousemove: (event)->
tile = @posToTile(event.x, event.y)
if tile
if tile != @currentHoveredTile
tile.moveIn()
@currentHoveredTile.moveOut()
@currentHoveredTile = tile
posToTile: (x, y)->
pos = (Math.floor(y/8/5)*20) + Math.floor(x/8/5)
@map[pos]
map: []
maxTileAmount: 15
resources:
stardust: 0
bedrock: 0
lubinit: 0
oxodum: 0
notch: 0