From 1250921e4b777d04dee2f54204093f71a24812a0 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Wed, 1 Feb 2023 17:14:20 +0100 Subject: [PATCH] - Sistema d'objectes funcionant --- data/balloon.lua | 36 ++++++++++++++++++++++++++++-------- data/editor.lua | 1 + data/game.lua | 23 +++++++++++++++-------- data/menu.lua | 6 +++--- data/objects.lua | 1 + 5 files changed, 48 insertions(+), 19 deletions(-) diff --git a/data/balloon.lua b/data/balloon.lua index 46e54cb..d49eebd 100644 --- a/data/balloon.lua +++ b/data/balloon.lua @@ -6,7 +6,7 @@ balloon={ old_update=nil, rect=nil, - show=function(txt,actorname,below,rectangle) + show=function(txt,col,actorname,below,rectangle) local actor = actors.search(actorname) if not actor then return end @@ -21,13 +21,15 @@ balloon={ end balloon.text=txt + balloon.color=col balloon.pos=1 balloon.ini=1 + balloon.obj=nil balloon.old_update=update update=balloon.update - local pos,height=actor.x*8+4,actor.y*8-4 + local pos=actor.x*8+4 if below==nil or below==false then balloon.rect.y=balloon.rect.y-balloon.rect.h-16 @@ -46,7 +48,6 @@ balloon={ line(pos+5,y+h+1,pos+5,y+h+6,6) line(pos,y+h+1,pos+5,y+h+6,6) end - height=height+7 else balloon.rect.y=balloon.rect.y+16 local x,y,w,h=balloon.rect.x,balloon.rect.y,balloon.rect.w,balloon.rect.h @@ -64,13 +65,28 @@ balloon={ line(pos+5,y,pos+5,y-6,6) line(pos-1,y,pos+5,y-6,6) end - height=height+7 end balloon.cursor={x=balloon.rect.x+8,y=balloon.rect.y+7} - --text("12345678901234567890123456789012\n3",16,height, 2) - --text("UNO DOS TRES",16,height+9, 2) - --text("UNO DOS TRES",16,height+18, 2) + end, + + narrator=function(obj) + balloon.rect={x=8,y=48,w=144,h=35} + balloon.text="HAS ACONSEGUIT:\n"..obj.name.."!" + balloon.color=8 + balloon.pos=1 + balloon.ini=1 + balloon.obj=obj + + balloon.old_update=update + update=balloon.update + + local x,y,w,h=balloon.rect.x,balloon.rect.y,balloon.rect.w,balloon.rect.h + rectfill(x+1,y+1,x+w+1,y+h+1,5) + rectfill(x,y,x+w,y+h,15) + rect(x,y,x+w,y+h,6) + + balloon.cursor={x=balloon.rect.x+12,y=balloon.rect.y+11} end, update=function() @@ -82,6 +98,10 @@ balloon={ if not beat() then return end if balloon.pos<0 then + if balloon.obj then + setsource(objectes) + sspr(balloon.obj.x,balloon.obj.y,16,16,balloon.rect.x+balloon.rect.w-28,balloon.rect.y+10) + end local col=8 if flr(time()*4)%2==0 then col=10 end local x,y=balloon.rect.x+balloon.rect.w-8, balloon.rect.y+balloon.rect.h-6 @@ -105,7 +125,7 @@ balloon={ --balloon.cursor.x=balloon.rect.x+8 balloon.cursor.y=balloon.cursor.y+9 else - text(txt,balloon.cursor.x,balloon.cursor.y,2) + text(txt,balloon.cursor.x,balloon.cursor.y,balloon.color) balloon.pos=balloon.pos+1 --balloon.cursor.x=balloon.cursor.x+4 end diff --git a/data/editor.lua b/data/editor.lua index 06a360c..1b61c28 100644 --- a/data/editor.lua +++ b/data/editor.lua @@ -91,6 +91,7 @@ editor={ update=function() cls() camera(editor.cam.x, editor.cam.y) + setsource(tiles) map(0,0,0,0,mapa.w, mapa.h) local mx,my=mousex()+editor.cam.x,mousey()+editor.cam.y diff --git a/data/game.lua b/data/game.lua index 1f9cae6..8f0677a 100644 --- a/data/game.lua +++ b/data/game.lua @@ -6,9 +6,11 @@ game={ mapa.load("test.map") actors.add({name="jailer",x=6,y=9,o="r",gfx={x=32,y=0}}) + actors.add({name="estudiant",x=12,y=8,o="d",gfx={x=64,y=0}}) actors.hero="jailer" update=game.update + --objects.collect({name="diskette",x=0,y=0}) switches.add({x=8,y=8,w=1,h=3,action= function() @@ -18,12 +20,13 @@ game={ function() actors.add({name="usufondo",x=16,y=8,o="d",gfx={x=0,y=0}}) scene.cont() end, function() wait.start(1) end, function() actors.search("usufondo").path={pos=0,route='dlllll'} end, - function() balloon.show("HOY NO HAY JAIL!\nTU MISMO!!","usufondo",false,{x=7,w=10,h=2}) end, + function() balloon.show("HOY NO HAY JAIL!\nTU MISMO!!",10,"usufondo",false,{x=7,w=10,h=2}) end, + function() objects.collect({name="DISQUITO DE USUFONDO",x=0,y=0}) end, function() actors.search("usufondo").path={pos=0,route='rrrrru'} end, function() wait.start(0.5) end, function() actors.remove("usufondo") scene.cont() end, function() wait.start(1) end, - function() balloon.show("IMBÈSIL...","jailer",true,{x=5,w=7,h=1}) end + function() balloon.show("IMBÈSIL...",2,"jailer",true,{x=5,w=7,h=1}) end }) end end @@ -78,14 +81,18 @@ game={ pause=function() game.paused = true - rectfill(10,84, 150, 128,6) - rect(10,84, 150, 128,8) - rect(9,83, 151, 129,6) + rectfill(9,84, 150, 128,6) + rect(9,84, 150, 128,8) + rect(8,83, 151, 129,6) text("OBJECTES:",14,82,8) setsource(objectes) - sspr(0,0,16,16,14,89) - sspr(0,0,16,16,34,89) - sspr(0,0,16,16,14,109) + + local x,y=15,90 + for k,v in pairs(objects.list) do + sspr(v.x,v.y,16,16,x,y) + x=x+19 + if x==148 then x,y=15,y+19 end + end end, resume=function() diff --git a/data/menu.lua b/data/menu.lua index 568a90f..d335017 100644 --- a/data/menu.lua +++ b/data/menu.lua @@ -15,9 +15,9 @@ menu = { update=function() --menu.old_update() - rectfill(10,20, 150, 34+#menu.options*10,6) - rect(10,20, 150, 34+#menu.options*10,8) - rect(9,19, 151, 35+#menu.options*10,6) + rectfill(9,20, 150, 34+#menu.options*10,6) + rect(9,20, 150, 34+#menu.options*10,8) + rect(8,19, 151, 35+#menu.options*10,6) for i,v in ipairs(menu.options) do color(4) if menu.selected==i then color(15) prnt(">",20,20+i*10) end diff --git a/data/objects.lua b/data/objects.lua index f090bd5..dd5c48e 100644 --- a/data/objects.lua +++ b/data/objects.lua @@ -3,6 +3,7 @@ objects={ collect=function(obj) table.insert(objects.list, obj) + balloon.narrator(obj) end, search=function(name)