+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, smoothing: false,
create: -> create: ->
@loadImages "layers", "active", "selected", "entities", "hud" @loadImages "layers", "active", "progress", "selected", "entities", "hud"
@currentHoveredTile = new Tile @currentHoveredTile = new Tile
ready: -> 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 class Miner
tick: (tile) -> tick: (tile)->
tile.click "left" 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: -> start: ->
for i in [0..20*15-1] for i in [0..20*15-1]
@map[i] = new Tile @map[i] = new Tile
@map[20*5+10].entity = new Base
@currentHoveredTile = new Tile @currentHoveredTile = new Tile
@currentSelectedTile = new Tile @currentSelectedTile = new Tile
# Start the game tick # Start the game tick
window.setInterval(@tick, 1000) window.setInterval @tick, 1000
@hud.start() @hud.start()
@ -39,6 +40,7 @@ app.game =
keyup: (event) -> keyup: (event) ->
switch event.key switch event.key
when "m" then @createMiner() when "m" then @createMiner()
when "s" then @createSilo()
when "c" then @cheatah() when "c" then @cheatah()
when "space" when "space"
@currentSelectedTile.deselect() if @currentSelectedTile @currentSelectedTile.deselect() if @currentSelectedTile
@ -48,10 +50,14 @@ app.game =
tile.tick() for tile in app.game.map tile.tick() for tile in app.game.map
createMiner: -> createMiner: ->
if @currentSelectedTile and @checkRessources 'lubinit', 30, true if @currentSelectedTile and @checkResource 'lubinit', 30, true
@currentSelectedTile.entity = new Miner @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 if @resources[type] >= amount
@resources[type] -= amount if drain @resources[type] -= amount if drain
return true return true

View file

@ -42,9 +42,11 @@ class Tile
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 @entity 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. # Draw the status indicator.
app.layer.drawImage app.images.progress, x*8, y*8
numPercent = Math.floor((tileLayer.amount*6)/app.game.maxTileAmount) numPercent = Math.floor((tileLayer.amount*6)/app.game.maxTileAmount)
for i in [0..numPercent] for i in [0..numPercent]
color = ["#f00", "#a00", "#f60", "#aa0", "#0a0", "#0a0"][numPercent] color = ["#f00", "#a00", "#f60", "#aa0", "#0a0", "#0a0"][numPercent]