From a44117d1dd51243d021bba775a14aa325f44ebb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ruben=20M=C3=BCller?= Date: Sat, 6 Dec 2014 14:28:58 +0100 Subject: [PATCH] Tileset fun --- src/entities/tile.coffee | 5 ++++- src/entities/tilelayer.coffee | 24 +++++++++++++----------- src/main.coffee | 1 + 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/entities/tile.coffee b/src/entities/tile.coffee index 08af36f..64de3e0 100644 --- a/src/entities/tile.coffee +++ b/src/entities/tile.coffee @@ -4,7 +4,10 @@ class Tile extends BaseEntity resTypes = (k for own k of app.game.resources) - @layers = (new Tilelayer(type: restype) for restype in resTypes) + @layers = [] + for restype in resTypes + @layers.push new Tilelayer(type: restype) + #@layers = (new Tilelayer(type: restype) for restype in resTypes) @currentLayer = getRandomInt 0, resTypes.length-1 tick: (delta) -> diff --git a/src/entities/tilelayer.coffee b/src/entities/tilelayer.coffee index 95fcd61..e0031b3 100644 --- a/src/entities/tilelayer.coffee +++ b/src/entities/tilelayer.coffee @@ -2,16 +2,18 @@ class Tilelayer extends BaseEntity constructor: (options) -> {@type, @depth, @amount} = options - render: (layer, x, y)-> - # TODO: Draw sprite - + render: (layer, x, y) -> switch @type - when "grass" then color = "green" - when "mud" then color = "brown" - when "gravel" then color = "lightgrey" - when "stone" then color = "darkgrey" - when "gold" then color = "yellow" + when "stardust" then color = [0, 0, 8, 8] + when "bedrock" then color = [0, 0, 8, 8] + when "lubinit" then color = [0, 0, 8, 8] + when "oxodum" then color = [0, 0, 8, 8] + when "notch" then color = [0, 0, 8, 8] - layer.fillStyle color - .fillRect x*8, y*8, 8, 8 - + #layer.fillStyle color + # .fillRect x*8, y*8, 8, 8 + + layer.drawRegion app.images.layers, color, x*8, y*8 + + getSpriteForType: (i) -> + \ No newline at end of file diff --git a/src/main.coffee b/src/main.coffee index 7ff68bf..cab6fde 100644 --- a/src/main.coffee +++ b/src/main.coffee @@ -5,6 +5,7 @@ app = playground({ smoothing: false, create: -> + @loadImages "layers" ready: -> @game.start()