Merge remote-tracking branch 'origin/master'

This commit is contained in:
Jonas1989 2014-12-07 00:58:34 +01:00
commit 37fbf37f6c
11 changed files with 123 additions and 14 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 510 B

After

Width:  |  Height:  |  Size: 739 B

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: ->

11
src/entities/base.coffee Normal file
View file

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

View file

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

21
src/entities/silo.coffee Normal file
View file

@ -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

View file

@ -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

View file

@ -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++

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()) 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]

View file

@ -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