|
|
|
@ -1,15 +1,13 @@
|
|
|
|
|
app.game =
|
|
|
|
|
start: ->
|
|
|
|
|
for i in [0..20*15-1]
|
|
|
|
|
@map[i] = new Tile
|
|
|
|
|
@map[i] = new Tile(i)
|
|
|
|
|
@map[20*5+10].entity = new Base
|
|
|
|
|
|
|
|
|
|
@currentHoveredTile = new Tile
|
|
|
|
|
@currentHoveredTile = new Tile(-1)
|
|
|
|
|
@currentSelectedTile = null
|
|
|
|
|
|
|
|
|
|
# Start the game tick
|
|
|
|
|
window.setInterval @tick, 1000
|
|
|
|
|
|
|
|
|
|
@hud.start()
|
|
|
|
|
|
|
|
|
|
render: ->
|
|
|
|
@ -17,14 +15,13 @@ app.game =
|
|
|
|
|
y = Math.floor(i/20)
|
|
|
|
|
x = i-(y*20)
|
|
|
|
|
tile.render(x, y)
|
|
|
|
|
|
|
|
|
|
@hud.render()
|
|
|
|
|
|
|
|
|
|
mousedown: (event)->
|
|
|
|
|
if @isMouseInView event.x, event.y
|
|
|
|
|
if @isMouseInView event.x/8, event.y/8
|
|
|
|
|
switch event.button
|
|
|
|
|
when 'left'
|
|
|
|
|
tile = posToTile(event.x, event.y)
|
|
|
|
|
tile = posToTile(Math.floor(event.x/8), Math.floor(event.y/8))
|
|
|
|
|
tile.click(event.button)
|
|
|
|
|
|
|
|
|
|
@currentSelectedTile.deselect() if @currentSelectedTile
|
|
|
|
@ -36,7 +33,7 @@ app.game =
|
|
|
|
|
|
|
|
|
|
mousemove: (event)->
|
|
|
|
|
if @isMouseInView event.x, event.y
|
|
|
|
|
tile = posToTile(event.x, event.y)
|
|
|
|
|
tile = posToTile(Math.floor(event.x/8), Math.floor(event.y/8))
|
|
|
|
|
|
|
|
|
|
if tile
|
|
|
|
|
if tile != @currentHoveredTile
|
|
|
|
@ -66,11 +63,11 @@ app.game =
|
|
|
|
|
tile.tick() for tile in app.game.map
|
|
|
|
|
|
|
|
|
|
createMiner: ->
|
|
|
|
|
if @currentSelectedTile and @checkResource 'stardust', 1, true
|
|
|
|
|
if @currentSelectedTile and !@currentSelectedTile.entity and @checkResource('stardust', 30, true)
|
|
|
|
|
@currentSelectedTile.entity = new Miner
|
|
|
|
|
|
|
|
|
|
createSilo: ->
|
|
|
|
|
if @currentSelectedTile and @checkResource 'stardust', 1, true
|
|
|
|
|
if @currentSelectedTile and @checkPosition(@currentSelectedTile) and @checkResource('stardust', 20, true)
|
|
|
|
|
@currentSelectedTile.entity = new Silo
|
|
|
|
|
|
|
|
|
|
checkResource: (type, amount, drain = false) ->
|
|
|
|
@ -79,6 +76,34 @@ app.game =
|
|
|
|
|
return true
|
|
|
|
|
false
|
|
|
|
|
|
|
|
|
|
checkPosition: (tile)->
|
|
|
|
|
return false if tile.entity
|
|
|
|
|
|
|
|
|
|
# Check all 4 directions
|
|
|
|
|
[x, y] = posToXY(tile.position)
|
|
|
|
|
|
|
|
|
|
# Left
|
|
|
|
|
return true if app.game.map[xyToPos(x-1, y)].entity \
|
|
|
|
|
and app.game.map[xyToPos(x-1, y)].entity.isDockable \
|
|
|
|
|
and x > 0
|
|
|
|
|
|
|
|
|
|
# Right
|
|
|
|
|
return true if app.game.map[xyToPos(x+1, y)].entity \
|
|
|
|
|
and app.game.map[xyToPos(x+1, y)].entity.isDockable \
|
|
|
|
|
and x < 19
|
|
|
|
|
|
|
|
|
|
# Top
|
|
|
|
|
return true if app.game.map[xyToPos(x, y-1)].entity \
|
|
|
|
|
and app.game.map[xyToPos(x, y-1)].entity.isDockable \
|
|
|
|
|
and y > 0
|
|
|
|
|
|
|
|
|
|
# Bottom
|
|
|
|
|
return true if app.game.map[xyToPos(x, y+1)].entity \
|
|
|
|
|
and app.game.map[xyToPos(x, y+1)].entity.isDockable \
|
|
|
|
|
and y < 14
|
|
|
|
|
|
|
|
|
|
false
|
|
|
|
|
|
|
|
|
|
cheatah: ->
|
|
|
|
|
for type, amount of @resources
|
|
|
|
|
@resources[type] = 100
|
|
|
|
@ -88,7 +113,7 @@ app.game =
|
|
|
|
|
maxTileAmount: 15
|
|
|
|
|
|
|
|
|
|
availableSiloStorage: ->
|
|
|
|
|
space = 50
|
|
|
|
|
space = 0
|
|
|
|
|
for tile in app.game.map
|
|
|
|
|
space += tile.entity.spaceProvided if tile.entity
|
|
|
|
|
space
|
|
|
|
|