I'm trying to make a Zelda style game, but i can't for the life of me figure out how to work the inventory.
What I'm trying to do is make a sort of Silent Hill thing where it shows the one you highlighted as being larger than the previous, and next item. I'm not doing anything complex, each item you can get corresponds to a sprite in the sprite sheet (probably 14 sprites in total, 33 to 47). I'm using a table called inv by the way, I don't know though.
Here's a gif and the code for the inventory. the gif is from earlier, right now I've just kind of left the code blank-ish for now.

--inventory-- function upd_inv() poke(0x5f30,1) if btn(➡️) and bhd==false then itmsel+=1 elseif btn(⬅️) and bhd==false then itmsel-=1 end --this just makes sure the buttons are pushed once if btn(➡️) or btn(⬅️) or btn(⬆️) or btn(⬇️) and bhd==false then bhd=true elseif bhd==true and not btn(➡️) or btn(⬅️) or btn(⬆️) or btn(⬇️) then bhd=false end if btn(6) and bh6==false then state="play" bh6=true elseif bh6==true and not btn(6) then bh6=false end end function drw_inv() --slots, middle shows item hovering over, right shows next item, left shows previous item sspr(8+slm*8,16,8,8,46+camx,46+camy,32,32) sspr(8+slr*8,16,8,8,82+camx,54+camy,16,16) sspr(8+sll*8,16,8,8,26+camx,54+camy,16,16) end |
Sorry for any bad grammar or spelling, and/or if this is confusing. It's 3:54am as I'm writing this and I'm also new here.



Are the items in your inventory objects with properties? If so, the very lazy way I'd probably do it is set a property on the object (item.selected) to either 1 (not selected) or 2 (selected) when left/right are pressed:
if btn(➡️) and bhd==false then inv[itmsel].selected=1 itmsel+=1 if(itemsel > #inv) itemsel=1 --wrap around if you advance past the last item inv[itmsel].selected=2 elseif btn(⬅️) and bhd==false then inv[itmsel].selected=1 itmsel-=1 if(itemsel==0) itemsel=#inv --wrap around if you advance past the first item inv[itmsel].selected=2 end |
Then in the drw_inv() function I'd use that to scale the correct one (right now it looks like you have those hard-coded as slm, sll, and slr for middle, left, right, but the code below assumes you are storing objects in the inv table and the sprite locations are stored in a variable named sl in each object).
function drw_inv() --slots, middle shows item hovering over, right shows next item, left shows previous item sspr(8+inv[1].sl*8,16,8,8,46+camx,46+camy,16*inv[1].selected,16*inv[1].selected) sspr(8+inv[2].sl*8,16,8,8,82+camx,54+camy,16*inv[2].selected,16*inv[2].selected) sspr(8+inv[3].sl*8,16,8,8,26+camx,54+camy,16*inv[3].selected,16*inv[3].selected) end |
So the one that is selected will have a value of 2 in selected and be scaled to 16*2, the rest will have values of 1 and will be scaled to 16*1.
Again, this is probably not the optimal way to do it, but that was the first thing that came to mind for me, so that's probably what would have ended up in my code, at least to start :).
[Please log in to post a comment]