What I am trying to accomplish is simple… Basically I want the flies that the player has missed to come back somehow so that the player has an infinite amount of chances to catch all the flies.
I could do something like this
[lua]function transition_to_left()
transition.to(aFly, {time=2000, x = 0, y = aFly.y, onComplete = transition_to_right})
end
function transition_to_right()
transition.to(aFly, {time=2000, x = 2000, y = aFly.y, onComplete = transition_to_left})
end
transition_to_right()[/lua]
The only problem is I don’t know how to add it to the game I already have done…
CODE:
[lua]display.setStatusBar( display.HiddenStatusBar ) – HIDE STATUS BAR
–Math Functions
local random = math.random
–requires Loq Sprite
local loqsprite = require(‘loq_sprite’)
–forward Declaration
local caughtFly, removeFly, spawnFly, catchFly
local onEnterFrame
–Variable we need for the game
local i
local fliesCaught = 0
local flies = {}
local fly
local maxFlies = 10
local fliesOnScreen = 0
local _fly={}
local counter = 0
local timeBetweenFlies = 1
local tries = 10
local screenW = display.contentWidth
local screenH = display.contentHeight
–Start creating the Elements on screen
–The background
local BG = display.newImageRect(“background.png”, 1024, 768)
BG.x = screenW/2; BG.y = screenH/2
–The Frog
local ffactory = loqsprite.newFactory(“frog”)
local frog = ffactory:newSpriteGroup()
frog.x = 640 ; frog.y = 470
–The Score Text
local numberCount = display.newText(string.format("%02d", 0), 0, 0, native.systemFontBold, 40)
numberCount.x = frog.x; numberCount.y = frog.y
function caughtFly(thisFly)
fliesCaught = fliesCaught + 1
–update the score
numberCount.text = string.format("%02d", fliesCaught)
–and let us remove this fly
removeFly(thisFly)
end
function removeFly(thisOne)
thisOne:removeSelf()
flies[thisOne.ID] = nil
thisOne = nil
–print(“Fly Removed”)
fliesOnScreen = fliesOnScreen - 1
end
function spawnFly()
if fliesOnScreen >= maxFlies then return end
local theFly = _fly.new()
if theFly == nil then return end
theFly:play(“aniFly fly”)
flies[theFly.ID] = theFly
fliesOnScreen = fliesOnScreen + 1
–print(“Flies on screen”, fliesOnScreen)
end
local function checkIfAnyFlyIsWithin(x1, x2)
local k,v
for k,v in pairs(flies) do
if v.x > x1 and v.x < x2 then
return v
end
end
end
local function catchFly(event)
–Play the frog aniamtion
frog:play(“aniFrog eat”)
–Determine if the fly is at the position where the frogs tongue is…
–1240 - 1280 is the window that we offer for the frog to catch the fly.
local theFly = checkIfAnyFlyIsWithin(1240,1300)
if theFly ~= nil then
caughtFly(theFly)
end
end
function onEnterFrame(event)
–the heart beat of this app
if counter >= tries and fliesOnScreen == 0 then
print(“Game Over”)
local text = display.newText(“Game Over”, 0,0, native.systemFontBold, 256)
text:scale(0.5,0.5)
text.x = screenW/2
text.y = screenH/2
text.alpha=0
transition.to(text,{time=1000, alpha=1})
Runtime:removeEventListener(“enterFrame”,onEnterFrame)
end
if fliesOnScreen < maxFlies then
timeBetweenFlies = timeBetweenFlies - 1
if timeBetweenFlies==0 then
spawnFly()
timeBetweenFlies = random(1,10)+20
end
end
local k,v
for k,v in pairs(flies)do
local theFly = v
theFly.x = theFly.x + theFly.speed
if theFly.x > 1550 then
theFly.canMove = false
flies[k]=nil
removeFly(v)
end
end
end
Runtime:addEventListener(“enterFrame”,onEnterFrame)
frog:addEventListener(“tap”, catchFly)
function _fly.new()
if tries < counter then return nil end
local flyfactory = loqsprite.newFactory(“fly”)
local aFly = flyfactory:newSpriteGroup()
aFly.x = 200; aFly.y = 350
aFly.ID = “Item_” … counter
aFly.speed = random(1,6)+3
aFly.canMove = true
counter= counter + 1
return aFly
end[/lua]
This link better explains the game itself http://howto.oz-apps.com/2011/10/bug-catcher-game-tutorial.html
Thanks for any help or suggestions!! [import]uid: 51459 topic_id: 16517 reply_id: 316517[/import]
[import]uid: 51459 topic_id: 16517 reply_id: 61719[/import]