diff --git a/images/bg2.png b/images/bg2.png index 0b31e56..61e95b9 100644 Binary files a/images/bg2.png and b/images/bg2.png differ diff --git a/images/map1.png b/images/map1.png index a646049..b9e91ca 100644 Binary files a/images/map1.png and b/images/map1.png differ diff --git a/images/player.png b/images/player.png index f765f5d..b63b6b8 100644 Binary files a/images/player.png and b/images/player.png differ diff --git a/images/small.png b/images/small.png index 66882ac..91d74c2 100644 Binary files a/images/small.png and b/images/small.png differ diff --git a/images/tiles.png b/images/tiles.png index 2188b58..48f189b 100644 Binary files a/images/tiles.png and b/images/tiles.png differ diff --git a/main.moon b/main.moon index c8fbfcc..09452ce 100644 --- a/main.moon +++ b/main.moon @@ -100,7 +100,7 @@ class World oy: 1210 } } - @map = Map.from_image "images/small.png", "images/tiles.png" + @map = Map.from_image "images/map1.png", "images/tiles.png" @overlay = (y) -> p = y / @map.real_height @@ -189,8 +189,8 @@ class Game extends GameState setColor {255,255,255} graphics.print tostring(love.timer.getFPS!), 10, 10 - graphics.print tostring(@player.box), 10, 20 - graphics.print tostring(@player), 10, 30 + -- graphics.print tostring(@player.box), 10, 20 + -- graphics.print tostring(@player), 10, 30 keypressed: (key, code) => if key == "lctrl" diff --git a/map.moon b/map.moon index 77d7665..a864244 100644 --- a/map.moon +++ b/map.moon @@ -6,34 +6,115 @@ require "collide" import rectangle, setColor, getColor from love.graphics import mixin_object from moon +import random from math export * style = { - dirt: 0 - hot: 3 - surface: 1 - behind: 2 + solid: 0 + solid_decor1: 16 + solid_decor2: 24 + + top: 1 + bottom: 18 + + back: 2 + back_floor: 13 + back_ceil: 14 + + back_topleft: 17 + + decor1: 4 + + hot: { + back: 3 + top: 6 + bottom: 5 + } + + inside: { + back: 9 + top: 10 + decor1: 11 + decor2: 12 + } + } hash_color = (r,g,b) -> r.."-"..g.."-"..b +nothing = (tile) -> + tile == nil or tile and tile.layer == 0 + tile_types = { ["0-0-0"]: { - sid: style.dirt + sid: style.solid layer: 1 + auto: (x,y) => + above = @tiles[@to_i x, y - 1] + if nothing above + style.top + else + below = @tiles[@to_i x, y + 1] + if nothing below + style.bottom + else + r = random! + if r > 0.98 + style.solid_decor1 + elseif r > 0.95 + style.solid_decor2 } ["107-0-3"]: { - sid: style.hot + sid: style.hot.back layer: 1 + auto: (x,y) => + below = @tiles[@to_i x, y + 1] + if nothing below + style.hot.bottom + else + above = @tiles[@to_i x, y - 1] + if nothing above + style.hot.top + } ["198-132-49"]: { - sid: style.behind + sid: style.back layer: 0 + auto: (x,y) => + below = @tiles[@to_i x, y + 1] + if below and below.layer == 1 + style.back_floor + else + -- check if corner + left = @tiles[@to_i x - 1, y] + above = @tiles[@to_i x, y - 1] + if left == nil and above == nil + style.back_topleft + elseif above and above.layer == 1 + style.back_ceil + elseif random! > 0.95 + style.decor1 } + + ["245-134-78"]: { + sid: style.inside.back + layer: 0 + auto: (x,y) => + above = @tiles[@to_i x, y - 1] + if above == nil + style.inside.top + else + r = random! + if r > 0.98 + style.inside.decor1 + elseif r > 0.96 + style.inside.decor2 + } + ["255-0-0"]: { spawn: true } } @@ -60,6 +141,7 @@ class Map tile = tile_types[hash_color r,g,b,a] tiles[len] = if tile if tile.spawn + print "found spawn" spawn = {x,y} nil else @@ -82,9 +164,14 @@ class Map @real_width = @width * @cell_size @real_height = @height * @cell_size - @layers = {} + -- do the autotiles + for x,y,t,i in @each_xyt! + if t and t.auto + sid = t.auto self, x,y,t,i + if sid + @tiles[i] = { layer: t.layer, :sid } - ground = {} + @layers = {} for x,y,t,i in @each_xyt! if t box = Tile t.sid, @@ -97,15 +184,12 @@ class Map @layers[t.layer] = layer! if not @layers[t.layer] @layers[t.layer]\add box - if t.layer == 1 -- ground - ground[i] = box - - -- color the tiles - for x,y,t in @each_xyt ground - if t - above = ground[@to_i x, y - 1] - if above == nil - t.sid = style.surface + -- -- color the tiles + -- for x,y,t in @each_xyt ground + -- if t + -- above = ground[@to_i x, y - 1] + -- if above == nil + -- t.sid = style.surface print "min:", @min_layer, "max:", @max_layer @solid = @layers[1] @@ -130,7 +214,7 @@ class Map i -= 1 x = i % @width y = math.floor(i / @width) - coroutine.yield x, y, t, i + coroutine.yield x, y, t, i + 1 draw: (viewport) => for i=@min_layer,@max_layer