How to make craters explosion?

I’m making an horizontal scrolling game.

I have a physic shape of a city skyline, created with physic editor, and a war plane.

How could I create a crater in this physic shape when my plane drops the bomb? In the event that another bomb had to be thrown in the same spot should go through the hole before tapping the remaining form and explode again.

 I have no idea how to do it.

Is it an endless scroller? If so, how can you drop two bombs at the same place?

Can you explain your game a bit more descriptively? Probably quote some existing games from which your game design has been inspired so that I can understand precisely what you’re trying to do.

Let’s make it easier. Let’s say I have a single screen. There is a ufo that moves left and right in this one screen. At the bottom there is a strip of land, and a tunnel under the ground where there are enemy soldiers who must hit. This is done by hitting the ground with bombs. Each explosion removes a piece of land, it must throw several bombs at the same point for discovering the tunnel. The ground then is a physical display shape object that contains a texture image. There is a system for removing from that physical display object the explosion area?

Sorry for Google Translate.

4ofZxj.png

Good, detailed description. Google translate did just fine. :slight_smile:

I don’t have an efficient solution yet. I will let you know as soon as I think of something.

ok :slight_smile:

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 –

  1. Create a background image.

  2. Place a ground image on top of the background.

  3. 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 –

  1. Create an absolutely plain background image with a solid color. You can do this using display.newRect().

  2. Place a ground image on top of the background at a suitable position.

  3. 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.

  4. 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 –

  1. 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).

  2. 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!

Sorry for the delay in response, but I have tried to better understand the significance of your answer. What embarrasses me is step 2 in Collision Detection. How could I implement this in a remake of qbasic gorillas? Another game I’m working on, where the banana thrown by gorila pit buildings of various height. I’m trying to find a solution but it is not easy. It would be possible to overlap sensors over physical object and make that the “bullet” warn passing through the sensor ignoring what beneath? A sensor with circular form with the color of the background as explosion hole.

Is it an endless scroller? If so, how can you drop two bombs at the same place?

Can you explain your game a bit more descriptively? Probably quote some existing games from which your game design has been inspired so that I can understand precisely what you’re trying to do.

Let’s make it easier. Let’s say I have a single screen. There is a ufo that moves left and right in this one screen. At the bottom there is a strip of land, and a tunnel under the ground where there are enemy soldiers who must hit. This is done by hitting the ground with bombs. Each explosion removes a piece of land, it must throw several bombs at the same point for discovering the tunnel. The ground then is a physical display shape object that contains a texture image. There is a system for removing from that physical display object the explosion area?

Sorry for Google Translate.

4ofZxj.png

Good, detailed description. Google translate did just fine. :slight_smile:

I don’t have an efficient solution yet. I will let you know as soon as I think of something.

ok :slight_smile:

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 –

  1. Create a background image.

  2. Place a ground image on top of the background.

  3. 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 –

  1. Create an absolutely plain background image with a solid color. You can do this using display.newRect().

  2. Place a ground image on top of the background at a suitable position.

  3. 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.

  4. 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 –

  1. 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).

  2. 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!

Sorry for the delay in response, but I have tried to better understand the significance of your answer. What embarrasses me is step 2 in Collision Detection. How could I implement this in a remake of qbasic gorillas? Another game I’m working on, where the banana thrown by gorila pit buildings of various height. I’m trying to find a solution but it is not easy. It would be possible to overlap sensors over physical object and make that the “bullet” warn passing through the sensor ignoring what beneath? A sensor with circular form with the color of the background as explosion hole.

Hi again. Now that Corona is free, can I use object.fill.blendMode and graphics.newOutline() for craters? If yes, I also don’t understand how subtract a shape to a physic body with this method. Could you explain me this way ?

Hello,
Well, you can’t just easily “subtract” a random part of a physics body. You would need to determine the new shape of the body, remove the current body, and apply a new body which has the “crater” part removed. Perhaps the following guide will help:

https://docs.coronalabs.com/guide/physics/physicsBodies/index.html

Brent

Could I use display.colorSample() during the bomb fall or performance will be too bad?

Yes, it will be too resource intensive.

I really need a simple idea to make this, or to give illusion of it. These solution are too hard for me now. In 1980 gorillas game, I think the solution was check color difference.

OpenGL isn’t pixel based, its texture based. Pixel operations are very expensive to do.  Why don’t you add an invisible half circle the size of the crater, and a few pixels above the top of the ground and give it a collision test that would allow you some further control. 

Rob

Hi again. Now that Corona is free, can I use object.fill.blendMode and graphics.newOutline() for craters? If yes, I also don’t understand how subtract a shape to a physic body with this method. Could you explain me this way ?