diff --git a/public/images/entities.png b/public/images/entities.png index 6c412f2..a8823d4 100644 Binary files a/public/images/entities.png and b/public/images/entities.png differ 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..cd0565d --- /dev/null +++ b/src/entities/base.coffee @@ -0,0 +1,11 @@ +class Base + tick: (tile)-> + + sprite: -> + [0, 0, 8, 8] + + isMoveable: -> + false + + spaceProvided: 50 + diff --git a/src/entities/miner.coffee b/src/entities/miner.coffee index cd7c9d6..4db52ac 100644 --- a/src/entities/miner.coffee +++ b/src/entities/miner.coffee @@ -1,5 +1,11 @@ class Miner - tick: (tile) -> + tick: (tile)-> tile.click "left" - sprite: [0, 16, 8, 8] + sprite: -> + [0, 16, 8, 8] + + isMoveable: -> + true + + spaceProvided: 5 diff --git a/src/entities/silo.coffee b/src/entities/silo.coffee new file mode 100644 index 0000000..b8db818 --- /dev/null +++ b/src/entities/silo.coffee @@ -0,0 +1,21 @@ +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 + + spaceProvided: 150 + diff --git a/src/game.coffee b/src/game.coffee index a3791d3..34981f6 100644 --- a/src/game.coffee +++ b/src/game.coffee @@ -2,12 +2,15 @@ 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() render: -> for tile, i in @map @@ -37,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 @@ -46,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 @@ -63,6 +71,17 @@ app.game = miners: [] maxTileAmount: 15 + availableSiloStorage: -> + space = 0 + for tile in app.game.map + space += tile.spaceProvided + space + + usedSiloStorage: -> + space = 0 + space += amount for resource, amount of @resources + space + resources: stardust: 0 dirt: 0 diff --git a/src/hud.coffee b/src/hud.coffee index 5c086bb..68f4da4 100644 --- a/src/hud.coffee +++ b/src/hud.coffee @@ -1,11 +1,60 @@ app.game.hud = + start: -> + resTypes = (k for own k of app.game.resources) + + @position = x: 45, y: 103 + + @resources = [] + for restype, i in resTypes + @resources[restype] = new Tilelayer( + type: restype, + depth: i + ) + render: -> - app.layer.drawImage app.images.hud, 0, 12*8+2 - posy = 15 + app.layer.drawImage app.images.hud, 0, 11*8 + + i = 0 for type, amount of app.game.resources if amount > 0 - app.layer - .fillStyle "#000" - .font "10px Arial" - .wrappedText(amount+" x "+type, 5, posy, 800) - posy += 10 + #console.log @resources[type] + tileLayer = @resources[type] + + spritePosition = { + x: i*9+@position.x + y: @position.y + } + + app.layer.drawRegion app.images.layers, tileLayer.hudSprite, spritePosition.x, spritePosition.y + + amountByTwenty = Math.floor(amount/20) + amountLeft = amount - amountByTwenty*20 + for e in [0..amountLeft] + color = "#0a0" + color = "#0f0" if e == amountLeft + + if e < 6 + x = spritePosition.x-1+e + y = spritePosition.y-1 + else if e < 10 + x = spritePosition.x+4 + y = spritePosition.y-1+e-5 + else if e < 15 + x = spritePosition.x+14-e + y = spritePosition.y+4 + else + x = spritePosition.x-1 + y = spritePosition.y+19-e + + app.layer.setPixel(color, x, y) + + for f in [0..amountByTwenty] + if f > 0 + color = "#0000ff" + + x = spritePosition.x-2+f + y = spritePosition.y+7 + + app.layer.setPixel(color, x, y) + + i++ diff --git a/src/tiles/tile.coffee b/src/tiles/tile.coffee index c15ffc7..a5677cb 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()) or @isActive # 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] diff --git a/src/tiles/tilelayer.coffee b/src/tiles/tilelayer.coffee index 3882592..6c1ec1d 100644 --- a/src/tiles/tilelayer.coffee +++ b/src/tiles/tilelayer.coffee @@ -3,6 +3,7 @@ class Tilelayer {@type, @depth, @amount} = options @randomFactor = getRandomInt 0, 4 @sprite = [@randomFactor*8, @depth*8, 8, 8] + @hudSprite = [@randomFactor*8, @depth*8, 4, 4] collect: -> return false if @amount == 0