Skip to content

Commit

Permalink
decorations and stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
leafo committed Aug 27, 2012
1 parent 297b2a7 commit 2e3ea81
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 12 deletions.
8 changes: 4 additions & 4 deletions attack.moon
Expand Up @@ -32,11 +32,11 @@ class Spear

@sprite = with Spriter "img/sprite.png"
@anim = StateAnim "down", {
left: \seq {"40,5,11,5"}, 0, true
up: \seq {"43,13,5,11"}
left: \seq {"39,5,12,5"}, 0, true
up: \seq {"43,13,5,12"}

right: \seq {"40,5,11,5"}
down: \seq {"43,13,5,11"}, 0, true, true
right: \seq {"39,5,12,5"}
down: \seq {"43,13,5,12"}, 0, true, true
}

-- draw on player
Expand Down
8 changes: 3 additions & 5 deletions autotile.moon
Expand Up @@ -191,7 +191,7 @@ class Autotile

tiles[i] = t for i, t in pairs to_add

make_solid: (from_layer=1)=>
make_solid: (from_layer=1) =>
solid_layer = {}
is_solid = Set { @types.wall, @types.border }

Expand All @@ -214,11 +214,9 @@ class Autotile
@map.layers[layer][i] = nil
@map.layers[to_layer][i] = tile

new: (fname, @tilesets={}) =>
new: (fname, @tilesets={}, color_to_tile) =>
sprite = FakeSpriter 16, 16
@map = TileMap.from_image fname, sprite, {
["59,57,77"]: { tid: @types.floor }
}
@map = TileMap.from_image fname, sprite, color_to_tile

@add_walls!
@add_surrounding!
Expand Down
Binary file modified img/map.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 img/sprite.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 img/tiles.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 82 additions & 1 deletion levels/all.moon
Expand Up @@ -2,7 +2,9 @@ export ^

class World
new: (@game) =>
@decorations = DrawList!
@map = @make_map!

@particles = DrawList!
@high_particles = DrawList!
@entities = DrawList!
Expand All @@ -11,6 +13,7 @@ class World

draw: =>
@map\draw_below @game.viewport
@decorations\draw!

@entities\sort!
@entities\draw!
Expand All @@ -23,6 +26,7 @@ class World
@high_particles\draw!

update: (dt) =>
@decorations\update dt
@entities\update dt
@particles\update dt
@high_particles\update dt
Expand All @@ -40,6 +44,56 @@ class World
if e.hurt_player and e.box\touches_box player.box
e\hurt_player player

class Decoration extends Box
w: 16, h: 16
ox: 0, oy: 0

new: (@x, @y, @cell_id) =>
@x += @ox
@y += @oy

if not Decoration.__base.sprite
Decoration.__base.sprite = with Spriter "img/tiles.png", @w, @h, 14
.oy = 64

update: (dt) => true
draw: =>
@sprite\draw_cell @cell_id, @x - @ox, @y - @oy

class UpDoor extends Decoration
cell_id: 2

class DownDoor extends Decoration
cell_id: 3

ox: 2, oy: 5
w: 13, h: 9

on_touch: (player) => print "touching exit"


class RandomDecor extends Decoration
cells: {}
new: (x,y) =>
super x,y, @cells[math.random 1, #@cells]

class FloorDecor extends RandomDecor
cells: { 10 }

class WallDecor extends RandomDecor
cells: { 9, 8 }

class BloodPit extends Decoration
new: (x, y) =>
super x, y
@anim = @sprite\seq { 11, 12, 13 }, 0.4

update: (dt) =>
@anim\update dt
super

draw: =>
@anim\draw @x - @ox, @y - @oy

class Level extends World
floor_color: "59,57,77"
Expand All @@ -52,11 +106,38 @@ class Level extends World
{ BorderTileSpriter, "img/tiles.png", 16, 16, 48*2 }
}

tile_colors: {
["59,57,77"]: => Autotile.types.floor

["160,62,97"]: (x,y) =>
@decorations\add UpDoor x,y
nil

["62,160,69"]: (x,y) =>
@decorations\add DownDoor x,y
Autotile.types.floor

["160,62,62"]: (x,y) =>
@decorations\add BloodPit x,y
Autotile.types.floor

["86,100,174"]: (x, y) =>
@decorations\add WallDecor x,y
nil

["41,40,54"]: (x,y) =>
@decorations\add FloorDecor x,y
Autotile.types.floor
}

make_map: =>
tilesets = for row in *@tilesets
cls = table.remove row, 1
cls unpack row

Autotile @map_file, tilesets
-- bind all the functions in tile_colors
bind = (fn, object) -> (...) -> fn object, ...
tile_colors = { k, bind v, self for k,v in pairs @tile_colors }

Autotile @map_file, tilesets, tile_colors

5 changes: 3 additions & 2 deletions main.moon
Expand Up @@ -96,8 +96,8 @@ class Player extends Entity
@weapon\draw! if @weapon
@draw_player!
else
@weapon\draw! if @weapon
@draw_player!
@weapon\draw! if @weapon

draw_player: =>
@hit\before! if @hit
Expand Down Expand Up @@ -151,7 +151,7 @@ class Game

update: (dt) =>
reloader\update dt
@player.velocity = movement_vector 60
@player.velocity = movement_vector 120
@world\update dt

hello\update dt
Expand Down Expand Up @@ -185,5 +185,6 @@ love.load = ->
love.mousepressed = (x,y, button) ->
x, y = game.viewport\unproject x, y
print "mouse", x, y, button
print game.world.map


0 comments on commit 2e3ea81

Please sign in to comment.