Advertisement
LuaWeaver

main.lua

Nov 27th, 2011
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.77 KB | None | 0 0
  1. function love.load()
  2.     juanPonce1={"Question", "Answer1", "Answer2", "Answer3", "Answer2"} --Table with certain question about Juan Ponce de Leon. 3rd level.
  3.     juanPonce={juanPonce1} --Table with all questions about Juan Ponce de Leon. 2ed level.
  4.     questionsAndAnswers={juanPonce} --Ttable with all the question. 1st  level.
  5.     height=love.graphics.getHeight() --Finds the height and width for later.
  6.     width=love.graphics.getWidth()
  7.     ButtonPressed=false --Whether the button is pressed or not
  8.     ButtonDown=love.graphics.newImage("Button2.png") --Creates our images.
  9.     ButtonUp=love.graphics.newImage("Button1.png")
  10.     ButtonColored=love.graphics.newImage("Button3.png")
  11.     love.graphics.setIcon(love.graphics.newImage("Button1Logo.png")) --Makes our logo.
  12.     answer="" --Current answer.
  13.     seconds=0 --Time stuffz.
  14.     secondsRequired=false
  15.     mouseX=0 --Mouse stuffz.
  16.     mouseY=0
  17.     buttonWidth=ButtonUp:getWidth()*(1/4) --Width and height of scaled buttons.
  18.     buttonHeight=ButtonUp:getHeight()*(1/4)
  19.     Button1Text="" --Stuff for answers next to buttons.
  20.     Button2Text=""
  21.     Button3Text=""
  22.     question=""
  23. end
  24.  
  25. function love.update(dt)
  26.     if secondsRequired then
  27.         seconds=seconds+dt
  28.     end
  29.     mouseX=love.mouse.getX() --Update the mouse.
  30.     mouseY=love.mouse.getY()
  31.     if (mouseX>=formula(1/8, 0.25)) and (mouseX<=formula(1/8, 0.25)+buttonWidth) and (mouseY>=formula(1/4, 0.25)) and (mouseY<=formula(1/4, 0.25)+buttonHeight) then --if is in the box of this image then
  32.         if love.mouse.isDown("l") then --If this image ios clicked on then
  33.             currentButton1=ButtonDown
  34.         else
  35.             currentButton1=ButtonColored --If this image is hovered over then
  36.         end
  37.     else
  38.         currentButton1=ButtonUp --If this image is not hovered over then
  39.     end
  40.     if (mouseX>=formula(1/8, 0.25)) and (mouseX<=formula(1/8, 0.25)+buttonWidth) and (mouseY>=formula(2/4, 0.25)) and (mouseY<=formula(2/4, 0.25)+buttonHeight) then --if is in the box of this image then
  41.         if love.mouse.isDown("l") then --If this image ios clicked on then
  42.             currentButton2=ButtonDown
  43.         else
  44.             currentButton2=ButtonColored --If this image is hovered over then
  45.         end
  46.     else
  47.         currentButton2=ButtonUp --If this image is not hovered over then
  48.     end
  49.     if (mouseX>=formula(1/8, 0.25)) and (mouseX<=formula(1/8, 0.25)+buttonWidth) and (mouseY>=formula(3/4, 0.25)) and (mouseY<=formula(3/4, 0.25)+buttonHeight) then --if is in the box of this image then
  50.         if love.mouse.isDown("l") then --If this image ios clicked on then
  51.             currentButton3=ButtonDown
  52.         else
  53.             currentButton3=ButtonColored --If this image is hovered over then
  54.         end
  55.     else
  56.         currentButton3=ButtonUp --If this image is not hovered over then
  57.     end
  58.     for i, level2 in pairs(questionsAndAnswers) do
  59.         for i2, level3 in pairs(level2) do
  60.             if i2==1 then
  61.                 question=level3[i2]
  62.             elseif i2==2 then
  63.                 Button1Text=level3[i2]
  64.             elseif i2==3 then
  65.                 Button2Text=level3[i2]
  66.             elseif i2==4 then
  67.                 Button3Text=level3[i2]
  68.             else
  69.                 answer=level3[i2]
  70.             end
  71.         end
  72.     end
  73. end
  74.  
  75. function love.draw()
  76.     love.graphics.draw(currentButton1, formula(1/8, 0.25), formula(1/4, 0.25), 0, 0.25) --The position is a formula to make the center of the image go to the desired spot, instead of the top left corner.
  77.     love.graphics.print(Button1Text, formula(1/8, 0.25)+75, formula(1/4, 0.25)+12.5)
  78.     love.graphics.draw(currentButton2, formula(1/8, 0.25), formula(2/4, 0.25), 0, 0.25)
  79.     love.graphics.print(Button2Text, formula(1/8, 0.25)+75, formula(1/4, 0.25)-12.5)
  80.     love.graphics.draw(currentButton3, formula(1/8, 0.25), formula(3/4, 0.25), 0, 0.25)
  81.     love.graphics.print(Button3Text, formula(1/8, 0.25)+75, formula(1/4, 0.25)-12.5)
  82.     love.graphics.print(question, width/2-#question, height/8, 0, 2)
  83.     print(answer)
  84. end
  85.  
  86. function formula(position, scale)
  87.     return (height*position)-((buttonHeight*scale)/2) --Formula. I'm proud of myself :D
  88. end
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement