Skip to content

Commit

Permalink
new graphics
Browse files Browse the repository at this point in the history
  • Loading branch information
leafo committed Dec 18, 2011
1 parent 35f02a2 commit 4e514b2
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 22 deletions.
Binary file modified images/bg2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/map1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/player.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/small.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/tiles.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions main.moon
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
122 changes: 103 additions & 19 deletions map.moon
Expand Up @@ -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 }
}

Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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]
Expand All @@ -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
Expand Down

0 comments on commit 4e514b2

Please sign in to comment.