+silos, polishing, gfx

This commit is contained in:
Aaron Mueller 2014-12-07 00:19:22 +01:00
parent 298849c2fb
commit dbea27ca39
8 changed files with 47 additions and 7 deletions

BIN
public/images/progress.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 946 B

After

Width:  |  Height:  |  Size: 148 B

View File

@ -5,7 +5,7 @@ app = playground(
smoothing: false,
create: ->
@loadImages "layers", "active", "selected", "entities", "hud"
@loadImages "layers", "active", "progress", "selected", "entities", "hud"
@currentHoveredTile = new Tile
ready: ->

9
src/entities/base.coffee Normal file
View File

@ -0,0 +1,9 @@
class Base
tick: (tile)->
sprite: ->
[0, 0, 8, 8]
isMoveable: ->
false

View File

@ -1,5 +1,9 @@
class Miner
tick: (tile) ->
tick: (tile)->
tile.click "left"
sprite: [0, 16, 8, 8]
sprite: ->
[0, 16, 8, 8]
isMoveable: ->
true

19
src/entities/silo.coffee Normal file
View File

@ -0,0 +1,19 @@
class Silo
constructor: ->
@frame = 0
window.setInterval @changeAnimation, 500
tick: (tile)->
sprite: ->
[@frame*8, 8, 8, 8]
isMoveable: ->
false
changeAnimation: =>
if @frame == 2
@frame = 0
else
@frame += 1

View File

@ -2,12 +2,13 @@ app.game =
start: ->
for i in [0..20*15-1]
@map[i] = new Tile
@map[20*5+10].entity = new Base
@currentHoveredTile = new Tile
@currentSelectedTile = new Tile
# Start the game tick
window.setInterval(@tick, 1000)
window.setInterval @tick, 1000
@hud.start()
@ -39,6 +40,7 @@ app.game =
keyup: (event) ->
switch event.key
when "m" then @createMiner()
when "s" then @createSilo()
when "c" then @cheatah()
when "space"
@currentSelectedTile.deselect() if @currentSelectedTile
@ -48,10 +50,14 @@ app.game =
tile.tick() for tile in app.game.map
createMiner: ->
if @currentSelectedTile and @checkRessources 'lubinit', 30, true
if @currentSelectedTile and @checkResource 'lubinit', 30, true
@currentSelectedTile.entity = new Miner
checkRessources: (type, amount, drain = false) ->
createSilo: ->
if @currentSelectedTile and @checkResource 'oxodum', 20, true
@currentSelectedTile.entity = new Silo
checkResource: (type, amount, drain = false) ->
if @resources[type] >= amount
@resources[type] -= amount if drain
return true

View File

@ -42,9 +42,11 @@ class Tile
app.layer.drawRegion app.images.layers, tileLayer.sprite, x*8, y*8
if @entity
app.layer.drawRegion app.images.entities, @entity.sprite, x*8, y*8
app.layer.drawRegion app.images.entities, @entity.sprite(), x*8, y*8
if (@entity and @entity.isMoveable())
# Draw the status indicator.
app.layer.drawImage app.images.progress, x*8, y*8
numPercent = Math.floor((tileLayer.amount*6)/app.game.maxTileAmount)
for i in [0..numPercent]
color = ["#f00", "#a00", "#f60", "#aa0", "#0a0", "#0a0"][numPercent]