Page 5 of 5

Re: Inventory help in an RPG game

Posted: Wed Oct 25, 2017 12:08 pm
by GameDummy
Azhukar wrote: Mon Oct 23, 2017 2:01 pm
GameDummy wrote: Sun Oct 22, 2017 8:20 amThank you for that, but can you guys tell me a way to draw this on the actual game screen ?

Code: Select all

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.

Re: Inventory help in an RPG game

Posted: Wed Oct 25, 2017 12:57 pm
by Azhukar
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.

Re: Inventory help in an RPG game

Posted: Wed Oct 25, 2017 10:25 pm
by zorg
Also congrats to GameDummy for bumping a 4 year old thread! :megagrin:

Re: Inventory help in an RPG game

Posted: Thu Oct 26, 2017 11:19 am
by Azhukar
zorg wrote: Wed Oct 25, 2017 10:25 pmAlso congrats to GameDummy for bumping a 4 year old thread! :megagrin:
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.

Re: Inventory help in an RPG game

Posted: Thu Oct 26, 2017 2:10 pm
by Stifu
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).

Re: Inventory help in an RPG game

Posted: Thu Oct 26, 2017 8:47 pm
by zorg
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

Re: Inventory help in an RPG game

Posted: Fri Oct 27, 2017 9:03 pm
by GameDummy
zorg wrote: Wed Oct 25, 2017 10:25 pm Also congrats to GameDummy for bumping a 4 year old thread! :megagrin:
Oh i didn't notice it was that old i just registered an account because i was interested in it :crazy: