ld31-space-diggers/src/game.coffee

50 lines
857 B
CoffeeScript
Raw Normal View History

2014-12-06 12:37:57 +01:00
app.game =
2014-12-06 08:37:36 +01:00
start: ->
2014-12-06 15:09:56 +01:00
for i in [0..20*15-1]
2014-12-06 10:34:53 +01:00
@map[i] = new Tile
2014-12-06 08:37:36 +01:00
2014-12-06 17:17:33 +01:00
@miners = []
@miners.push = new Miner
2014-12-06 17:26:12 +01:00
@currentHoveredTile = new Tile
2014-12-06 17:17:33 +01:00
2014-12-06 10:34:53 +01:00
render: ->
2014-12-06 16:49:29 +01:00
app.layer.save().scale(5, 5)
2014-12-06 12:37:57 +01:00
for tile, i in @map
2014-12-06 15:09:56 +01:00
y = Math.floor(i/20)
x = i-(y*20)
tile.render(x, y)
2014-12-06 16:49:29 +01:00
app.layer.restore()
2014-12-06 12:55:43 +01:00
@hud.render()
2014-12-06 09:24:36 +01:00
2014-12-06 08:37:36 +01:00
step: ->
2014-12-06 10:34:53 +01:00
2014-12-06 17:26:12 +01:00
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]
2014-12-06 10:34:53 +01:00
map: []
2014-12-06 17:32:37 +01:00
maxTileAmount: 15
2014-12-06 08:37:36 +01:00
resources:
2014-12-06 17:38:03 +01:00
stardust: 0
bedrock: 0
2014-12-06 13:14:15 +01:00
lubinit: 0
oxodum: 0
notch: 0