From 9a6bceec91f4a46c0e080f788b7025090b6b60b0 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Fri, 20 Jun 2025 18:32:46 +0200 Subject: [PATCH] - [NEW] 'animations' module - [NEW] 'game' module - [NEW] 'sprites' module - [NEW] more tiles - [NEW] Can choose which tile layer to edit from the editor menu --- data/animations.lua | 11 +++++++++ data/editor.lua | 9 +++++-- data/game.lua | 18 ++++++++++++++ data/main.lua | 4 ++-- data/menu.lua | 9 ------- data/rooms.lua | 18 +++++++------- data/rooms_foreground.bin | Bin 263 -> 272 bytes data/sprites.lua | 48 ++++++++++++++++++++++++++++++++++++++ data/tiles.gif | Bin 897 -> 952 bytes 9 files changed, 96 insertions(+), 21 deletions(-) create mode 100644 data/animations.lua create mode 100644 data/game.lua create mode 100644 data/sprites.lua 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 da30aa073a80296080393531cd017ba415857900..8a1f60bd0edee3121ce9a4fb276ab30c2a049998 100644 GIT binary patch delta 153 zcmV;K0A~M(0+0fb7=QHuVZ;zfaG=401pz2r$grWqhY%x5oJg^v#fumj4$R20qsNaR zLvj=-vZTqAC{b=q$+D%(mkI?!h%ghT&6_wW4m5Ber_Y~01tI`Sv}ntfMw2T2NOGyu zrxlSxok}%kjH+0thSgC!-^eCwyfE+Xw#})%eJlCw~?1>5A)~Hqf4Joy}EUa H0RaFzSo241 delta 144 zcmV;B0B`@00*3;S7=P>l0SFvOu%N+%2oow?$grWqhY%wklrTY}#fum-YTUR`#0ZWc zLy8=!ks`^HC{v>J2q8jCl`vz!bxC!q)d*0tYTe4UtJkk!!-^eCwyfE+Xw#})%eJlCw~?1>26Kl20RTIa`9cf; 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 cb393b5aa25e9f094d10703b6f8766dbf7724c85..56f1a4a3cb404fe024c30de6e8e8d1f53b276d17 100644 GIT binary patch delta 721 zcmV;?0xtc52e=22mVcrRTs@L-NGuwUNRkZZYQAR68L&p;1x421HOcLIi&27e%u0m= z8{ki^)?%yKuY8Uq+wV>42sesbb##G(LuOGiGb?8@Whg*?RDL;wlaz%^hhm9_i<&2n zdwqVCqk}Mphb^Z}DvfV#Zltk;c(izGl0C1oyG8*6zrex3Eq?~Z#>d4h3CqmQ%K^M4 zD#+B;$&|na1KQl%1qBR=#TDe_78U0f1}X!~5%2F55%LrX(E!s1=;izA<^JlhZ5zn# z+cyT`Sn1wG1E7mtEPdG?}B>zB?UK#vfy85~IxoVbPj(El}z*lr@liuLYI z^Ov%wxs?J*GJgQa6QMYp<{+|j`7&OFjJ!6UE4Q#|%5w%p9_-oEr$UrZ)eR;3(jwAb zGnrZ&cQfjw00`5nRa*w@Q=t-z!ow&t0Lo*;j0H72tJYPZ*|B5*o9uGjvI&`4LPdm27dty=6_n$aIBe2JLlaTa*~13qB8^# z9hEm~6Z+ip6MXctYf?%Rk6|3}Y!lqKMgJ8Zcx!RF$44P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