Hi everyone,
This is my first attempt at an app and it is based on the traditional bubble shooter game (shoot a colored bubble at target bubbles above if 3 or more of the same colour bubbles are touching remove the bubbles).
I have managed to create the target bubbles in a separate bubble.lua class by using a 2d array in a 9x9 grid. I have added physics to these bubbles and have made them static.
function bubble.new(x, y) – constructor
bubbleTable = { {“redbubble.png” } , { “bluebubble.png” } , { “greenbubble.png” } }
newBubble = { }
newBubble.image =display.newImage ( ( bubbleTable[math.random( 1,3 )][1] ), x, y)
physics.addBody( newBubble.image, “static”, { density=2.9, friction=0.1, bounce=0.2, radius=(d/2) } )
return setmetatable( newBubble, bubble_mt )
end
I’ve also created a blue bubble to act as the bubble being fired from the bottom of the screen. I have added physics to it and made it kinematic and added a touch event listener to fire the bubble
physics.addBody( bubbleBlue, “kinematic”, { density=2.9, friction=0.1, bounce=0.2, radius=d/2 } )
function fire(event)
if(event.phase == “began”) then
–Do something during the began phase
txt.text = "Began Phase “…event.x…” = x “…event.y…” = y "
display.getCurrentStage():setFocus(event.target, event.id)
startForceX = event.x; startForceY = event.y
elseif(event.phase == “moved”) then
–Do something during the moved phase
txt.text = event.x…" = x “…event.y…” = y Moved"
elseif(event.phase == “ended”) then
–Do something when the phase has ended
txt.text = event.x…" = x “…event.y…” = y Ended"
display.getCurrentStage():setFocus(event.target, nil)
endForceX = event.x; endForceY = event.y
bubbleBlue:setLinearVelocity( (startForceX - endForceX), (startForceY - endForceY) )
end
end
My problem is that once the bubble is fired it pass over the bubbles i have created. however when i remove “static” from the target bubbles which makes them fall to the bottom of the screen, they do collide with the bubble to be fired.
Thank you in advance for any help [import]uid: 163580 topic_id: 30197 reply_id: 330197[/import]
[import]uid: 52491 topic_id: 30197 reply_id: 120961[/import]