require "ads"
require "googleplay"
GameOver = gideros.class(Sprite)
INTERSTITIAL = 1
VIDEO = 2
BANNER = 4
BANNER_BOTTOM = 8
BANNER_TOP = 16
BANNER_CENTER = 32
ALL = 127
ANY = 127
function GameOver:init(t)
appodeal = Ads.new("appodeal")
appodeal:setKey("")
GameOver:initializeGameSprites(self)
end
function GameOver:initializeGameSprites(self)
fontLarge = TTFont.new("GROBOLD.ttf", 24)
self:addChild(Bitmap.new(Texture.new("GameBG.png")))
local imgGameOverBackdrop = Bitmap.new(Texture.new("GameOver.png"))
imgGameOverBackdrop:setPosition(10, 5)
self:addChild(imgGameOverBackdrop)
local GameOver = TextField.new(fontLarge, "Your Score")
centreAt(GameOver, 160, 150)
GameOver:setTextColor(0xffffff)
self:addChild(GameOver)
local finalScore = TextField.new(fontLarge, _G.finalScore)
centreAt(finalScore, 160,200)
finalScore:setTextColor(0xffffff)
self:addChild(finalScore)
local applause = Sound.new("applause.wav")
local btnSubmitScore = Button.new(Bitmap.new(Texture.new("btnSubmitScore.png")), Bitmap.new(Texture.new("btnSubmitScore.png")))
btnSubmitScore:setPosition(50, 325)
self:addChild(btnSubmitScore)
btnSubmitScore:addEventListener("click",
function()
if _G.gLogin == false then
--log into google play
googleplay:login()
else
googleplay:reportScore("CgkIudWT9tcCEAIQAA", _G.finalScore)
end
end)
googleplay:addEventListener(Event.LOGIN_ERROR, function()
_G.gLogin = false
end)
googleplay:addEventListener(Event.LOGIN_COMPLETE, function()
_G.gLogin = true
googleplay:reportScore("", _G.finalScore)
end)
local btnMainMenu = Button.new(Bitmap.new(Texture.new("btnMainMenu.png")), Bitmap.new(Texture.new("btnMainMenu.png")))
btnMainMenu:setPosition(50, 400)
self:addChild(btnMainMenu)
btnMainMenu:addEventListener("click",
function()
local transition = transitions[math.random(1, 4)]
sceneManager:changeScene("MainMenu", 1, transition, easing.outBack, { eventFilter={Event.MOUSE_DOWN} } )
end)
--hook into the android back button
self:addEventListener(Event.KEY_DOWN, self.onKeyDown, self)
self:addEventListener("enterBegin", self.onTransitionInBegin, self)
self:addEventListener("enterEnd", self.onTransitionInEnd, self)
self:addEventListener("exitBegin", self.onTransitionOutBegin, self)
self:addEventListener("exitEnd", self.onTransitionOutEnd, self)
if _G.soundEnabled == true then
applause:play()
end
end
function GameOver:onKeyDown(event)
if (event.keyCode == KeyCode.BACK) then
local transition = transitions[math.random(9, 12)]
sceneManager:changeScene("MainMenu", 1, transition, easing.outBounce, { userData = "outBounce" } )
end
end
function centreAt(sprite,x,y)
local w=sprite:getWidth()
local h=sprite:getHeight()
sprite:setPosition(math.floor(x-w/2),math.floor(y+h/2))
end
function GameOver:onTransitionInBegin()
print("Credits - enter begin")
end
function GameOver:onTransitionInEnd()
appodeal:showAd(INTERSTITIAL)
end
function GameOver:onTransitionOutBegin()
print("Credits - exit begin")
end
function GameOver:onTransitionOutEnd()
end
Comments