local myInventory = {food = 10,sword = 4,coin = 50,axe = 2,shield = 1,armor = 40}
local function drawItem(item,itemWidth,itemHeight)
if (item == "food") then
love.graphics.setColor(0,128,0,255)
elseif (item == "coin") then
love.graphics.setColor(0,128,128,255)
else
love.graphics.setColor(128,0,0,255)
end
love.graphics.rectangle("fill",0,0,itemWidth,itemHeight)
end
local function drawInventory(inventory,itemWidth,itemHeight,itemSpacing,horizontalSlots)
local slot_x,slot_y = 0,0
for item,amount in pairs(myInventory) do
local x,y = slot_x*(itemWidth+itemSpacing),slot_y*(itemHeight+itemSpacing)
love.graphics.push()
love.graphics.translate(x,y)
drawItem(item,itemWidth,itemHeight)
love.graphics.pop()
love.graphics.setColor(255,255,255,255)
love.graphics.print(item.."\n"..amount.."x",x,y)
slot_x = slot_x + 1
if (slot_x >= horizontalSlots) then
slot_x = 0
slot_y = slot_y + 1
end
end
end
function love.draw()
drawInventory(myInventory,50,50,4,3)
end
Thanks for your great help.
İ will try to add images for the inventory myself, but if you come up with a way to do that and share it i would appreciate that as well.
GameDummy wrote: ↑Wed Oct 25, 2017 12:08 pmİ will try to add images for the inventory myself, but if you come up with a way to do that and share it i would appreciate that as well.
The same way the items are differently colored you can specify different images. The code already includes the conditional construct for that behavior in the drawItem function.
Also congrats to GameDummy for bumping a 4 year old thread!
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
zorg wrote: ↑Wed Oct 25, 2017 10:25 pmAlso congrats to GameDummy for bumping a 4 year old thread!
I will never understand forum culture obsession with thread age. The entire point of the forum structure is to provide easy access to all topics ever made on it, but somehow someone came to the conclusion that the idea that 'bumping' or 'necroing' are undesirable, when they in fact complement the functionality of the place.
I'd rather continue discussion in an already established thread where all related information is already given than create a completely new one to satisfy some ritualistic behavior.
Azhukar wrote: ↑Thu Oct 26, 2017 11:19 amI will never understand forum culture obsession with thread age.
My 2 cents. It's a bit hard to follow a thread with a lot of pages, and it takes a while to catch up (the off topic chatting doesn't help, as you have to skim through all of the posts to find useful information). Also, 4 years is kinda long when it comes to technology, meaning past answers might now be outdated (may not be the case here, however). Besides, the topic has been drifting from general logic to drawing on screen, hasn't it? Sounds to me like it'd be simpler to just start a new thread (which doesn't prevent you from referencing this one if you think it's relevant).
My take on this is that solutions in an ancient thread, especially on these forums, may not be relevant at all now, with the new versions of the engine coming out relatively fast. (This thread happened when 0.8 was out, now we're up to 0.10) It's not the fact that newbies finding these threads is bad, but thy may be expecting things in it to work inherently/out of the box. Of course, all that depends on what the discussion was about. What Stifu said, basically.
Also, this is a rite of passage nowadays anyway, since everyone does it. :p
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.