HELP!!! This code runs great in the Corona AVM, but I get a build error I just can’t figure out! Can anyone help me? I get no error messages in the console window.
The code:
–[[---------------------------------------------------
Burst-UR-Bubble
Author: Chris Renshaw
Copyright February 4, 2011
–]]---------------------------------------------------
– Add physics engine, start up the engine, and apply gravity
local physics = require(“physics”)
physics.start()
physics.setGravity(0, 2)
–*******************************************************************************************
– local Main variables
– adjustable settings
–local gravity = 2
local radius = 15
local delay = 500
– score variables
local bubblesSpawned = 0
local bubblesPopped = 0
local bubblesDropped = 0
–*******************************************************************************************
– physics.setDrawMode(“hybrid”)
–*******************************************************************************************
– system.activate(“multitouch”) (ios)
– display.setStatusBar(display.HiddenStatusBar) (ios)
–*******************************************************************************************
– *************preload sounds***************************
local popSound = audio.loadSound(“sounds/pop2_wav.wav”)
local bombSound = audio.loadSound(“sounds/bomb_wav.wav”)
local beginSound = audio.loadSound(“sounds/CameraShutter_wav.wav”)
–*******************************************************************************************
– Add splash screen background
local splashBkg = display.newRect(0, 0, display.contentWidth, display.contentHeight)
splashBkg:setFillColor(0, 0, 0)
splashBkg.isVisible = false
– Add logo
local logo = display.newImage("./images/splashScreen.png")
logo.x = display.contentWidth * .5
logo.y = display.contentHeight * .5
logo.isVisible = false
– Add Background image
local background = display.newImage("./images/bkg.png", 0, 0, false)
background.x = display.contentWidth * .5
background.y = display.contentHeight * .5
background.isVisible = false
– Add ground image and position
local ground = display.newImage("./images/grass.png")
ground.y = display.contentHeight - (ground.contentHeight * .5)
ground.isVisible = false
– Add walls
local leftWall = display.newRect(0, 0, 0, display.contentHeight)
local rightWall = display.newRect(display.contentWidth, 0, 0, display.contentHeight)
local ceiling = display.newRect(0, 0, display.contentWidth, 0)
local floor = display.newRect(0, display.contentHeight - 50, display.contentWidth, display.contentHeight - 50)
physics.addBody(leftWall, “static”, {bounce = 0.1})
physics.addBody(rightWall, “static”, {bounce = 0.1})
physics.addBody(ceiling, “static”, {bounce = 0.1})
physics.addBody(floor, “static”, {bounce = 0.1})
floor.isVisible = false
floor.myName = “ground”
– Add sword
local sword = display.newImage("./images/sword.png")
sword.x = display.contentWidth * 0.5
sword.y = display.contentHeight - ground.contentHeight - 65
triangleShape = {0, -60, 10, 60, -10, 60}
physics.addBody(sword, “static”, {friction = 0.0, shape=triangleShape})
sword.isPlatform = true
sword.myName = “sword”
sword.collision = onLocalCollision
sword.isVisible = false
– Add counter
local counter = display.newText(" ", 0, 0, system.systemFont, 60)
counter.x = display.contentWidth * 0.5
counter.y = 0 + 15 * 2.5
counter:setTextColor(255, 0, 0)
counter.isVisible = true
–*******************************************************************************************
– display splash screen
local function splashScreen()
audio.play(beginSound)
splashBkg.isVisible = true
logo.isVisible = true
end
–*******************************************************************************************
– display end splash screen
local function endSplash()
– Draw black background for end of game
local gameOver = display.newRect(0, 0, display.contentWidth, display.contentHeight)
gameOver:setFillColor(0 ,0, 0)
gameOver.isVisible = true
– Add counter
local counter = display.newText(tostring(bubblesPopped), 0, 0, system.systemFont, 60)
counter.x = display.contentWidth * 0.5
counter.y = 0 + 15 * 2.5
counter:setTextColor(255, 0, 0)
counter.isVisible = true
– Add Game Over! text
local gameOverText = display.newText(“Game Over!”, 0, 0, system.systemFont, 60)
gameOverText.x = display.contentWidth * 0.5
gameOverText.y = display.contentHeight * 0.5
gameOverText:setTextColor(255, 0, 0)
gameOverText.isVisible = true
end
–*******************************************************************************************
– A basic function for dragging sword
local function startDrag(event)
local t = event.target
local phase = event.phase
if “began” == phase then
display.getCurrentStage():setFocus(t)
t.isFocus = true
– Store initial position
t.x0 = event.x - t.x
t.y0 = event.y - t.y
– Stop current motion, if any
event.target:setLinearVelocity(0, 0)
event.target.angularVelocity = 0
elseif t.isFocus then
if “moved” == phase then
t.x = event.x - t.x0
t.y = event.y - t.y0
if t.y < (display.contentHeight * 0.66) then
t.y = (display.contentHeight * 0.66)
end
if t.y > (display.contentHeight - ground.contentHeight) then
t.y = (display.contentHeight - ground.contentHeight)
end
if t.x > (display.contentWidth) then
t.x = (display.contentWidth - 1)
end
if t.x < (0) then
t.x = (1)
end
elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus(nil)
t.isFocus = false
end
end
– Stop further propagation of touch event!
return true
end
–*******************************************************************************************
– update score function
local function dScore()
if bubblesDropped == 0 then
counter.text = (tostring(bubblesPopped))
end
end
–*******************************************************************************************
– quit the game
local function quitGame()
os.exit()
end
–*******************************************************************************************
– game over splash screen
local function endLevel()
endSplash()
timer.performWithDelay(10000, quitGame, 1)
end
–*******************************************************************************************
– A touch listener to pop bubbles
local popBubble = function(event)
local t = event.target
local phase = event.phase
if bubblesDropped == 0 then
if event.other.myName == “sword” then
if “began” == phase then
audio.play(popSound)
dScore()
t:removeSelf() – destroy object
– Bubble counter & update score display
bubblesPopped = bubblesPopped + 1
end
end
end
if bubblesDropped > 0 then
endLevel()
end
– stop further propagation of touch event
return true
end
–*******************************************************************************************
– A touch listener for dropped bubbles
local dropBubble = function(event)
local t = event.target
local phase = event.phase
if event.other.myName == “ground” then
if “began” == phase then
if bubblesDropped == 0 then
audio.play(bombSound)
dScore()
end
t:removeSelf() – destroy object
– Bubble counter & update score display
bubblesDropped = bubblesDropped + 1
if bubblesDropped > 0 then
endLevel()
end
end
end
– stop further propagation of touch event
return true
end
–*******************************************************************************************
– Create bubbles for game play
local function spawnBubbles(event)
– Add bubbles to stage and position
local bubble = display.newImage("./images/bubble-xs.png")
bubble.x = math.random(radius, display.contentWidth - radius)
bubble.y = math.random(30 + radius, display.contentHeight * 0.30)
physics.addBody(bubble, {bounce = 1,friction = .9, radius = radius} )
– Bubble counter & update score display
bubblesSpawned = bubblesSpawned + 1
dScore()
if bubblesDropped > 0 then
bubble:removeSelf()
end
– Add the listener to pop bubble
local function listen(event)
if bubblesDropped == 0 then
bubble:addEventListener(“collision”, popBubble)
bubble:addEventListener(“collision”, dropBubble)
end
end
listen()
end
–*******************************************************************************************
– game play function
local function playGame()
– unhide game screen
background.isVisible = true
ground.isVisible = true
sword.isVisible = true
counter.isVisible = true
– Spawning bubbles
timer.performWithDelay(delay, spawnBubbles, 0)
if bubblesDropped > 0 then
timer.cancel(self.source)
end
return false
end
–*******************************************************************************************
– start and allow delay for splash screen game play function
local function start(event)
timer.performWithDelay(5000, playGame, 1)
end
–*******************************************************************************************
– Main start section of game
splashScreen()
start()
Runtime:addEventListener(“collision”, sword)
Runtime:addEventListener(“collision”, ground)
sword:addEventListener(“touch”, startDrag)
–*******************************************************************************************
[import]uid: 25239 topic_id: 6454 reply_id: 306454[/import]