2014-12-06 09:24:36 +01:00
|
|
|
app = playground({
|
2014-12-06 16:49:29 +01:00
|
|
|
width: 8*20*5,
|
|
|
|
height: 8*15*5,
|
2014-12-06 15:57:02 +01:00
|
|
|
scaleToFit: true,
|
2014-12-06 09:24:36 +01:00
|
|
|
smoothing: false,
|
2014-12-06 15:57:02 +01:00
|
|
|
|
2014-12-06 09:24:36 +01:00
|
|
|
create: ->
|
2014-12-06 17:17:33 +01:00
|
|
|
@loadImages "layers", "active", "selected", "entities"
|
2014-12-06 15:57:02 +01:00
|
|
|
@currentHoveredTile = new Tile
|
2014-12-06 09:24:36 +01:00
|
|
|
|
|
|
|
ready: ->
|
2014-12-06 10:34:53 +01:00
|
|
|
@game.start()
|
|
|
|
@setState @game
|
2014-12-06 09:24:36 +01:00
|
|
|
|
|
|
|
step: ->
|
2014-12-06 15:57:02 +01:00
|
|
|
|
|
|
|
mousedown: (event)->
|
|
|
|
@posToTile(event.x, event.y).click(event.button)
|
|
|
|
|
|
|
|
mousemove: (event)->
|
|
|
|
tile = @posToTile(event.x, event.y)
|
|
|
|
if tile != @currentHoveredTile
|
|
|
|
tile.moveIn()
|
|
|
|
@currentHoveredTile.moveOut()
|
|
|
|
@currentHoveredTile = tile
|
|
|
|
|
2014-12-06 09:24:36 +01:00
|
|
|
render: ->
|
2014-12-06 15:57:02 +01:00
|
|
|
@layer.clear "#00f"
|
|
|
|
@game.render()
|
|
|
|
|
|
|
|
posToTile: (x, y)->
|
2014-12-06 16:49:29 +01:00
|
|
|
pos = (Math.floor(y/8/5)*20) + Math.floor(x/8/5)
|
2014-12-06 15:57:02 +01:00
|
|
|
@game.map[pos]
|
|
|
|
|
2014-12-06 08:22:38 +01:00
|
|
|
})
|