diff --git a/data/animations.lua b/data/animations.lua new file mode 100644 index 0000000..96902e7 --- /dev/null +++ b/data/animations.lua @@ -0,0 +1,11 @@ + +animations = { + ["hero_walk"] = { + cycle = {1,2,1,3}, + frames = { + { frame={x=0,y=0,w=16,h=17}, wait=4 }, + { frame={x=16,y=0,w=16,h=17}, wait=4 }, + { frame={x=32,y=0,w=16,h=17}, wait=4 } + } + } +} \ No newline at end of file diff --git a/data/editor.lua b/data/editor.lua index 35feb8c..ccbf50f 100644 --- a/data/editor.lua +++ b/data/editor.lua @@ -10,7 +10,6 @@ editor = { modified = false, enable = function() - menu.show() app.update = editor.update sys.beat(2) end, @@ -109,6 +108,12 @@ editor = { end, stamp=function(tx,ty) + if editor.layer == LAYER_FOREGROUND then + map.surf(rooms.surf_foreground) + elseif editor.layer == LAYER_BACKGROUND then + map.surf(rooms.surf_background) + end + local w,h=editor.brush.w,editor.brush.h local p=1 for y=1,h do @@ -145,7 +150,7 @@ editor = { update_tiles = function() view.origin(0,0) view.clip() - surf.source(tiles) + surf.source(surf_tiles) surf.cls(1) draw.surf(0,0,128,128,0,0) diff --git a/data/game.lua b/data/game.lua new file mode 100644 index 0000000..c4a75be --- /dev/null +++ b/data/game.lua @@ -0,0 +1,18 @@ +game = { + + enable = function() + app.update = game.update + sys.beat(20) + end, + + update = function() + view.origin(0,0) + surf.target(0) + + score.draw() + + -- Pintar el mapa i sprites + rooms.draw() + + end +} \ No newline at end of file diff --git a/data/main.lua b/data/main.lua index f17b36d..34bc6f6 100644 --- a/data/main.lua +++ b/data/main.lua @@ -4,8 +4,8 @@ require "rooms" require "editor" function mini.init() - sprites = surf.load("sprites.gif") - tiles = surf.load("tiles.gif") + surf_sprites = surf.load("sprites.gif") + surf_tiles = surf.load("tiles.gif") pal.set(pal.load("tiles.gif")) pal.trans(0) diff --git a/data/menu.lua b/data/menu.lua index 8be5ac4..4f538da 100644 --- a/data/menu.lua +++ b/data/menu.lua @@ -1,20 +1,11 @@ require "popup" menu = { - visible = false, current_x = 0, init = function() end, - show = function() - menu.visible = true - end, - - hide = function() - menu.visible = false - end, - draw = function() view.origin(0,0) view.clip() diff --git a/data/rooms.lua b/data/rooms.lua index 79c526b..7c7debf 100644 --- a/data/rooms.lua +++ b/data/rooms.lua @@ -1,3 +1,5 @@ +require "sprites" + LAYER_FOREGROUND = 1 LAYER_BACKGROUND = 2 LAYER_ITEMS = 4 @@ -32,6 +34,7 @@ rooms = { surf.target(rooms.surf_original_items) draw.surf(0,0,160,96,0,0) + sprites.init() --map.surf(rooms.surf_background) --for y=0,12*8 do -- for x=0,20*8 do @@ -64,7 +67,7 @@ rooms = { view.origin(-rooms.pos.x*8,-rooms.pos.y*8+8) -- Pintem el background - surf.source(tiles) + surf.source(surf_tiles) map.surf(rooms.surf_background) if rooms.is_visible(LAYER_BACKGROUND) then map.draw() @@ -81,10 +84,9 @@ rooms = { if rooms.is_visible(LAYER_FOREGROUND | LAYER_SHADOWS) then map.draw() end -- Pintem els sprites de negre - -- [TODO] - surf.source(sprites) if rooms.is_visible(LAYER_SPRITES | LAYER_SHADOWS) then - draw.surf(0, 0, 16, 17, 10, 10, 16, 17) + sprites.draw() + --draw.surf(0, 0, 16, 17, 20, 15, 16, 17) end -- Movem la càmara al lloc que toca de nou, i tornem la paleta normal @@ -92,17 +94,17 @@ rooms = { pal.subpal() -- Pintem el foreground - surf.source(tiles) + surf.source(surf_tiles) map.surf(rooms.surf_foreground) if rooms.is_visible(LAYER_FOREGROUND) then map.draw() end -- Pintem els sprites - -- [TODO] - surf.source(sprites) if rooms.is_visible(LAYER_SPRITES) then - draw.surf(0, 0, 16, 17, 10, 10, 16, 17) + sprites.draw() + --draw.surf(0, 0, 16, 17, 20, 15, 16, 17) end + sprites.update() -- Pintem la rejilla --for y=0,12 do draw.line(0,y*8, 160, y*8, 27) end --for x=0,20 do draw.line(x*8, 0, x*8, 104, 27) end diff --git a/data/rooms_foreground.bin b/data/rooms_foreground.bin index da30aa0..8a1f60b 100644 Binary files a/data/rooms_foreground.bin and b/data/rooms_foreground.bin differ diff --git a/data/sprites.lua b/data/sprites.lua new file mode 100644 index 0000000..59ecd36 --- /dev/null +++ b/data/sprites.lua @@ -0,0 +1,48 @@ +require "animations" + +sprites = { + hero = nil, + list = {}, + + init = function() + sprites.hero = { + pos = { x=24, y=15 }, + size= { w=16, h=17 }, + bbo = { left=0, top=0, right=0, bottom=0 }, + animation = "hero_walk", + current_frame = 1, + current_wait = 1 + } + end, + + update = function() + sprites.update_sprite(sprites.hero) + end, + + update_sprite = function(sprite) + if sys.beat() then + sprite.current_wait = sprite.current_wait - 1 + if sprite.current_wait == 0 then + if sprite.current_frame < #animations[sprite.animation].cycle then + sprite.current_frame = sprite.current_frame + 1 + else + sprite.current_frame = 1 + end + local cycle = animations[sprite.animation].cycle[sprite.current_frame] + sprite.current_wait = animations[sprite.animation].frames[cycle].wait + end + end + end, + + draw = function() + surf.source(surf_sprites) + + sprites.draw_sprite(sprites.hero) + end, + + draw_sprite = function(sprite) + local cycle = animations[sprite.animation].cycle[sprite.current_frame] + local frame = animations[sprite.animation].frames[cycle] + draw.surf(frame.frame.x, frame.frame.y, frame.frame.w, frame.frame.h, sprite.pos.x, sprite.pos.y, sprite.size.w, sprite.size.h) + end +} \ No newline at end of file diff --git a/data/tiles.gif b/data/tiles.gif index cb393b5..56f1a4a 100644 Binary files a/data/tiles.gif and b/data/tiles.gif differ