[code]
require “CiderDebugger”;local physics = require(“physics”)
local physics = require(“physics”)
physics.start()
display.setStatusBar(display.HiddenStatusBar)
_W = display.contentWidth
_H = display.contentHeight
_CW = display.contentWidth / 2
_CH = display.contentHeight / 2
local sounds = {
[1] = “introMusic.mp3”,
[2] = “gamePlayMusic.mp3”,
[3] = “birdWav.wav”,
[4] = “fireWav.mp3”
}
local sound = {}
for i = 1, 4 do
sound[i] = audio.loadSound(sounds[i])
end
audio.play(sound[1], { loops = -1})
bkg2 = display.newImage(“bkg2.png”, 0, 0)
bkg2.x, bkg2.y = _CW, _CH
local bkg = display.newImage(“bkg.jpg”, 0, 0)
bkg.x, bkg.y = _CW, _CH
local function loadGamePlay()
local bird
randomSpawn = math.random(0, 100)
birdsCollection = {
[1] = “angryBirdRed.png”,
[2] = “angryBirdWhite.png”,
[3] = “angryBirdYellow.png”
}
if randomSpawn <= 30 and randomSpawn >= 0 then
bird = display.newImage(birdsCollection[math.random(1, 3)], 0, 0)
bird.myName = “bird”
bird.x, bird.y = -25, math.random(-25, _CH + 240)
elseif randomSpawn <= 60 and randomSpawn >= 31 then
bird = display.newImage(birdsCollection[math.random(1, 3)], 0, 0)
bird.myName = “bird”
bird.x, bird.y = display.contentWidth + 25, math.random(-25, _CH + 240)
elseif randomSpawn <= 100 and randomSpawn >= 61 then
bird = display.newImage(birdsCollection[math.random(1, 3)], 0, 0)
bird.myName = “bird”
bird.x, bird.y = math.random(0, display.contentWidth), -25
end
physics.addBody(bird, {density = 1})
transition.to(bird, {time = 1500, x = _CW, y = _CH + 240 })
return bird
end
local tempBird = loadGamePlay()
function birdTrans()
timer.performWithDelay(800, loadGamePlay, 0)
end
function throwRock(e)
local rock
if e.phase == “began” then
rock = display.newImage(“rock.png”, 0, 0)
rock.myName = “rock”
rock.x, rock.y = _CW, _CH + 240
transition.to(rock,{
onStart = audio.play(sound[4]),
time = 600,
x = e.x,
y = e.y
})
transition.to(rock, {time = 10, delay = 600, alpha = 0 })
end
return rock
end
function closeIntro()
audio.pause(sound[1])
sound[1] = nil
audio.play(sound[2],{loops = -1})
loadGamePlay()
end
function onIntro(e)
if e.phase == “began” then
transition.to(bkg,{time = 100, alpha = 0, x = bkg.x - _W, onComplete = closeIntro})
birdTrans()
end
return true
end
local function onLocalCollision(self, e)
if e.phase == “began” then
if self.myName == “bird” then
print(“ouch”)
tempBird:removeSelf()
–rock:removeSelf()
bird = nil
rock = nil
end
end
end
bird.collision = onLocalCollision
bird:addEventListener(“collision”, bird)
bkg:addEventListener(“touch”, onIntro)
bkg2:addEventListener(“touch”, throwRock)
[/code] [import]uid: 197599 topic_id: 33407 reply_id: 333407[/import]