Inventory help in an RPG game

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
GameDummy
Prole
Posts: 3
Joined: Sun Oct 22, 2017 8:16 am

Re: Inventory help in an RPG game

Post 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.
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: Inventory help in an RPG game

Post 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.
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Inventory help in an RPG game

Post by zorg »

Also congrats to GameDummy for bumping a 4 year old thread! :megagrin:
Me and my stuff :3True 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.
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: Inventory help in an RPG game

Post 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.
User avatar
Stifu
Party member
Posts: 106
Joined: Mon Mar 14, 2016 9:53 am
Contact:

Re: Inventory help in an RPG game

Post 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).
Zabuyaki, our upcoming beat 'em up: https://www.zabuyaki.com
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Inventory help in an RPG game

Post 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
Me and my stuff :3True 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.
GameDummy
Prole
Posts: 3
Joined: Sun Oct 22, 2017 8:16 am

Re: Inventory help in an RPG game

Post 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:
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Amazon [Bot] and 2 guests