Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
15d6f375cd
3 changed files with 40 additions and 25 deletions
|
@ -9,18 +9,20 @@ class Tile extends BaseEntity
|
||||||
@layers.push new Tilelayer(
|
@layers.push new Tilelayer(
|
||||||
type: restype,
|
type: restype,
|
||||||
depth: i,
|
depth: i,
|
||||||
amount: Math.random(5)+10
|
amount: Math.round(Math.random(app.game.maxTileAmount-10)+10)
|
||||||
)
|
)
|
||||||
|
|
||||||
@currentLayer = 0
|
@currentLayer = 0
|
||||||
@isActive = false
|
@isActive = false
|
||||||
|
|
||||||
click: (button)->
|
click: (button)->
|
||||||
@isSelected = true
|
#@isSelected = true
|
||||||
if button == "left" and @layers[@currentLayer].collect()
|
if button == "left"
|
||||||
name = app.layerIndexToName(@currentLayer)
|
if @layers[@currentLayer].collect()
|
||||||
console.log(name)
|
name = app.layerIndexToName(@currentLayer)
|
||||||
app.game.resources[name] += 1
|
app.game.resources[name] += 1
|
||||||
|
else
|
||||||
|
@currentLayer += 1
|
||||||
|
|
||||||
moveIn: ->
|
moveIn: ->
|
||||||
@isActive = true
|
@isActive = true
|
||||||
|
@ -35,7 +37,15 @@ class Tile extends BaseEntity
|
||||||
tileLayer = @layers[@currentLayer]
|
tileLayer = @layers[@currentLayer]
|
||||||
app.layer.drawRegion app.images.layers, tileLayer.sprite, x*8, y*8
|
app.layer.drawRegion app.images.layers, tileLayer.sprite, x*8, y*8
|
||||||
|
|
||||||
if @isSelected
|
#if @isSelected
|
||||||
app.layer.drawImage app.images.selected, x*8, y*8
|
# app.layer.drawImage app.images.selected, x*8, y*8
|
||||||
else if @isActive
|
if @isActive
|
||||||
app.layer.drawImage app.images.active, x*8, y*8
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,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,11 +22,28 @@ 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: []
|
||||||
|
maxTileAmount: 15
|
||||||
|
|
||||||
resources:
|
resources:
|
||||||
stardust: 10
|
stardust: 0
|
||||||
bedrock: 1
|
bedrock: 0
|
||||||
lubinit: 0
|
lubinit: 0
|
||||||
oxodum: 0
|
oxodum: 0
|
||||||
notch: 0
|
notch: 0
|
||||||
|
|
|
@ -14,24 +14,10 @@ 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]
|
|
||||||
|
|
||||||
layerIndexToName: (index)->
|
layerIndexToName: (index)->
|
||||||
resTypes = (k for own k of @game.resources)
|
resTypes = (k for own k of @game.resources)
|
||||||
resTypes[index]
|
resTypes[index]
|
||||||
|
|
Loading…
Reference in a new issue