Files
jailsadventure2/data/balloon.lua

145 lines
4.5 KiB
Lua

require "scene"
balloon={
text=nil,
pos=1,
ini=1,
cursor={x=0,y=0},
old_update=nil,
rect=nil,
quick=false,
show=function(txt,col,actorname,below,rectangle)
local actor = actors.search(actorname)
if not actor then return end
if rectangle==nil then
balloon.rect={x=8,y=actor.y*8-4-game.cam.y,w=144,h=35}
else
balloon.rect={}
balloon.rect.x=rectangle.x*8
balloon.rect.y=actor.y*8-4-game.cam.y
balloon.rect.w=rectangle.w*8
balloon.rect.h=rectangle.h*9+8
end
balloon.text=txt
balloon.color=col
balloon.pos=1
balloon.ini=1
balloon.obj=nil
balloon.quick=false
balloon.old_update=update
update=balloon.update
local pos=actor.x*8+8-game.cam.x
if below==nil or below==false then
balloon.rect.y=balloon.rect.y-balloon.rect.h-16
local x,y,w,h=balloon.rect.x,balloon.rect.y,balloon.rect.w,balloon.rect.h
draw.rectf(x+1,y+1,w+1,h+1,5)
draw.rectf(x,y,w+1,h+1,8)
draw.rect(x,y,w+1,h+1,6)
if pos<80 then
for i=0,4 do draw.rect(pos,y+h+(4-i),i+1,2,8) end
draw.line(pos-1,y+h+1,pos-1,y+h+6,6)
draw.line(pos+4,y+h+1,pos-1,y+h+6,6)
else
pos=pos-5
for i=0,4 do draw.rect(pos+i,y+h+i,5-i,2,8) end
draw.line(pos+5,y+h+1,pos+5,y+h+6,6)
draw.line(pos,y+h+1,pos+5,y+h+6,6)
end
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
draw.rectf(x+1,y+1,w+1,h+1,5)
draw.rectf(x,y,w+1,h+1,8)
draw.rect(x,y,w+1,h+1,6)
if pos<80 then
for i=0,4 do draw.rect(pos,y-(4-i),i+1,2,8) end
draw.line(pos-1,y,pos-1,y-6,6)
draw.line(pos+5,y,pos-1,y-6,6)
else
pos=pos-5
for i=0,4 do draw.rect(pos+i,y-i,5-i,2,8) end
draw.line(pos+5,y,pos+5,y-6,6)
draw.line(pos-1,y,pos+5,y-6,6)
end
end
balloon.cursor={x=balloon.rect.x+8,y=balloon.rect.y+7}
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.quick=false
balloon.old_update=update
update=balloon.update
local x,y,w,h=balloon.rect.x,balloon.rect.y,balloon.rect.w,balloon.rect.h
draw.rectf(x+1,y+1,w+1,h+1,5)
draw.rectf(x,y,w+1,h+1,15)
draw.rect(x,y,w+1,h+1,6)
balloon.cursor={x=balloon.rect.x+12,y=balloon.rect.y+11}
end,
update=function()
if key.any() then
if balloon.pos<0 then
update=balloon.old_update
update()
scene.cont()
else
balloon.quick=true
end
end
if not sys.beat() and not balloon.quick then return end
if balloon.pos<0 then
if balloon.obj then
surf.source(objectes)
draw.surf(balloon.obj.x,balloon.obj.y,16,16,balloon.rect.x+balloon.rect.w-28,balloon.rect.y+10)
end
local col=8
if math.floor(sys.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
draw.line(x,y,x+4,y,col)
draw.line(x+1,y+1,x+3,y+1,col)
draw.line(x+2,y+2,x+2,y+2,col)
if key.press(key.SPACE) then
update=balloon.old_update
end
else
local txt=string.sub(balloon.text,balloon.ini,balloon.pos)
local char=string.sub(balloon.text,balloon.pos,balloon.pos)
if char=='' then
-- final
balloon.pos=-1
--update=balloon.old_update
elseif char=='\n' then
-- salt de linea
balloon.pos=balloon.pos+1
balloon.ini=balloon.pos
--balloon.cursor.x=balloon.rect.x+8
balloon.cursor.y=balloon.cursor.y+9
else
text(txt,balloon.cursor.x,balloon.cursor.y,balloon.color)
balloon.pos=balloon.pos+1
--balloon.cursor.x=balloon.cursor.x+4
end
end
end
}