I've "studied" python and c++ for a while some months ago.
I decided to resume studying, this time starting with this incredible framework (the first I ever used) and lua.
After my first 5 days in this new world i decided to share my first project ever, in order to get criticisms and help.
---------------------------------------------------------------------------------------------------------------------------------------
I've decided to start making a simple program that generates random (or pseudorandom) number/words.
I'm working on make many filters and options to make this simple program as completely as possible.
Currently the user can only choose between the number of consonants, vowels and numbers to generate.
Some features, like choose the order or the generated characters are only avaibles by editing the code (in a future update the user will insert all this kind of things).
Space = To generate
LeftMouse = To interact
---------------------------------------------------------------------------------------------------------------------------------------
I know it's not the most exciting project ever created, but for me it's a goal.
I didn't want to create a classic game for the first project.
Thank you for the kindness, it would be great if someone more experienced than me (not hard to find) wants to help me (advices on how to improve my code etc.)
Code: Select all
function love.load()
love.graphics.setBackgroundColor(50,50,50)
--Window x/y
Window_Height = love.graphics.getHeight()
Window_Width = love.graphics.getWidth()
--Fonts
Font_Pcsenior_16 = love.graphics.newFont( "pcsenior.ttf", 16 )
Font_Pcsenior_13 = love.graphics.newFont( "pcsenior.ttf", 13 )
--Accepted texts
----------------
Array_Accepted_Text_Consonants_Button = {"1","2","3","4","5","6","7","8","9"}
NumberOfConsonants = 0
----------------
Array_Accepted_Text_Vowels_Button = {"1","2","3","4","5","6","7","8","9"}
NumberOfVowels = 0
----------------
Array_Accepted_Text_Numbers_Button = {"1","2","3","4","5","6","7","8","9"}
NumberOfNumbers = 0
----------------
--Text
Text_1 = ""
Text_2 = ""
Text_3 = ""
Word = ""
Maximum_Text_Lenght = 2
--Text boxes
Value_Standard_Added = 10
Distance = 40
Text_Color = 150
Text_Color_Pressed = 100
Text_Box_1_Visibility = true
Text_Box_2_Visibility = true
Text_Box_3_Visibility = true
----------------(1)
Pression_Text_Box_1 = 1
Pression_Text_Box_2 = 1
Pression_Text_Box_3 = 1
--Others
Error = false
Word = "Random!"
--Arrays
Array_Consonants={"B", "C", "D", "F", "G", "H", "L", "M", "N", "P", "Q", "R", "S", "T", "V", "Z"}
Array_Vowels={"A", "E", "I", "O", "U"}
Array_Numbers={"0","1","2","3","4","5","6","7","8","9"}
--Accepted text
Accepted_Text = {0,1,2,3,4,5,6,7,8,9}
Numbers1 = 10
end
function love.mousepressed(x, y, button, istouch)
if button == 1 and x>Text_Box_1_X and x<Text_Box_1_X+Width_Text_Text_Box_1+Value_Standard_Added and y>Text_Box_1_Y and y<Text_Box_1_Y+Height_Text_Text_Box_1+Value_Standard_Added and Text_Box_1_Visibility == true then
Pression_Text_Box_1 = (Pression_Text_Box_1 + 1)
if Pression_Text_Box_1%2==0 then
Text_Box_2_Visibility = false
Text_Box_3_Visibility = false
Open = true
elseif Pression_Text_Box_1%2==1 then
Text_Box_2_Visibility = true
Text_Box_3_Visibility = true
Open = false
end
end
if button == 1 and x>Text_Box_2_X and x<Text_Box_2_X+Width_Text_Text_Box_2+Value_Standard_Added and y>Text_Box_2_Y and y<Text_Box_2_Y+Height_Text_Text_Box_2+Value_Standard_Added and Text_Box_2_Visibility == true then
Pression_Text_Box_2 = (Pression_Text_Box_2 + 1)
if Pression_Text_Box_2%2==0 then
Text_Box_1_Visibility = false
Text_Box_3_Visibility = false
Open = true
elseif Pression_Text_Box_2%2==1 then
Text_Box_1_Visibility = true
Text_Box_3_Visibility = true
Open = false
end
end
if button == 1 and x>Text_Box_3_X and x<Text_Box_3_X+Width_Text_Text_Box_3+Value_Standard_Added and y>Text_Box_3_Y and y<Text_Box_3_Y+Height_Text_Text_Box_3+Value_Standard_Added and Text_Box_3_Visibility == true then
Pression_Text_Box_3 = (Pression_Text_Box_3 + 1)
if Pression_Text_Box_3%2==0 then
Text_Box_1_Visibility = false
Text_Box_2_Visibility = false
Open = true
elseif Pression_Text_Box_3%2==1 then
Text_Box_1_Visibility = true
Text_Box_2_Visibility = true
Open = false
end
end
end
function love.textinput(UserText)
if Pression_Text_Box_1%2==0 then
Verify = tonumber(UserText)
Numbers2 = Numbers1
Control = false
while Control == false do
Numbers2 = (Numbers2-1)
if Verify == Accepted_Text[Numbers2] then
Control = true
Error = false
end
if Numbers2 == 0 then
Control = true
Error = true
end
end
if Error == false then
NumberOfConsonants = NumberOfConsonants..Verify
if string.len(NumberOfConsonants)>Maximum_Text_Lenght then
NumberOfConsonants=0
end
end
end
if Pression_Text_Box_2%2==0 then
Verify = tonumber(UserText)
Numbers2 = Numbers1
Control = false
while Control == false do
Numbers2 = (Numbers2-1)
if Verify == Accepted_Text[Numbers2] then
Control = true
Error = false
end
if Numbers2 == 0 then
Control = true
Error = true
end
end
if Error == false then
NumberOfVowels = NumberOfVowels..Verify
if string.len(NumberOfVowels)>Maximum_Text_Lenght then
NumberOfVowels=0
end
end
end
if Pression_Text_Box_3%2==0 then
Verify = tonumber(UserText)
Numbers2 = Numbers1
Control = false
while Control == false do
Numbers2 = (Numbers2-1)
if Verify == Accepted_Text[Numbers2] then
Control = true
Error = false
end
if Numbers2 == 0 then
Control = true
Error = true
end
end
if Error == false then
NumberOfNumbers = NumberOfNumbers..Verify
if string.len(NumberOfNumbers)>Maximum_Text_Lenght then
NumberOfNumbers=0
end
end
end
end
function love.update(dt)
PressPlay = love.keyboard.isDown("space")
end
function love.draw()
function WordGenerator(NumberOfConsonants, NumberOfVowels, NumberOfNumbers)
Word = ""
Consonants = ""
Vowels = ""
Numbers = ""
for NumberOfConsonants = NumberOfConsonants, 1, -1
do
RandomNumber = love.math.random(1, 16)
Consonants = Consonants.. Array_Consonants[RandomNumber]
end
for NumberOfVowels = NumberOfVowels, 1, -1
do
RandomNumber = love.math.random(1, 5)
Vowels = Vowels .. Array_Vowels[RandomNumber]
end
for NumberOfNumbers = NumberOfNumbers, 1, -1
do
RandomNumber = love.math.random(1, 10)
Numbers = Numbers .. Array_Numbers[RandomNumber]
end
Order_1 = Numbers
Order_2 = Vowels
Order_3 = Consonants
Word = Order_1..Order_2..Order_3
return Word, Order_1
end
if PressPlay == true then
WordGenerator(NumberOfConsonants, NumberOfVowels, NumberOfNumbers)
end
--Random text box
Width_Random_Text_Box = Font_Pcsenior_13:getWidth(Word)
Height_Random_Text_Box = Font_Pcsenior_13:getHeight(Word)
Text_Random_Text_Box = love.graphics.newText(Font_Pcsenior_16, Word)
love.graphics.draw(Text_Random_Text_Box,(Window_Width/2)-(Width_Random_Text_Box/2) ,100)
--Text boxes
----------------(1)
if Text_Box_1_Visibility == true then
Text_Text_Box_1 = "Number of consonants to generate: " .. NumberOfConsonants
Width_Text_Text_Box_1 = Font_Pcsenior_13:getWidth(Text_Text_Box_1)
Height_Text_Text_Box_1 = Font_Pcsenior_13:getHeight(Text_Text_Box_1)
Text_Box_1_Width = (Width_Text_Text_Box_1 + Value_Standard_Added)
Text_Box_1_Height = (Height_Text_Text_Box_1 + Value_Standard_Added)
Text_Box_1_X = (Window_Width/2) - (Text_Box_1_Width/2)
Text_Box_1_Y = (Window_Height/2) - (Text_Box_1_Height/2)
if Pression_Text_Box_1%2==0 then
love.graphics.setColor(Text_Color_Pressed,Text_Color_Pressed,Text_Color_Pressed)
love.graphics.rectangle("fill", Text_Box_1_X, Text_Box_1_Y,Text_Box_1_Width , Text_Box_1_Height)
love.graphics.setColor(225,225,225)
elseif Pression_Text_Box_1%2==1 then
love.graphics.setColor(Text_Color,Text_Color,Text_Color)
love.graphics.rectangle("fill", Text_Box_1_X, Text_Box_1_Y,Text_Box_1_Width , Text_Box_1_Height)
love.graphics.setColor(225,225,225)
end
Text_Sentence_Text_Box_1 = love.graphics.newText( Font_Pcsenior_13, Text_Text_Box_1 )
love.graphics.draw(Text_Sentence_Text_Box_1, Text_Box_1_X+(Value_Standard_Added/2), Text_Box_1_Y+(Value_Standard_Added/2))
end
----------------(2)
if Text_Box_2_Visibility == true then
Text_Text_Box_2 = "Number of vowels to generate: " .. NumberOfVowels
Width_Text_Text_Box_2 = Font_Pcsenior_13:getWidth(Text_Text_Box_2)
Height_Text_Text_Box_2 = Font_Pcsenior_13:getHeight(Text_Text_Box_2)
Text_Box_2_Width = (Width_Text_Text_Box_2 + Value_Standard_Added)
Text_Box_2_Height = (Height_Text_Text_Box_2 + Value_Standard_Added)
Text_Box_2_X = (Window_Width/2) - (Text_Box_2_Width/2)
Text_Box_2_Y = (Window_Height/2) - (Text_Box_2_Height/2) + (Distance)
if Pression_Text_Box_2%2==0 then
love.graphics.setColor(Text_Color_Pressed,Text_Color_Pressed,Text_Color_Pressed)
love.graphics.rectangle("fill", Text_Box_2_X, Text_Box_2_Y,Text_Box_2_Width , Text_Box_2_Height)
love.graphics.setColor(225,225,225)
elseif Pression_Text_Box_2%2==1 then
love.graphics.setColor(Text_Color,Text_Color,Text_Color)
love.graphics.rectangle("fill", Text_Box_2_X, Text_Box_2_Y,Text_Box_2_Width , Text_Box_2_Height)
love.graphics.setColor(225,225,225)
end
Text_Sentence_Text_Box_2 = love.graphics.newText( Font_Pcsenior_13, Text_Text_Box_2 )
love.graphics.draw(Text_Sentence_Text_Box_2, Text_Box_2_X+(Value_Standard_Added/2), Text_Box_2_Y+(Value_Standard_Added/2))
end
----------------(3)
if Text_Box_3_Visibility == true then
Text_Text_Box_3 = "Number of numbers to generate: " .. NumberOfNumbers
Width_Text_Text_Box_3 = Font_Pcsenior_13:getWidth(Text_Text_Box_3)
Height_Text_Text_Box_3 = Font_Pcsenior_13:getHeight(Text_Text_Box_3)
Text_Box_3_Width = (Width_Text_Text_Box_3 + Value_Standard_Added)
Text_Box_3_Height = (Height_Text_Text_Box_3 + Value_Standard_Added)
Text_Box_3_X = (Window_Width/2) - (Text_Box_3_Width/2)
Text_Box_3_Y = (Window_Height/2) - (Text_Box_3_Height/2) + (Distance * 2)
if Pression_Text_Box_3%2==0 then
love.graphics.setColor(Text_Color_Pressed,Text_Color_Pressed,Text_Color_Pressed)
love.graphics.rectangle("fill", Text_Box_3_X, Text_Box_3_Y,Text_Box_3_Width , Text_Box_3_Height)
love.graphics.setColor(225,225,225)
elseif Pression_Text_Box_3%2==1 then
love.graphics.setColor(Text_Color,Text_Color,Text_Color)
love.graphics.rectangle("fill", Text_Box_3_X, Text_Box_3_Y,Text_Box_3_Width , Text_Box_3_Height)
love.graphics.setColor(225,225,225)
end
Text_Sentence_Text_Box_3 = love.graphics.newText( Font_Pcsenior_13, Text_Text_Box_3 )
love.graphics.draw(Text_Sentence_Text_Box_3, Text_Box_3_X+(Value_Standard_Added/2), Text_Box_3_Y+(Value_Standard_Added/2))
end
end