Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------------------------
- -- lookup.lua
- --[[screenshot here:
- http://snag.gy/GxyLY.jpg
- --]]
- ------------------------------------
- _M = {}
- _M.taken = {}
- _M.myBase = {
- --------------------------
- [1] = { question = "What is my name ?",
- alt1 = "Hendrix",
- alt2 = "Carlos",
- alt3 = "Jesus",
- alt4 = "BerhanK",
- answer = "Hendrix"
- },
- [2] = { question = "Who is the king ?",
- alt1 = "Hendrix",
- alt2 = "Baktus",
- alt3 = "BerhanK",
- alt4 = "Carlos",
- answer = alt1
- },
- }
- return _M
- -------------------------------------
- --main.lua
- -------------------------------------
- display.setStatusBar(display.HiddenStatusBar)
- local lookup = require "lookup"
- --VARIABLE DECLARATIONS------------
- local _W = display.contentWidth * 0.5
- local _H = display.contentHeight * 0.5
- --[Graphics]
- local bg
- --[Score TextField]
- local score = display.newText("0", 2, 0, "SuperMarioGalaxy", 14)
- score:setTextColor(255, 206, 0)
- --[Title screen]
- local titleBg
- titleBg = display.newImageRect ( "bg.jpg", 320, 480 )
- titleBg:setReferencePoint(display.CenterReferencePoint)
- titleBg.x = _W
- titleBg.y = _H
- local R, answerBeholder, logo, quizzLogo, playButton, credButton, titleView
- --[Credit View]
- local credView, lastY, score
- --[Game View]
- local gameView, question, aText, bText, cText, dText
- --[Sounds]
- --local bell = audio.loadSound ( "bell.mp3" )
- --local buzz = audio.loadSound ( "buzz.mp3" )
- --DECLARE FUNCTIONS------------------
- local Main = {}
- local startButtonListeners = {}
- local showCredits = {}
- local hideCredits = {}
- local showGameView = {}
- local gameListeners = {}
- local update = {}
- local gameFunction = {}
- -- CONSTRUCTOR OF MAIN FUNCTION ------
- function Main()
- logo = display.newImageRect ( "logo.png", 326, 128 )
- logo:setReferencePoint(display.TopCenterReferencePoint)
- logo.x = _W
- logo.y = 0
- quizzLogo = display.newImageRect ( "quizzLogo.png", 320, 140, true )
- quizzLogo:setReferencePoint(display.TopCenterReferencePoint)
- quizzLogo.x = _W
- quizzLogo.y = logo.height
- playButton = display.newImageRect ( "playButton.png", 204, 60, true )
- playButton:setReferencePoint(display.TopCenterReferencePoint)
- playButton.x = _W
- playButton.y = display.contentHeight - ( playButton.height*2) -60
- credButton = display.newImageRect ( "scoreButton.png", 204, 60, true )
- credButton:setReferencePoint(display.TopCenterReferencePoint)
- credButton.x = _W
- credButton.y = display.contentHeight - credButton.height - 50
- titleView = display.newGroup (logo, quizzLogo, playButton, credButton)
- titleView.x = _W
- titleView.y = 70
- startButtonListeners( "add" )
- end
- --CLASSES (OTHER FUNCS)--------------
- function startButtonListeners(action)
- if action == "add" then
- playButton:addEventListener( "tap", showGameView )
- credButton:addEventListener( "tap", showCredits )
- elseif action == "rmv" then
- playButton:removeEventListener( "tap", showGameView )
- credButton:removeEventListener( "tap", showCredits )
- end
- end
- function gameListeners(action)
- if action == "add" then
- aButton:addEventListener( "touch", gameFunction )
- bButton:addEventListener( "touch", gameFunction )
- cButton:addEventListener( "touch", gameFunction )
- dButton:addEventListener( "touch", gameFunction )
- Runtime:addEventListener( "enterFrame", update )
- else
- aButton:removeEventListener( "touch", gameFunction )
- bButton:removeEventListener( "touch", gameFunction )
- cButton:removeEventListener( "touch", gameFunction )
- dButton:removeEventListener( "touch", gameFunction )
- Runtime:removeEventListener( "enterFrame", update )
- end
- end
- function showCredits:tap(e)
- playButton.isVisible = false
- credButton.isVisible = false
- credView = display.newImageRect ( "bg.jpg", 320, 480, true )
- credView:setReferencePoint(display.CenterReferencePoint)
- credView.x = _W
- credView.y = _H
- lastY = titleBg.y
- transition.to ( titleBg, { time = 300, onComplete = function()
- credButton.isVisible = true playButton.isVisible = true
- credView:removeEventListener("tap", hideCredits)
- display.remove( credView ) credView = nil
- end} )
- transition.to ( creditsView, {time = 300, onComplete = function()
- creditsView:addEventListener("tap", hideCredits)
- end} )
- end
- function hideCredits(e)
- transition.to(credView, {time = 300, onComplete = function()
- credButton.isVisible = true playButton.isVisible = true
- credView:removeEventListener("tap", hideCredits)
- display.remove(credView) credView = nil
- end})
- transition.to(titleBg, {time = 300, y = lastY});
- end
- function gameFunction(event)
- if event.phase == "began" then
- if event.target.answer == answerBeholder then
- print(answerBeholder)
- else
- print("wrong answer")
- end
- end
- end
- function showGameView:tap(e)
- R = math.random(1, #lookup.myBase)
- answerBeholder = lookup.myBase[R].answer
- question = display.newText( lookup.myBase[R].question, 0, 0, "SuperMarioGalaxy", 24 )
- question:setTextColor ( 254, 254, 254 )
- question.x = _W
- question.y = 10
- aButton = display.newImageRect ( "buttonImage.png", 320, 95, true )
- aButton.x = _W
- aButton.y = 200
- aText = display.newText( lookup.myBase[R].alt1, 0, 0, "SuperMarioGalaxy", 24 )
- aText:setTextColor ( 254, 254, 254 )
- aText.x = aButton.x
- aText.y = aButton.y
- bButton = display.newImageRect ( "buttonImage.png", 320, 95, true )
- bButton.x = _W
- bButton.y = aButton.y + 80
- bText = display.newText( lookup.myBase[R].alt2, 0, 0, "SuperMarioGalaxy", 24 )
- bText:setTextColor ( 254, 254, 254 )
- bText.x = aButton.x
- bText.y = bButton.y
- cButton = display.newImageRect ( "buttonImage.png", 320, 95, true )
- cButton.x = _W
- cButton.y = bButton.y + 80
- cText = display.newText( lookup.myBase[R].alt3, 0, 0, "SuperMarioGalaxy", 24 )
- cText:setTextColor ( 254, 254, 254 )
- cText.x = aButton.x
- cText.y = cButton.y
- dButton = display.newImageRect ( "buttonImage.png", 320, 95, true )
- dButton.x = _W
- dButton.y = cButton.y + 80
- dText = display.newText( lookup.myBase[R].alt4, 0, 0, "SuperMarioGalaxy", 24 )
- dText:setTextColor ( 254, 254, 254 )
- dText.x = aButton.x
- dText.y = dButton.y
- gameView = display.newGroup ( aButton, bButton, cButton, dButton, aText, bText, cText, dText, question )
- transition.to(gameView, {time = 300,
- onComplete = function() gameListeners("add")
- display.remove(titleView) titleView = nil
- end})
- end
- --CALL THE MAIN FUNCTION--------------
- Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement