I am not sure how to do that. I will post the code for the entire mini game here. If you can’t figure it out like that just tell me how to upload the zip file and I will do that.
[code]
module(…, package.seeall)
–====================================================================–
– SCENE: Fishbowl Game
–====================================================================–
–[[
- Version: 0.1
- Made by Ninja Carnival Team @ 2011
******************
–]]
new = function ( params )
– Imports
local ui = require ( “ui” )
– Groups
local localGroup = display.newGroup()
local bgGroup = display.newGroup()
local scoreLayer = display.newGroup()
– Declare Variables
local gameIsActive = true
local toRemove = {}
local score = 0
local halfPlayerWidth
local toRemoveFish = {}
– start physics
local physics = require(“physics”)
local sprite = require(“sprite”)
physics.start()
physics.setGravity(0,0 )
– Enemy graphics held in memory
local textureCache = {}
textureCache[1] = display.newImage(“images/Lvl_2/fish.png”)
textureCache[1].isVisible = false
local halfEnemyWidth = textureCache[1].contentWidth * .5
– Pre-loads our sounds
swimming = audio.loadSound(“audio/Lvl_2/swimmingfinal.wav”)
music = audio.loadStream(“audio/Lvl_2/LevelTwoSongFinal.wav”)
– Display Objects
local contentWidth = display.contentWidth
local image1 = display.newImage(“images/Lvl_2/Level_2_BG_1.png”,0,0)
local image2 = display.newImage(“images/Lvl_2/Level_2_BG_2.png”,480,0)
local image3 = display.newImage(“images/Lvl_2/Level_2_BG_3.png”,480,0)
local image4 = display.newImage(“images/Lvl_2/Level_2_BG_4.png”,480,0)
local image5 = display.newImage(“images/Lvl_2/Level_2_BG_5.png”,480,0)
local image6 = display.newImage(“images/Lvl_2/Level_2_BG_6.png”,480,0)
local image7 = display.newImage(“images/Lvl_2/Level_2_BG_7.png”,480,0)
local image8 = display.newImage(“images/Lvl_2/Level_2_BG_8.png”,480,0)
local image9 = display.newImage(“images/Lvl_2/Level_2_BG_9.png”,480,0)
local image10 = display.newImage(“images/Lvl_2/Level_2_BG_10.png”,480,0)
–[[transition.to(image1, { time= 10000, delay= 1500, x= -(image1.width* 0.5)} )
transition.to(image2, { time= 10000, delay= 1500, x= (image2.width * 0.5) } )
transition.to(image3, { time= 10000, delay= 1500, x= (image3.width * 0.5) } )
transition.to(image4, { time= 10000, delay= 1500, x= (image4.width * 0.5) } )
transition.to(image5, { time= 10000, delay= 1500, x= (image5.width * 0.5) } )
transition.to(image6, { time= 10000, delay= 1500, x= (image6.width* 0.5) } )
transition.to(image7, { time= 10000, delay= 1500, x= (image7.width * 0.5) } )
transition.to(image8, { time= 10000, delay= 1500, x= (image8.width * 0.5) } )
transition.to(image9, { time= 10000, delay= 1500, x= (image9.width * 0.5) } )
transition.to(image10, { time= 10000, delay= 1500, x= (image10.width * 0.5) } ) --]]
scoreText = display.newText(score, 0, 0, native.systemFont, 19)
scoreText:setTextColor(0,0,155)
scoreText.x = 100
– BUTTONS
– Functions
local function onCollision(self, event)
if self.name == “swimming” and event.other.name == “fish” and gameIsActive then
score = score + 1
scoreText.text = score
–get a sound effect for this event
table.insert(toRemove, event.other)
elseif self.name == “swimming” and event.other.name == “squid” and gameIsActive then
gameEnd()
elseif self.name == “swimming” and event.other.name == “urchin” and gameIsActive then
gameEnd()
end
end
local function spawnUrchin( event )
local urchin = display.newImage(“images/Lvl_2/urchin_final_56.png”)
urchin.name = “urchin”
physics.addBody(urchin, “kinematic”, {density=1.0, friction=0.5, bounce=0.0, radius= 30})
urchin.y = 320
urchin.x = math.random(50,480)
transition.to(urchin, {time = 20000, y = -320})
print (urchin.y)
return urchin
end
local function spawnFish( event )
local fish = display.newImage(“images/Lvl_2/fish.png”,50,60)
fish.name = “fish”
physics.addBody(fish, “kinematic”, {density=1.0, friction=0.5, bounce=0.0, radius= 30})
fish.x = math.random(480, 480)
fish.y = math.random(50, 320)
transition.to(fish, {time= math.random(2000,4000), x=-250})
return fish
end
function newSwimmingSprite()
swimming = sprite.newSprite(spriteSet2)
swimming:prepare(“default”)
swimming.isHitTestable = false
print (“gotit”)
return swimming
end
local function movePlayer( event )
if event.phase ~= ended and gameIsActive then
transition.to( swimming, { time=1500, x = event.x, y = event.y } )
swimming.velocity = 0
print(swimming.y)
end
–print (“moved player”)
end
local function spawnPlayer( event )
swimming = newSwimmingSprite()
swimming.name = “swimming”
physics.addBody(swimming, “dynamic”, {density=1.0, friction=0.5, bounce=0.0, radius= 15})
swimming.collision = onCollision
swimming:addEventListener(“collision”, swimming)
Runtime:addEventListener(“touch”, movePlayer)
swimming:play()
print (“spawnedPlayer”)
end
function coordUpdate( event )
if swimming.x > 460 then swimming.x = 460
print(swimming.x)
end
end
local function canWeScroll(event)
bgGroup.x = bgGroup.x - 1
if image1.x > 800 then
bgGroup.x = bgGroup.x - 1
end
end
function gameEnd( event )
gameIsActive = false
swimming:pause()
end
– PARAMETERS
– Listener
– INITIALIZE
local initVars = function ()
– Inserts
bgGroup:insert(image1)
bgGroup:insert(image2)
bgGroup:insert(image3)
bgGroup:insert(image4)
bgGroup:insert(image5)
bgGroup:insert(image6)
bgGroup:insert(image7)
bgGroup:insert(image8)
bgGroup:insert(image9)
bgGroup:insert(image10)
scoreLayer:insert(scoreText)
– Positions
– Colors
– Listeners
swimming = sprite.newSpriteSheet( “swim_sheet.png”, 64, 31 )
spriteSet2 = sprite.newSpriteSet(swimming, 1, 4)
sprite.add( spriteSet2, “default”, 1, 4, 1000, 0 )
spawnPlayer()
swimming.x = display.contentWidth * 0.5
swimming.y = display.contentHeight * 0.5
end
– Initiate variables
initVars()
– Update
local update = function ( event )
local timeLastEnemy = 0
if gameIsActive then
for i = #toRemove, 1, -1 do
toRemove[i].parent:remove(toRemove[i])
toRemove[i] = nil
end
for i = #toRemoveFish, 1, -1 do
remove(toRemoveFish[i])
toRemoveFish[i] = nil
end
end
end
audio.play(music, {loops = -1})
timer.performWithDelay(math.random(500, 1000), spawnFish, 0)
timer.performWithDelay(2500, spawnUrchin, 0)
Runtime:addEventListener(“enterFrame”, update)
Runtime:addEventListener(“enterFrame”, coordUpdate)
Runtime:addEventListener(“enterFrame”, canWeScroll)
– MUST return a display.newGroup()
return localGroup
end [import]uid: 49863 topic_id: 19155 reply_id: 76933[/import]