Merge branch 'master' of https://github.com/arg-games/ld31
This commit is contained in:
commit
927ae718f7
6 changed files with 28 additions and 43 deletions
Binary file not shown.
Before Width: | Height: | Size: 381 B After Width: | Height: | Size: 510 B |
Binary file not shown.
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.5 KiB |
|
@ -1,3 +1,5 @@
|
||||||
class Miner
|
class Miner
|
||||||
tick: (tile) ->
|
tick: (tile) ->
|
||||||
tile.click "left"
|
tile.click "left"
|
||||||
|
|
||||||
|
sprite: [0, 16, 8, 8]
|
||||||
|
|
|
@ -19,10 +19,8 @@ app.game =
|
||||||
|
|
||||||
@hud.render()
|
@hud.render()
|
||||||
|
|
||||||
step: ->
|
|
||||||
|
|
||||||
mousedown: (event)->
|
mousedown: (event)->
|
||||||
tile = @posToTile(event.x, event.y)
|
tile = posToTile(event.x, event.y)
|
||||||
tile.click(event.button)
|
tile.click(event.button)
|
||||||
|
|
||||||
@currentSelectedTile.deselect() if @currentSelectedTile
|
@currentSelectedTile.deselect() if @currentSelectedTile
|
||||||
|
@ -30,7 +28,7 @@ app.game =
|
||||||
@currentSelectedTile = tile
|
@currentSelectedTile = tile
|
||||||
|
|
||||||
mousemove: (event)->
|
mousemove: (event)->
|
||||||
tile = @posToTile(event.x, event.y)
|
tile = posToTile(event.x, event.y)
|
||||||
|
|
||||||
if tile
|
if tile
|
||||||
if tile != @currentHoveredTile
|
if tile != @currentHoveredTile
|
||||||
|
@ -51,17 +49,7 @@ app.game =
|
||||||
|
|
||||||
createMiner: ->
|
createMiner: ->
|
||||||
if @currentSelectedTile and @checkRessources 'lubinit', 30, true
|
if @currentSelectedTile and @checkRessources 'lubinit', 30, true
|
||||||
newMiner = new Miner
|
@currentSelectedTile.entity = new Miner
|
||||||
|
|
||||||
@miners.push = newMiner
|
|
||||||
@currentSelectedTile.attachMiner newMiner
|
|
||||||
|
|
||||||
@currentSelectedTile.deselect() if @currentSelectedTile
|
|
||||||
@currentSelectedTile = null
|
|
||||||
|
|
||||||
posToTile: (x, y)->
|
|
||||||
pos = (Math.floor(y/8)*20) + Math.floor(x/8)
|
|
||||||
@map[pos]
|
|
||||||
|
|
||||||
checkRessources: (type, amount, drain = false) ->
|
checkRessources: (type, amount, drain = false) ->
|
||||||
if @resources[type] >= amount
|
if @resources[type] >= amount
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
class Tile
|
class Tile
|
||||||
constructor: ->
|
constructor: ->
|
||||||
resTypes = (k for own k of app.game.resources)
|
|
||||||
|
|
||||||
@layers = []
|
@layers = []
|
||||||
for restype, i in resTypes
|
for restype, i in allResourceTypes()
|
||||||
@layers.push new Tilelayer(
|
@layers.push new Tilelayer(
|
||||||
type: restype,
|
type: restype,
|
||||||
depth: i,
|
depth: i,
|
||||||
|
@ -11,25 +9,21 @@ class Tile
|
||||||
)
|
)
|
||||||
|
|
||||||
@currentLayer = 0
|
@currentLayer = 0
|
||||||
|
@entity = null
|
||||||
@isActive = false
|
@isActive = false
|
||||||
|
|
||||||
died: false
|
|
||||||
|
|
||||||
click: (button)->
|
click: (button)->
|
||||||
if button == "left" and !@died
|
if button == "left"
|
||||||
if @layers[@currentLayer].collect()
|
if @layers[@currentLayer].collect()
|
||||||
name = app.layerIndexToName(@currentLayer)
|
name = app.layerIndexToName(@currentLayer)
|
||||||
app.game.resources[name] += 1
|
app.game.resources[name] += 1
|
||||||
else
|
else
|
||||||
@currentLayer += 1
|
@currentLayer += 1
|
||||||
|
# If we reach the bottom, the entity on top dies.
|
||||||
if @currentLayer == Object.keys(app.game.resources).length-1
|
@entity = null if @currentLayer == allResourceTypes().length-1
|
||||||
@died = true
|
|
||||||
|
|
||||||
@currentMiner = null if @currentMiner
|
|
||||||
|
|
||||||
tick: ->
|
tick: ->
|
||||||
@currentMiner.tick @ if @currentMiner
|
@entity.tick @ if @entity
|
||||||
|
|
||||||
moveIn: ->
|
moveIn: ->
|
||||||
@isActive = true
|
@isActive = true
|
||||||
|
@ -43,19 +37,19 @@ class Tile
|
||||||
deselect: ->
|
deselect: ->
|
||||||
@isSelected = false
|
@isSelected = false
|
||||||
|
|
||||||
attachMiner: (miner) ->
|
|
||||||
if !@currentMiner
|
|
||||||
@currentMiner = miner
|
|
||||||
|
|
||||||
detachMiner: ->
|
|
||||||
@currentMiner = null
|
|
||||||
|
|
||||||
render: (x, y)->
|
render: (x, y)->
|
||||||
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 @currentMiner
|
if @entity
|
||||||
app.layer.drawRegion app.images.entities, [16, 0, 8, 8], x*8, y*8
|
app.layer.drawRegion app.images.entities, @entity.sprite, x*8, y*8
|
||||||
|
|
||||||
|
# Draw the status indicator.
|
||||||
|
numPercent = Math.floor((tileLayer.amount*6)/app.game.maxTileAmount)
|
||||||
|
for i in [0..numPercent]
|
||||||
|
color = ["#f00", "#a00", "#f60", "#aa0", "#0a0", "#0a0"][numPercent]
|
||||||
|
color = ["#f00", "#f00", "#f80", "#ff0", "#0f0", "#0f0"][numPercent] if i == numPercent
|
||||||
|
app.layer.setPixel(color, x*8+1+i, y*8+6)
|
||||||
|
|
||||||
if @isSelected
|
if @isSelected
|
||||||
app.layer.drawImage app.images.selected, x*8, y*8
|
app.layer.drawImage app.images.selected, x*8, y*8
|
||||||
|
@ -63,10 +57,4 @@ class Tile
|
||||||
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.
|
|
||||||
numPercent = Math.floor((tileLayer.amount*6)/app.game.maxTileAmount)
|
|
||||||
for i in [0..numPercent]
|
|
||||||
color = ["#f00", "#a00", "#f60", "#aa0", "#0a0", "#0a0"][numPercent]
|
|
||||||
color = ["#f00", "#f00", "#f80", "#ff0", "#0f0", "#0f0"][numPercent] if i == numPercent
|
|
||||||
app.layer.setPixel(color, x*8+1+i, y*8+6)
|
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,9 @@
|
||||||
getRandomInt = (min, max) ->
|
getRandomInt = (min, max) ->
|
||||||
Math.floor(Math.random() * (max - min + 1)) + min;
|
Math.floor(Math.random() * (max - min + 1)) + min;
|
||||||
|
|
||||||
|
allResourceTypes = ->
|
||||||
|
(k for own k of app.game.resources)
|
||||||
|
|
||||||
|
posToTile = (x, y)->
|
||||||
|
pos = (Math.floor(y/8)*20) + Math.floor(x/8)
|
||||||
|
app.game.map[pos]
|
||||||
|
|
Loading…
Reference in a new issue