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/screen_inventory.lua

119 lines
3.4 KiB

inventory_drawer_height=0
inventory_drawer_height_max=106
inventory_cursor = {
x=0, y=0,
}
function inventory_before()
inventory_cursor.x = 0
inventory_cursor.y = 0
end
function inventory_slide(x1, x2)
return {
timer = 0,
active=true,
before=function(s)
inventory_drawer_height = x1
end,
update=function(s)
inventory_drawer_height = x1 + (s.timer/0.2)*(x2-x1)
if s.timer > 0.2 then
inventory_drawer_height = x2
s.active=false
end
end,
draw=function(s)
draw_drawer()
draw_item_sheet()
end,
}
end
function inventory_update()
cx, cy = inventory_cursor.x, inventory_cursor.y
if btnp(0) then cx -= 1 end
if btnp(1) then cx += 1 end
if btnp(2) then cy -= 1 end
if btnp(3) then cy += 1 end
if cy >= 0 and cy < flr(#inventory/5) and cx >= 0 and cx < 5 then
inventory_cursor.x = cx
inventory_cursor.y = cy
elseif cy == flr(#inventory / 5) and cx >= 0 and cx < #inventory % 5 then
inventory_cursor.x = cx
inventory_cursor.y = cy
elseif btnp(3) then
animate(inventory_slide(inventory_drawer_height_max,0))
change_screen(screen_workbench)
end
if btnp(5) then
animate(inventory_slide(inventory_drawer_height_max,0))
change_screen(screen_workbench)
end
end
function inventory_draw()
bench_draw()
draw_drawer()
draw_item_sheet()
end
function draw_drawer()
rectfill(14, 0, 114, inventory_drawer_height, 4)
for y=0,(inventory_drawer_height_max / 8) do
yval = y*8 + inventory_drawer_height - inventory_drawer_height_max
line(10, yval, 110, yval, 5)
for x=1,(4 - (y%2)) do
xval = x*32 + (y%2)*16
line(xval, yval, xval, yval+8, 5)
end
spr(20, 10, yval)
spr(20, 110, yval)
end
rectfill(6, inventory_drawer_height, 120, inventory_drawer_height+7, 4)
line(6, inventory_drawer_height, 120, inventory_drawer_height, 9)
line(6, inventory_drawer_height+7, 120, inventory_drawer_height+7, 9)
spr(21, 2, inventory_drawer_height)
spr(21, 118, inventory_drawer_height, 1, 1, true, false)
spr(22, 60, inventory_drawer_height+8)
draw_drawer_contents()
end
function draw_drawer_contents()
for i, val in ipairs(inventory) do
x, y = 20+20*((i-1)%5), 10+20*flr((i-1)/5) + inventory_drawer_height - inventory_drawer_height_max
if inventory_cursor.x + 5*inventory_cursor.y == i-1 then
rect(x-2,y-2,x+9,y+9, 10)
end
sprite = val.sprite
if sprite == nil then sprite = 36 end
if val.sprite_recolor ~= nil then
pal(val.sprite_recolor)
end
spr(sprite, x, y)
pal()
end
end
function draw_item_sheet()
local item = inventory[1 + 5*inventory_cursor.y + inventory_cursor.x]
if item ~= nil then
draw_paper(35,94, 128-2*35,28)
draw_ingredient_listing(item, 35, 94)
end
end
screen_inventory_raw = {before=inventory_before, draw=inventory_draw, update=inventory_update}
9 months ago
screen_inventory = screen_conversation({
{ph_p, [[oh right, this is the drawer where i keep my stuff!]]},},
9 months ago
function()
screen_inventory = screen_inventory_raw
change_screen(screen_inventory)
end,
screen_inventory_raw)