diff --git a/public/images/progress.png b/public/images/progress.png new file mode 100644 index 0000000..78646a4 Binary files /dev/null and b/public/images/progress.png differ diff --git a/public/images/selected.png b/public/images/selected.png index 541a5fb..ae0b345 100644 Binary files a/public/images/selected.png and b/public/images/selected.png differ diff --git a/src/app.coffee b/src/app.coffee index 5261f5c..1468d47 100644 --- a/src/app.coffee +++ b/src/app.coffee @@ -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: -> diff --git a/src/entities/base.coffee b/src/entities/base.coffee new file mode 100644 index 0000000..66581e7 --- /dev/null +++ b/src/entities/base.coffee @@ -0,0 +1,9 @@ +class Base + tick: (tile)-> + + sprite: -> + [0, 0, 8, 8] + + isMoveable: -> + false + diff --git a/src/entities/miner.coffee b/src/entities/miner.coffee index cd7c9d6..5eb5e20 100644 --- a/src/entities/miner.coffee +++ b/src/entities/miner.coffee @@ -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 diff --git a/src/entities/silo.coffee b/src/entities/silo.coffee new file mode 100644 index 0000000..40783e2 --- /dev/null +++ b/src/entities/silo.coffee @@ -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 + diff --git a/src/game.coffee b/src/game.coffee index c8fe60b..388fd3e 100644 --- a/src/game.coffee +++ b/src/game.coffee @@ -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 diff --git a/src/tiles/tile.coffee b/src/tiles/tile.coffee index c15ffc7..734238e 100644 --- a/src/tiles/tile.coffee +++ b/src/tiles/tile.coffee @@ -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]