an atelier fangame for the pico-8
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
atelier_phoebe/conversation.lua

81 lines
2.3 KiB

prev_screen = screen_workbench
message_idx = 1
conversation_active = false
function phoebe_say(face_sprite, words, ...)
x,y=10,80
--background color
local c = sget((face_sprite*8) % 128, flr((face_sprite*8)/128)*8)
-- facebox
draw_paper_with_color(x,y, 4*8+1, 4*8+1, c)
spr(face_sprite, x+1,y+1, 4,4)
-- textbox
draw_paper_with_color(x+4*8+4, y, 68, 4*8+1, c)
color(base_text_color)
print(wrap(words, 16), x+4*8+4+2, y+2)
end
function draw_chatbox(face_sprite, words, ...)
x,y=10,80
--background color
local c = sget((face_sprite*8) % 128, flr((face_sprite*8)/128)*8)
-- textbox
draw_paper_with_color(x, y, 68, 4*8+1, c)
color(light_text_color)
print(wrap(words, 16), x+2, y+2)
-- facebox
draw_paper_with_color(x+68+3, y, 4*8+1,4*8+1, 0)
spr(face_sprite, x+69+3,y+1, 4,4)
end
function conversation_draw(screen)
--prev_screen.draw()
message = messages[message_idx]
if message[1] == ph_p then
phoebe_say(unpack(message))
else
draw_chatbox(unpack(message))
end
end
function conversation_update(after)
return function()
conversation_active = true
if btnp(4) or btnp(5) then
callback = messages[message_idx][3]
if callback ~= nil then callback() end
if message_idx == #messages then
if after ~= nil then
after()
else
change_screen(prev_screen)
end
conversation_active = false
else
message_idx += 1
end
end
end
end
-- base holds the screen to display under the conversation. nil if you want to simply use the existing screen.
-- convo holds a list of {headsprite, message} pairs to display as a conversation
-- after holds a callback for what to do after the screen is displayed. usually you'll call change_screen().
function screen_conversation(convo, after, base)
return {
before=function()
if base ~= nil then
prev_screen=base
end
messages=convo
message_idx=1
conversation_active = true
end,
update=conversation_update(after),
draw=conversation_draw
}
end