I’m trying to create a Angry Bird-esque game where you fling a bomb to a structure. Upon collision, the bomb should explode, create a explosion field that pushes any object caught in it in a certain direction, depending on its location in comparison to the explosion’s center.
I’ve got the code I need, but I ran into a limitation of Corona, which is that I cant alter or do anything with the physics engine while Corona is “number crunching”
I wanted to draw a static circle, with isSensor set to true, to act as the explosion radius.
My relevant code:
My code for shooting the bomb
--Shoot the bomb function circleTouched(event) if event.phase == "began" then display.getCurrentStage():setFocus(bomb) elseif event.phase == "ended" then bomb:applyLinearImpulse(event.xStart - event.x, event.yStart - event.y, bomb.x, bomb.y) timer.performWithDelay ( 250, checkHit ) display.getCurrentStage():setFocus(nil) end end
Code that checks if the bomb collided with something:
--Check if bomb hit function checkHit(event) bomb.collision = onCollision bomb:addEventListener( "collision", bomb ) end
Spawning the “explosion” (currently the circle should be visible, for testing purposes):
--Execute on bomb collision function onCollision(event) hit = true bomb:removeEventListener("touch", circleTouched) bomb:removeEventListener ( "collision", bomb ) bomb:removeSelf() circle = display.newCircle( event.x, event.y, 80 ) circle.myName = "circle" circle:setFillColor(100,100,100, 100) physics.addBody( circle, "static", {isSensor = true} ) circle.collision = onLocalCollision circle:addEventListener( "collision", circle ) end
The code for the explosion itself hasnt been written yet, but that shouldn’t (hopefully) be much of a problem.
Is there any way I can still create an explosion in a way like I envisioned, or am I forced to take a completely different approach?