Love2D Currency Converter Mini Project

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
Shadowraix
Prole
Posts: 4
Joined: Tue Jul 30, 2013 3:59 pm

Love2D Currency Converter Mini Project

Post by Shadowraix »

So I haven't posted in these forums in a long time. I wanted to enter a programming competition for my school and my computer teacher gave me project details of last years' competition. One was a currency converter from a set list of currencies. I thought doing this in Visual Studio would be too easy. So I decided to do it in Love. Since there is the challenge of handling the visual rendering and handling things like button inputs and such. I was going for more of functionality and just tried to get something working so it doesn't look very appealing. Also the actual exchange rates are inaccurate since I was only going by the conversion rates on the paper. The code will probably be a mess too.

Anyways, I figured I would release it and see what you guys think. I made it in about 6 hours starting from no Love knowledge and slowly working my way up learning the framework again...Im running on one hour of sleep because of this thing. program is in the attachments.

Instructions are basically click the two currencies you want to convert, type the value for the base currency and click calculate and it will give you the converted currency. Clear will reset everything.
Attachments
ProgramConversion.love
(2.98 KiB) Downloaded 92 times
User avatar
ivan
Party member
Posts: 1915
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Love2D Currency Converter Mini Project

Post by ivan »

Hey Shadowraix.
Not bad for an educational project.
One thing I would say is that UI can be pretty complicated but you've managed it OK with this example.
I would suggest a loop for things like:

Code: Select all

	Button.Pound = {PosX = 5,PosY = 5,SizeX = 80,SizeY = 50,Text = "Pound",CallBack = function()
		if ConvertFrom == "None" then
			ConvertFrom = "Pound"
		elseif ConvertTo == "None" then
			ConvertTo = "Pound"
		end
	end}
	
	Button.Francs = {PosX = 95,PosY = 5,SizeX = 80,SizeY = 50,Text = "Francs",CallBack = function()
		if ConvertFrom == "None" then
			ConvertFrom = "Francs"
		elseif ConvertTo == "None" then
			ConvertTo = "Francs"
		end
	end}
	
	Button.Lire = {PosX = 185,PosY = 5,SizeX = 80,SizeY = 50,Text = "Lire",CallBack = function()
		if ConvertFrom == "None" then
			ConvertFrom = "Lire"
		elseif ConvertTo == "None" then
			ConvertTo = "Lire"
		end
	end}
	
	Button.Mark = {PosX = 275,PosY = 5,SizeX = 80,SizeY = 50,Text = "Mark",CallBack = function()
		if ConvertFrom == "None" then
			ConvertFrom = "Mark"
		elseif ConvertTo == "None" then
			ConvertTo = "Mark"
		end
	end}
	
	Button.Pesetas = {PosX = 365,PosY = 5,SizeX = 80,SizeY = 50,Text = "Pesetas",CallBack = function()
		if ConvertFrom == "None" then
			ConvertFrom = "Pesetas"
		elseif ConvertTo == "None" then
			ConvertTo = "Pesetas"
		end
	end}
	
	Button.Dollar = {PosX = 455,PosY = 5,SizeX = 80,SizeY = 50,Text = "Dollar",CallBack = function()
		if ConvertFrom == "None" then
			ConvertFrom = "Dollar"
		elseif ConvertTo == "None" then
			ConvertTo = "Dollar"
		end
	end}
and:

Code: Select all

	--Pounds Button--
	love.graphics.setColor(83,185,210)
	love.graphics.rectangle("fill",Button.Pound.PosX,Button.Pound.PosY,Button.Pound.SizeX,Button.Pound.SizeY)
	love.graphics.setColor(255,255,255)
	love.graphics.print(Button.Pound.Text,(Button.Pound.PosX + Button.Pound.SizeX/2)-font:getWidth(Button.Pound.Text)/2,(Button.Pound.PosY + Button.Pound.SizeY/2)-font:getHeight(Button.Pound.Text)/2)
	
	--Francs Button
	love.graphics.setColor(83,185,210)
	love.graphics.rectangle("fill",Button.Francs.PosX,Button.Francs.PosY,Button.Francs.SizeX,Button.Francs.SizeY)
	love.graphics.setColor(255,255,255)
	love.graphics.print(Button.Francs.Text,(Button.Francs.PosX + Button.Francs.SizeX/2)-font:getWidth(Button.Francs.Text)/2,(Button.Francs.PosY + Button.Francs.SizeY/2)-font:getHeight(Button.Francs.Text)/2)
	
	--Lire Button--
	love.graphics.setColor(83,185,210)
	love.graphics.rectangle("fill",Button.Lire.PosX,Button.Lire.PosY,Button.Lire.SizeX,Button.Lire.SizeY)
	love.graphics.setColor(255,255,255)
	love.graphics.print(Button.Lire.Text,(Button.Lire.PosX + Button.Lire.SizeX/2)-font:getWidth(Button.Lire.Text)/2,(Button.Lire.PosY + Button.Lire.SizeY/2)-font:getHeight(Button.Lire.Text)/2)
	
	--Mark Button--
	love.graphics.setColor(83,185,210)
	love.graphics.rectangle("fill",Button.Mark.PosX,Button.Mark.PosY,Button.Mark.SizeX,Button.Mark.SizeY)
	love.graphics.setColor(255,255,255)
	love.graphics.print(Button.Mark.Text,(Button.Mark.PosX + Button.Mark.SizeX/2)-font:getWidth(Button.Mark.Text)/2,(Button.Mark.PosY + Button.Mark.SizeY/2)-font:getHeight(Button.Mark.Text)/2)
	
	--Pesetas Button--
	love.graphics.setColor(83,185,210)
	love.graphics.rectangle("fill",Button.Pesetas.PosX,Button.Pesetas.PosY,Button.Pesetas.SizeX,Button.Pesetas.SizeY)
	love.graphics.setColor(255,255,255)
	love.graphics.print(Button.Pesetas.Text,(Button.Pesetas.PosX + Button.Pesetas.SizeX/2)-font:getWidth(Button.Pesetas.Text)/2,(Button.Pesetas.PosY + Button.Pesetas.SizeY/2)-font:getHeight(Button.Pesetas.Text)/2)
	
	--Dollar Button--
	love.graphics.setColor(83,185,210)
	love.graphics.rectangle("fill",Button.Dollar.PosX,Button.Dollar.PosY,Button.Dollar.SizeX,Button.Dollar.SizeY)
	love.graphics.setColor(255,255,255)
	love.graphics.print(Button.Dollar.Text,(Button.Dollar.PosX + Button.Dollar.SizeX/2)-font:getWidth(Button.Dollar.Text)/2,(Button.Dollar.PosY + Button.Dollar.SizeY/2)-font:getHeight(Button.Dollar.Text)/2)
	
Other than that, good job. :)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 3 guests