This commit is contained in:
Ruben Müller 2014-12-06 17:26:12 +01:00
parent 9f863f232d
commit ebae442b9b
3 changed files with 19 additions and 16 deletions

View file

@ -13,7 +13,7 @@ class Tile extends BaseEntity
click: (button)-> click: (button)->
# console.log button # console.log button
@isSelected = true # @isSelected = true
moveIn: -> moveIn: ->
@isActive = true @isActive = true

View file

@ -5,6 +5,8 @@ app.game =
@miners = [] @miners = []
@miners.push = new Miner @miners.push = new Miner
@currentHoveredTile = new Tile
render: -> render: ->
app.layer.save().scale(5, 5) app.layer.save().scale(5, 5)
@ -20,6 +22,22 @@ app.game =
step: -> 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: [] map: []
resources: resources:

View file

@ -6,7 +6,6 @@ app = playground({
create: -> create: ->
@loadImages "layers", "active", "selected", "entities" @loadImages "layers", "active", "selected", "entities"
@currentHoveredTile = new Tile
ready: -> ready: ->
@game.start() @game.start()
@ -14,22 +13,8 @@ app = playground({
step: -> step: ->
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
render: -> render: ->
@layer.clear "#00f" @layer.clear "#00f"
@game.render() @game.render()
posToTile: (x, y)->
pos = (Math.floor(y/8/5)*20) + Math.floor(x/8/5)
@game.map[pos]
}) })