display.setStatusBar( display.HiddenStatusBar )
-- Physics engine to apply gravity
local physics = require("physics")
physics.start()
-- physics.pause()
-- gravity to speed down or up
physics.setGravity(0, 8)
-- physics.setDrawMode("hybrid")
local background = display.newImage("sky.png")
local balloon = display.newImage("balloon1.png", 50,100)
--math.randomseed(os.time())
-- add options (for image sellection)
local options = { "balloon1.png", "balloon2.png", "balloon3.png", "balloon4.png", "balloon5.png", "balloon6.png", "balloon7.png", "balloon8.png", "balloon9.png", "balloon10.png" }
-- display random balloon function
function showBalloon ()
local above = math.random( 1, 10 )
local balloon = display.newImage( options[above], 150, 400 )
physics.addBody( balloon, { density = 1, friction = 1, bounce = 1 } )
end
Runtime:addEventListener( "tap", showBalloon )
--\> Adding touch sound
local town = audio.loadSound ("adelle.wav")
local function playTown (event)
audio.play (town)
end
balloon:addEventListener ("tap", playTown)
-- get balloon moving
physics.addBody ( balloon, "dynamic", {density=1, friction=1, bounce=.5})
-- Add balloon2
local balloon2 = display.newImage("balloon2.png", 800,500)
physics.addBody ( balloon2, "dynamic", {density=1, friction=1, bounce=.8})
-- Add balloon3
local balloon3 = display.newImage("balloon3.png", 100,300)
physics.addBody ( balloon3, "dynamic", {density=1, friction=2, bounce=.3})
-- Add balloon4
local balloon4 = display.newImage("balloon4.png", 60,200)
physics.addBody ( balloon4, "dynamic", {density=1, friction=1, bounce=.7})
-- Add balloon5
local balloon5 = display.newImage("balloon5.png", 90,550)
physics.addBody ( balloon5, "dynamic", {density=0, friction=2, bounce=.4})
-- Add balloon6
local balloon6 = display.newImage("balloon6.png", 410,490)
physics.addBody ( balloon6, "dynamic", {density=1, friction=2, bounce=.8})
-- Add balloon7
local balloon7 = display.newImage("balloon7.png", 700,690)
physics.addBody ( balloon7, "dynamic", {density=0, friction=2, bounce=.8})
-- Add balloon8
local balloon8 = display.newImage("balloon8.png", 300,590)
physics.addBody ( balloon8, "dynamic", {density=0, friction=1, bounce=.6})
-- Add balloon9
local balloon9 = display.newImage("balloon9.png", 500,690)
physics.addBody ( balloon9, "dynamic", {density=0, friction=1, bounce=.6})
-- Add balloon10
local balloon10 = display.newImage("balloon10.png", 750,250)
physics.addBody ( balloon10, "dynamic", {density=0, friction=1, bounce=.6})
--\> To have a static wall so the balloons won't disapear
local leftWall = display.newRect (0, 0, 1, display.contentHeight)
local rightWall = display.newRect (display.contentWidth, 0, 1, display.contentHeight)
local ceiling = display.newRect (0, 0, display.contentWidth, 1)
physics.addBody (leftWall, "static", {bounce = 0.5, friction = 10})
physics.addBody (rightWall, "static", {bounce = 0.5, friction = 10})
physics.addBody (ceiling, "static", {bounce = 0.5, friction = 10})
-- Add floor
local floor = display.newImage("grass2.png", 0,700)
physics.addBody ( floor, "static", {density=1, friction=1, bounce=.5})
-- touch function.....too much duplication here
function moveBalloon(event)
local balloon = event.target
local balloon2 = event.target
local balloon3 = event.target
local balloon4 = event.target
local balloon5 = event.target
local balloon6 = event.target
local balloon7 = event.target
local balloon8 = event.target
local balloon9 = event.target
local balloon10 = event.target
balloon:applyLinearImpulse(0, -0.6)
balloon2:applyLinearImpulse(0, -0.5)
balloon3:applyLinearImpulse(0, -0.3)
balloon4:applyLinearImpulse(0, -0.5)
balloon5:applyLinearImpulse(0, -0.6)
balloon6:applyLinearImpulse(0, -0.7)
balloon7:applyLinearImpulse(0, -0.4)
balloon8:applyLinearImpulse(0, -0.5)
balloon9:applyLinearImpulse(0, -0.5)
balloon10:applyLinearImpulse(0, -0.7)
end
----- too much duplication here too
balloon:addEventListener("touch", moveBalloon)
balloon2:addEventListener("touch", moveBalloon)
balloon3:addEventListener("touch", moveBalloon)
balloon4:addEventListener("touch", moveBalloon)
balloon5:addEventListener("touch", moveBalloon)
balloon6:addEventListener("touch", moveBalloon)
balloon7:addEventListener("touch", moveBalloon)
balloon8:addEventListener("touch", moveBalloon)
balloon9:addEventListener("touch", moveBalloon)
balloon10:addEventListener("touch", moveBalloon)
Questions:
I have got my code working and all the balloons are floating in the air but I have a few questions:
The balloons should be in the sequence or random order. They move the tendon to the edge and then the player should move back the balloons to the right place with the mouse. How?
- My random function keeps popping out more balloons by simple click.
I would like the user to perform some math operations, for instance add two random balloons and display the right answer on the screen.
How can i use 2 different level of difficulties? (L1, L2)
-
How to make my balloons to move to the different edges on the screen?
-
How can a user move back the balloons with mouse to the right places?
-
How can I tie my balloons to a rope (horizontally) ? so the user can make a choice.
-
My background image is about 3MB original(1024 x 768) to match well with ipad resolution, can I change the size without affecting the display in ipad?
-
I feel like the local balloon1,2,3…is repeated too much, and same goes to moveBalloon and applyLinear. Is there a way of shortening them? or is it normal since there are 10 balloons?
-
I have added sound to the first balloon by simple click, should duplicate the same function for the rest of the 9 balloons (another mess)? I will use the same sound to all.
Your feedback is much appreciated.
Thanx in advance !
[import]uid: 133212 topic_id: 23117 reply_id: 323117[/import]