From ebae442b9bc8d63a2439a7262f5d0d3a6d050971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ruben=20M=C3=BCller?= Date: Sat, 6 Dec 2014 17:26:12 +0100 Subject: [PATCH 1/5] Changes --- src/entities/tile.coffee | 2 +- src/game.coffee | 18 ++++++++++++++++++ src/main.coffee | 15 --------------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/entities/tile.coffee b/src/entities/tile.coffee index cba6637..e042da6 100644 --- a/src/entities/tile.coffee +++ b/src/entities/tile.coffee @@ -13,7 +13,7 @@ class Tile extends BaseEntity click: (button)-> # console.log button - @isSelected = true + # @isSelected = true moveIn: -> @isActive = true diff --git a/src/game.coffee b/src/game.coffee index 9f0eef3..e4958a2 100644 --- a/src/game.coffee +++ b/src/game.coffee @@ -5,6 +5,8 @@ app.game = @miners = [] @miners.push = new Miner + + @currentHoveredTile = new Tile render: -> app.layer.save().scale(5, 5) @@ -20,6 +22,22 @@ app.game = step: -> + mousedown: (event)-> + @posToTile(event.x, event.y).click(event.button) + + mousemove: (event)-> + tile = @posToTile(event.x, event.y) + + if tile + if tile != @currentHoveredTile + tile.moveIn() + @currentHoveredTile.moveOut() + @currentHoveredTile = tile + + posToTile: (x, y)-> + pos = (Math.floor(y/8/5)*20) + Math.floor(x/8/5) + @map[pos] + map: [] resources: diff --git a/src/main.coffee b/src/main.coffee index 68890a4..a9c5f90 100644 --- a/src/main.coffee +++ b/src/main.coffee @@ -6,7 +6,6 @@ app = playground({ create: -> @loadImages "layers", "active", "selected", "entities" - @currentHoveredTile = new Tile ready: -> @game.start() @@ -14,22 +13,8 @@ app = playground({ step: -> - mousedown: (event)-> - @posToTile(event.x, event.y).click(event.button) - - mousemove: (event)-> - tile = @posToTile(event.x, event.y) - if tile != @currentHoveredTile - tile.moveIn() - @currentHoveredTile.moveOut() - @currentHoveredTile = tile - render: -> @layer.clear "#00f" @game.render() - - posToTile: (x, y)-> - pos = (Math.floor(y/8/5)*20) + Math.floor(x/8/5) - @game.map[pos] }) From 8b85c12512dd312d526ce9650d89f6deba723111 Mon Sep 17 00:00:00 2001 From: Aaron Mueller Date: Sat, 6 Dec 2014 17:32:37 +0100 Subject: [PATCH 2/5] dig deep, dude! --- src/entities/tile.coffee | 25 ++++++++++++++++--------- src/game.coffee | 1 + 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/entities/tile.coffee b/src/entities/tile.coffee index 28c53db..7a0857e 100644 --- a/src/entities/tile.coffee +++ b/src/entities/tile.coffee @@ -9,18 +9,21 @@ class Tile extends BaseEntity @layers.push new Tilelayer( type: restype, depth: i, - amount: Math.random(5)+10 + amount: Math.round(Math.random(app.game.maxTileAmount-10)+10) ) @currentLayer = 0 @isActive = false click: (button)-> - @isSelected = true - if button == "left" and @layers[@currentLayer].collect() - name = app.layerIndexToName(@currentLayer) - console.log(name) - app.game.resources[name] += 1 + #@isSelected = true + if button == "left" + if @layers[@currentLayer].collect() + name = app.layerIndexToName(@currentLayer) + app.game.resources[name] += 1 + else + @currentLayer += 1 + moveIn: -> @isActive = true @@ -35,7 +38,11 @@ class Tile extends BaseEntity tileLayer = @layers[@currentLayer] app.layer.drawRegion app.images.layers, tileLayer.sprite, x*8, y*8 - if @isSelected - app.layer.drawImage app.images.selected, x*8, y*8 - else if @isActive + #if @isSelected + # app.layer.drawImage app.images.selected, x*8, y*8 + if @isActive app.layer.drawImage app.images.active, x*8, y*8 + + # Draw the status indicator. + + diff --git a/src/game.coffee b/src/game.coffee index e4958a2..8c4b17b 100644 --- a/src/game.coffee +++ b/src/game.coffee @@ -39,6 +39,7 @@ app.game = @map[pos] map: [] + maxTileAmount: 15 resources: stardust: 10 From 945533b9edd218cd1e715d3b59c50585bbc5673e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ruben=20M=C3=BCller?= Date: Sat, 6 Dec 2014 17:38:03 +0100 Subject: [PATCH 3/5] Start with zero score --- src/game.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/game.coffee b/src/game.coffee index 8c4b17b..f471b9f 100644 --- a/src/game.coffee +++ b/src/game.coffee @@ -42,8 +42,8 @@ app.game = maxTileAmount: 15 resources: - stardust: 10 - bedrock: 1 + stardust: 0 + bedrock: 0 lubinit: 0 oxodum: 0 notch: 0 From eecacde582492022f8b4832e9dfb9003d991eb90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ruben=20M=C3=BCller?= Date: Sat, 6 Dec 2014 17:42:16 +0100 Subject: [PATCH 4/5] Fixed double bug --- src/main.coffee | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/main.coffee b/src/main.coffee index 3260965..5d7a67a 100644 --- a/src/main.coffee +++ b/src/main.coffee @@ -14,24 +14,10 @@ app = playground( step: -> - mousedown: (event)-> - @posToTile(event.x, event.y).click(event.button) - - mousemove: (event)-> - tile = @posToTile(event.x, event.y) - if tile != @currentHoveredTile - tile.moveIn() - @currentHoveredTile.moveOut() - @currentHoveredTile = tile - render: -> @layer.clear "#00f" @game.render() - posToTile: (x, y)-> - pos = (Math.floor(y/8/5)*20) + Math.floor(x/8/5) - @game.map[pos] - layerIndexToName: (index)-> resTypes = (k for own k of @game.resources) resTypes[index] From 8d5e7c10ff1ec7899d8b032531143ea661cf0207 Mon Sep 17 00:00:00 2001 From: Aaron Mueller Date: Sat, 6 Dec 2014 17:42:23 +0100 Subject: [PATCH 5/5] Start with the amount indicator --- src/entities/tile.coffee | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/entities/tile.coffee b/src/entities/tile.coffee index 7a0857e..8692fbd 100644 --- a/src/entities/tile.coffee +++ b/src/entities/tile.coffee @@ -22,8 +22,7 @@ class Tile extends BaseEntity name = app.layerIndexToName(@currentLayer) app.game.resources[name] += 1 else - @currentLayer += 1 - + @currentLayer += 1 moveIn: -> @isActive = true @@ -42,7 +41,11 @@ class Tile extends BaseEntity # app.layer.drawImage app.images.selected, x*8, y*8 if @isActive app.layer.drawImage app.images.active, x*8, y*8 + # Draw the status indicator. + for i in [0..5] + color = "#0a0" + color = "#0f0" if i == 5 + app.layer.setPixel(color, x*8+1+i, y*8+6) - # Draw the status indicator.