Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- PLEASE TAKE A LOOK AT THIS IMAGE CLOSELY FIRST: HTTP://WWW.HIDEAWAYSPA.NO/HENDRIX/gcExpl01.jpg
- -- This is some of the code (_G.scoreUser = 580 under is just to check gc and will be commented out of course)
- -- gameCenter.lua-----------
- ----------------------------
- local widget = require( "widget" )
- local composer = require "composer"
- --local scene = composer.newScene()
- local ui = require "userinterface" -- handles various user-interface related tasks
- local gameNetwork = require "gameNetwork"
- -- Define reference points locations anchor ponts
- local TOP_REF = 0
- local BOTTOM_REF = 1
- local LEFT_REF = 0
- local RIGHT_REF = 1
- local CENTER_REF = 0.5
- _G.scoreUser = 580 --comment out when ready to build
- local centerX = display.contentCenterX
- local centerY = display.contentCenterY
- local _W = display.contentWidth
- local _H = display.contentHeight
- -- setup composer scenes (non-external module scenes)
- local boardScene = composer.newScene( "boardScene" )
- -- variables (and forward declarations)
- local logo, bg, currentScoreLabel, titleBar, titleText, shadow
- local requestCallback, userScoreText, currentBoardText, userBestText, bestLabel, bestText, butLeaderboard, butGoBack, butSubmitScore, butShowLeaderboard
- local userScore, userBest, bestTextValue, topScorer = 0, "points", "points", "???"
- local setUserScore = {}
- local offlineAlert = {}
- local onIncrementScore = {}
- local onSubmitScore = {}
- local onChangeBoard = {}
- local onShowBoards = {}
- local onShowAchievements = {}
- local onGoBack = {}
- userScore = _G.scoreUser
- --FUNCTIONS--
- function requestCallback( event )
- if event.type == "setHighScore" then
- ----UNLOCK ACHEIVMENTS-----------------------------
- if _G.scoreAlbumCounter == 1 then
- gameNetwork.request( "unlockAchievement", {
- achievement = {
- identifier=achievements["1_record"],
- percentComplete=25,
- showsCompletionBanner=true,
- }
- })
- elseif _G.scoreAlbumCounter == 2 then
- gameNetwork.request( "unlockAchievement", {
- achievement = {
- identifier=achievements["2_record"],
- percentComplete=50,
- showsCompletionBanner=true,
- }
- })
- elseif _G.scoreAlbumCounter == 3 then
- gameNetwork.request( "unlockAchievement", {
- achievement = {
- identifier=achievements["3_record"],
- percentComplete=75,
- showsCompletionBanner=true,
- }
- })
- )
- elseif _G.scoreAlbumCounter == 4 then
- gameNetwork.request( "unlockAchievement", {
- achievement = {
- identifier=achievements["4_record"],
- percentComplete=100,
- showsCompletionBanner=true,
- }
- })
- end
- -------------------------------------
- local function alertCompletion() gameNetwork.request( "loadScores", { leaderboard={ category="overall_allTime", playerScope="Global", timeScope="AllTime", range={1,3} }, listener=requestCallback } ); end
- native.showAlert( "High Score Reported!", "", { "OK" }, alertCompletion )
- elseif event.type == "loadScores" then
- if event.data then
- local topRankID = event.data[1].playerID
- local topRankScore = event.data[1].formattedValue
- bestTextValue = string.sub( topRankScore, 1, 12 )
- if topRankID then gameNetwork.request( "loadPlayers", { playerIDs={ topRankID }, listener=requestCallback} ); end
- end
- if event.localPlayerScore then
- userBest = event.localPlayerScore.formattedValue
- else
- userBest = "Not ranked"
- end
- if userBestText then ui.updateLabel( userBestText, userBest, display.contentWidth-25, 177, TOP_REF, RIGHT_REF ); end
- elseif event.type == "loadPlayers" then
- if event.data then
- local topRankAlias = event.data[1].alias
- if topRankAlias then
- topScorer = topRankAlias
- if bestLabel and bestText then
- ui.updateLabel( bestLabel, topScorer .. " got:", 25, 212, TOP_REF, LEFT_REF )
- ui.updateLabel( bestText, bestTextValue, display.contentWidth-25, 212, TOP_REF, RIGHT_REF )
- end
- end
- end
- end
- end
- function offlineAlert()
- native.showAlert( "GameCenter Offline", "Please check your internet connection.", { "OK" } )
- end
- function onSubmitScore( )
- if loggedIntoGC then gameNetwork.request( "setHighScore", { localPlayerScore={ category="overall_allTime", value=userScore }, listener=requestCallback } ); else offlineAlert(); end
- end
- function onShowBoards( )
- if loggedIntoGC then gameNetwork.show( "leaderboards", { leaderboard={ category="overall_allTime", timeScope="Week" } } ); else offlineAlert(); end
- end
- function onShowAchievements( )
- if loggedIntoGC then gameNetwork.show( "achievements" ); else offlineAlert(); end
- end
- function onGoBack( )
- timer.performWithDelay(600, function() composer.gotoScene("cred", "fade", 400) end )
- end
- -- boardScene (second tab) --------------------------------------------------------------
- function boardScene:create( event )
- local sceneGroup = self.view
- bg = display.newImageRect( "bgImage.jpg", 480, 320 )
- bg.x, bg.y = display.contentWidth*0.5, display.contentHeight*0.5
- bg.alpha = 1
- sceneGroup:insert( bg )
- --Leaderboard headding
- butLeaderboard = display.newImageRect( "images/butLeaderBoard.png", 325, 80 )
- butLeaderboard.x, butLeaderboard.y = display.contentWidth*0.5, 40
- butLeaderboard.alpha = 1
- sceneGroup:insert( butLeaderboard )
- -------------------
- butShowLeaderboard = display.newImageRect( "images/butShowLeaderboard.png", 260*0.7, 44*0.7 )
- butShowLeaderboard.x, butShowLeaderboard.y = display.contentWidth /2+20 , butLeaderboard.height + 20
- butShowLeaderboard:addEventListener("tap", onShowBoards)
- butShowLeaderboard.alpha = 1
- sceneGroup:insert( butShowLeaderboard )
- -------------------
- butGoBack = display.newImageRect( "images/butGoBack.png", 145*0.7, 44*0.7 )
- butGoBack.x, butGoBack.y = display.contentWidth-10 , butLeaderboard.height + 20
- butGoBack.anchorX = 1
- butGoBack:addEventListener("tap", onGoBack)
- butGoBack.alpha = 1
- sceneGroup:insert( butGoBack )
- -------------------
- butSubmitScore = display.newImageRect( "images/butSubmitScore.png", 212*0.7, 44*0.7 )
- butSubmitScore.x, butSubmitScore.y = 10, butLeaderboard.height + 20
- butSubmitScore.anchorX = 0
- butSubmitScore:addEventListener("tap", onSubmitScore)
- butSubmitScore.alpha = 1
- sceneGroup:insert( butSubmitScore )
- if loggedIntoGC then gameNetwork.request( "setHighScore", { localPlayerScore={ category="overall_allTime", value=scoreUser }, listener=requestCallback } ); end
- print("userScore = " .. userScore)
- local yourLabel = ui.createLabel( sceneGroup, "Your Best score", 25, 177, TOP_REF, LEFT_REF, true )
- display.remove( userBestText )
- userBestText = ui.createLabel( sceneGroup, userBest, display.contentWidth-25, 177, TOP_REF, RIGHT_REF )
- display.remove( bestLabel )
- bestLabel = ui.createLabel( sceneGroup, topScorer .. " got:", 25, 212, TOP_REF, LEFT_REF, true )
- display.remove( bestText )
- bestText = ui.createLabel( sceneGroup, bestTextValue, display.contentWidth-25, 212, TOP_REF, RIGHT_REF )
- native.showAlert( "unlockAchievement 1", { "OK" } )
- end
- boardScene:addEventListener( "create", boardScene )
- ---------------------------------------------------------------------------------
- --Runtime:addEventListener( "system", onSystemEvent )
- --ui.createTabs( widget )
- return boardScene
- --main.lua--------------------
- ------------------------------
- display.setStatusBar(display.HiddenStatusBar)
- local gameNetwork = require "gameNetwork"
- local composer = require "composer"
- initCallback = {}
- onSystemEvent = {}
- _G.messageFont = "Gartentika" -- Custom font used in the game
- _G.scoreFont = "Cheboygan"
- _G.debugMode = 0 -- Switch to 0 when done debugging
- _G.help = 0 -- Check if the user use helpfunction or not
- _G.scorePath = "images/"
- _G.livesLeft = 3
- _G.scoreUser = 600 -- [ Default values = 0 ] The Total user score
- _G.scoreTrackCounter = 1 -- [ Default values = 1 ] Amount of tracks you need to manage before ure done w the Album, this is set in main and increased in playGame on sucess
- _G.scoreTrackCounter = 1 -- [ Default values = 1 ] Amount of tracks you need to manage before ure done w the Album, this is set in main and increased in playGame on sucess
- _G.scoreAlbumCounter = 1 -- [ Default values = 0 ] This is increased by 1 for every 5 tracks u manage
- _G.doneSplash = false -- Starts the initial mode with the intro, this changes to true when entering playGame
- -- so we dont have to see the intro every time we decide to hit replay.
- -- thats why we set this boolean to true when entering playGame
- _G.trackCounter = 1
- --audio.setVolume(0) --when ure sick of music and want to hear other music when coding !
- print("\n\n¡!¡!¡!¡!¡ REMEMBER TO COMMENT audio.setVolume IN MAIN.LUA ¡!¡!¡!¡!¡\n\n")
- print("\n\n¡!¡!¡!¡!¡ REMEMBER DEBUGMODE = 0 BEFORE BUILD FOR STORE¡!¡!¡!¡!¡\n\n")
- print(_G.scoreUser , "ScoreUser")
- print(_G.scoreAlbumCounter , "scoreAlbumCounter")
- print(_G.scoreAlbumCounter , "scoreAlbumCounter")
- --Log in to GC ---------------------------------------------------------------------------------
- function initCallback( event )
- -- "showSignIn" is only available on iOS 6+
- if event.type == "showSignIn" then
- elseif event.data then
- loggedIntoGC = true
- end
- end
- -- system event handler -----------------------------------------------------------------
- function onSystemEvent( event )
- if "applicationStart" == event.type then
- loggedIntoGC = false
- gameNetwork.init( "gamecenter", { listener=initCallback } )
- return true
- end
- end
- -- END OF GAME CENTER CODE -----------------------------------------------------------------
- Runtime:addEventListener( "system", onSystemEvent )
- composer.gotoScene( "intro", "fade", 400 )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement