Merge branch 'master' of https://github.com/arg-games/ld31
Conflicts: src/entities/tile.coffee src/main.coffee
This commit is contained in:
commit
3753b67b07
6 changed files with 36 additions and 7 deletions
Binary file not shown.
Before Width: | Height: | Size: 315 B |
Binary file not shown.
BIN
public/images/HUD.png
Normal file
BIN
public/images/HUD.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 890 B |
|
@ -6,14 +6,21 @@ class Tile extends BaseEntity
|
||||||
|
|
||||||
@layers = []
|
@layers = []
|
||||||
for restype, i in resTypes
|
for restype, i in resTypes
|
||||||
@layers.push new Tilelayer(type: restype, depth: i)
|
@layers.push new Tilelayer(
|
||||||
|
type: restype,
|
||||||
|
depth: i,
|
||||||
|
amount: Math.random(5)+10
|
||||||
|
)
|
||||||
|
|
||||||
@currentLayer = 0
|
@currentLayer = 0
|
||||||
@isActive = false
|
@isActive = false
|
||||||
|
|
||||||
click: (button)->
|
click: (button)->
|
||||||
# console.log button
|
@isSelected = true
|
||||||
# @isSelected = true
|
if button == "left" and @layers[@currentLayer].collect()
|
||||||
|
name = app.layerIndexToName(@currentLayer)
|
||||||
|
console.log(name)
|
||||||
|
app.game.resources[name] += 1
|
||||||
|
|
||||||
moveIn: ->
|
moveIn: ->
|
||||||
@isActive = true
|
@isActive = true
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
class Tilelayer extends BaseEntity
|
class Tilelayer extends BaseEntity
|
||||||
constructor: (options) ->
|
constructor: (options)->
|
||||||
{@type, @depth, @amount} = options
|
{@type, @depth, @amount} = options
|
||||||
@randomFactor = getRandomInt 0, 4
|
@randomFactor = getRandomInt 0, 4
|
||||||
@sprite = [@randomFactor*8, @depth*8, 8, 8]
|
@sprite = [@randomFactor*8, @depth*8, 8, 8]
|
||||||
|
|
||||||
|
collect: ->
|
||||||
|
return false if @amount == 0
|
||||||
|
@amount -= 1
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
app = playground({
|
app = playground(
|
||||||
width: 8*20*5,
|
width: 8*20*5,
|
||||||
height: 8*15*5,
|
height: 8*15*5,
|
||||||
scaleToFit: true,
|
scaleToFit: true,
|
||||||
|
@ -6,6 +6,7 @@ app = playground({
|
||||||
|
|
||||||
create: ->
|
create: ->
|
||||||
@loadImages "layers", "active", "selected", "entities"
|
@loadImages "layers", "active", "selected", "entities"
|
||||||
|
@currentHoveredTile = new Tile
|
||||||
|
|
||||||
ready: ->
|
ready: ->
|
||||||
@game.start()
|
@game.start()
|
||||||
|
@ -13,8 +14,25 @@ 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)->
|
||||||
|
resTypes = (k for own k of @game.resources)
|
||||||
|
resTypes[index]
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue