How do I make a plane drop a bomb

0 favourites
  • 7 posts
From the Asset Store
Bomb Box
$3 USD
Game inspired by the classic bomberman game, with a 3D footprint!
  • I'm just starting out and I'm getting there but I have hit a brick wall with this.

    I have a plane (enemy) flying across the screen every 3 seconds. His speed and angle are random as is where he pops out. His direction is always left to right. Because his speed is random you can sometimes have two planes on screen at the same time, but that is fine with me.

    I have achieved all of the above by reading/watching tutorials and forum posts. If I can't find an example of what I want to happen, I'm kind of lost. I am not at the stage where I can work without an example to go from. I thought my problem would be simple to solve, but in fact I can find no example of this type of action.

    What I am looking for is that this plane, at a given point (say, 300 pix from left edge) drops a bomb which then falls vertically towards the ground where my hero has to dodge it. I thought such an example would be simple to find but the nearest I have found is a mouse or touch action to spawn a bomb, which works, but my first problem is when I try to set a condition like when plane is 300 pix from X axis, spawn bomb nothing ever appears. This is confirmed when I run it in debug. Bomb is always (0).

    My second problem is that even when I use a mouse or touch action to spawn a bomb, my bomb appears but ALWAYS goes horizontally to the right, whatever bullet angle I set it to (0,90,180 or 270). It's a bomb, not a missile, I need it to fall.

    I'm clearly trying to run before I can walk, and I'm no programmer but Construct 2, which I have bought, says you don't have to be a programmer so I kind of hoped this wouldn't be the nightmare it seems to have become. Can somebody point me to a tutorial or example script which has a flying enemy dropping a single bomb and then disappearing?

  • Here is a super cheesy version I threw together to get you started in the right direction.

    https://drive.google.com/open?id=0Bx-ufu2WID53ZDl1VFpGdk05ZGs (click the download arrow in the upper right corner of screen)

  • That is EXACTLY what I want to happen. Thank you so much! It is super cheesy and super brilliant!

    I can see that there are a whole bunch of concepts that I don't yet understand and as I dissect your work I will hopefully learn why my effort was a dismal failure

  • Glad I could help. If you wanted to make the planes appear like they are actually trying to drop bombs on the player (or if you had a different kind of plane that came in periodically that was more accurate) you could remove the timer object and instead make the condition if plane.X = player.x then spawn bomb (super accurate). If you wanted your bombs to have more realistic falls.. ie travel forward slightly with planes momentum you could play around with the bullet behaviors bullet drop and gravity to get an arc style fall.

    I just had the bomb spawn and let gravity pull it down in my example. If instead you gave the bullet (bomb) a low speed on creation and tweaked the strength of gravity you would get a nice realistic drop.

    Lots of places to go from here.

  • Hi Chris,

    Once again, thank you for the demo you put up for me - it's incredibly helpful. I try to dissect everything to help the little grey cells... so I hope you don't mind if I pick your brains on this? I have lack of experience, lack of understanding of the principles which I hope to redress

    Here's your code:

    Here are my questions:

    1. Line 1 is empty? Not sure if that's even an issue but I mention it because I noticed it. I don't seem to be able to produce an empty line, lol

    2. On line 2 you have "when bomber is NOT onscreen" without an event. I don't understand what that does but it prevented me from setting the bomber behaviour "Destroy Outside Layout". Removing your line allowed me to destroy outside layout (memory consumption).

    3. All of the object events below line 2 have a little green arrow. What does this denote? What is its purpose?

    I had a whole bunch more but have resolved them all by remembering to look at the behaviours attributed to objects before engaging mouth!

    I've programmed a bit in basic and javascript in my time but this is visually object-oriented, and it's not always possible to follow the path of code as displayed in Construct 2 without explanation.

    Thank you very much in advance for your replies!

  • 1. I didn't add the second event condition bomber X on screen by right clicking and choosing add new condition. I added it by creating a new event, highlighting it and cut/pasting it into the original event... this left the new one empty and I forgot to delete it. It is simply that, an empty event with no value or function and should have been deleted. I didn't do it that way for any specific reason though either way is fine to add extra conditions to events.

    2. The second condition means that every 3 seconds AND a bomber object is not on screen. This simply keeps multiple bombers from being on screen at once. If you want multiple bombers then you don't need it.

    As for destroying off screen, this is an easy fix anyways. I usually use a large sprite I call "Destroyer" just off screen and use an on overlap with destroyer.. destroy and set all objects leaving the screen into a family that it destroys. Keeps me from having to condition each to destroy off screen.

    Lastly, I threw this code together quickly without even worrying about flow.. I just kept running it and as long as it worked I moved on... yes you would want to use a better top to bottom flow and use groups to make it flow better in a big project.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 1. ... this left the new one empty and I forgot to delete it. It is simply that, an empty event with no value or function and should have been deleted. I didn't do it that way for any specific reason though either way is fine to add extra conditions to events.

    Now I understand! Thanks

    2. I usually use a large sprite I call "Destroyer" just off screen and use an on overlap with destroyer.. destroy and set all objects leaving the screen into a family that it destroys. Keeps me from having to condition each to destroy off screen.

    What a brilliant idea - I wouldn't have thought of that. Thinking out of the box

    Lastly, I threw this code together quickly without even worrying about flow...

    Your little capx did more for me than reading a ton of tutorials. However "rough" it was, I learned loads from it so thank you very much!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)