Here are some suggestions –
Crater Creation:
I see that you’re a Starter. If you’d a Pro or Enterprise subscription, you could’ve done this –
-
Create a background image.
-
Place a ground image on top of the background.
-
When the bomb collides with the ground, create an ellipse (display object) at that location on the ground image and use object.fill.blendMode to “reveal” the background. On how to use object.fill.blendMode, you can refer to the “SnapshotEraser” (Graphics-Premium) sample code that comes along with Corona SDK.
This would effectively create the illusion of a crater being created. However, since you’re a starter, you won’t be able to use Graphics 2.0 features. So object.fill.blendMode is out of the question. So you can probably do this –
-
Create an absolutely plain background image with a solid color. You can do this using display.newRect().
-
Place a ground image on top of the background at a suitable position.
-
Create other elements like clouds etc. (using images) on the background above the level of the ground. This would make your background appear a bit more appealing when compared to a plain color. You could go for parallax scrolling of these objects if you so desire.
-
When a bomb collides with the ground, create an ellipse and place it on the ground image. Ensure that the ellipse has the same color as the background. Since you don’t have a fancy background (with a gradient), and since your background and ellipse are of the same color, it would appear as if part of the ground was destroyed (in an elliptical shape) which resulted in a crater. For drawing ellipses, you can refer to this – http://code.coronalabs.com/code/arcs-and-ellipses
Collision Detection:
For creating dynamic elliptical (crater) physics objects, one could use the graphics.newOutline() feature used in this tutorial. But then again, you would need a Pro or an Enterprise subscription for that and also, runtime tracing could hurt performance. Since you’ll always be drawing elliptical craters, you can instead use this code to can scale a pre-defined elliptical physics object at runtime for your dynamically sized craters. However, this has two drawbacks –
-
Eventually, the player might end up making a lot of craters during the course of a game. Having so many physics bodies for collision detection could be taxing (especially on older phones) and hamper the smoothness of your game (60 fps will be hard to achieve).
-
Simple collision detection will not help you entirely. If the bomb collided with a crater, you also need to make another check to see if the bomb is completely inside the crater. If so, the bomb should continue descending downwards. If not, it means that the bomb hit the edge of the crater and you must then create another explosion/crater at that point.
Because of the above, I suggest you avoid physics-based collision completely. Instead refer to bobcook47’s sample program for Arcs and Ellipses that I linked above. It not only has code for creation of ellipses but also for intersection testing. You could use this as a basis for developing your own non-physics based collision detection routine. You can also refer to Rob’s tutorial on Non-Physics Collision Detection here for further pointers.
This was from the top of my head and I haven’t tested any of this. If I come across a better approach, I will post back. Good luck!