Inventory

When the player holds down the X key we'll show how many keys the player has in their inventory.

Create a new tab for inventory code. It should be tab 3. Add a function called show_inventory to it.

 
-- inventory code
function show_inventory()
invx=mapx*8+40
invy=mapy*8+8
rectfill(invx,invy,invx+48,invy+24,0)
print("inventory",invx+7,invy+4,7)
print("keys "..p.keys,invx+12,invy+14,9)
end
 

Then call this function from the _draw function in the game loop tab (tab 0). . You can use shift-x to get the X glyph.

 
function _draw()
cls()
draw_map()
draw_player()
if (btn(X)) show_inventory()
end
 

End Result

Save your changes with ctrl+S. Run them with ctrl+R. You should now be able to pick up a key and then press X to see how many keys the player has in their inventory. Next, lets add a way for the player to use the keys they collect.

Download