Merge remote-tracking branch 'origin/master'

This commit is contained in:
Jonas1989 2014-12-06 17:57:36 +01:00
commit 15d6f375cd
3 changed files with 40 additions and 25 deletions

View file

@ -9,18 +9,20 @@ class Tile extends BaseEntity
@layers.push new Tilelayer(
type: restype,
depth: i,
amount: Math.random(5)+10
amount: Math.round(Math.random(app.game.maxTileAmount-10)+10)
)
@currentLayer = 0
@isActive = false
click: (button)->
@isSelected = true
if button == "left" and @layers[@currentLayer].collect()
#@isSelected = true
if button == "left"
if @layers[@currentLayer].collect()
name = app.layerIndexToName(@currentLayer)
console.log(name)
app.game.resources[name] += 1
else
@currentLayer += 1
moveIn: ->
@isActive = true
@ -35,7 +37,15 @@ class Tile extends BaseEntity
tileLayer = @layers[@currentLayer]
app.layer.drawRegion app.images.layers, tileLayer.sprite, x*8, y*8
if @isSelected
app.layer.drawImage app.images.selected, x*8, y*8
else if @isActive
#if @isSelected
# app.layer.drawImage app.images.selected, x*8, y*8
if @isActive
app.layer.drawImage app.images.active, x*8, y*8
# Draw the status indicator.
for i in [0..5]
color = "#0a0"
color = "#0f0" if i == 5
app.layer.setPixel(color, x*8+1+i, y*8+6)

View file

@ -6,6 +6,8 @@ app.game =
@miners = []
@miners.push = new Miner
@currentHoveredTile = new Tile
render: ->
app.layer.save().scale(5, 5)
@ -20,11 +22,28 @@ app.game =
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: 10
bedrock: 1
stardust: 0
bedrock: 0
lubinit: 0
oxodum: 0
notch: 0

View file

@ -14,24 +14,10 @@ app = playground(
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: ->
@layer.clear "#00f"
@game.render()
posToTile: (x, y)->
pos = (Math.floor(y/8/5)*20) + Math.floor(x/8/5)
@game.map[pos]
layerIndexToName: (index)->
resTypes = (k for own k of @game.resources)
resTypes[index]