A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Random Shots

Hybrid View

  1. #1
    Senior Member TheLostGuru's Avatar
    Join Date
    Aug 2004
    Location
    I live on this webpage...
    Posts
    784

    Random Shots

    I have these airplanes that are attached to the screen on using attachMovie("aircraft", "aircraft" + p, p);
    you get the picture. They fly across the screen from right to left with a random speed and y position. What I am trying to randomly get bombs to drop from the planes. Right now all I have been able to do is randomly drop bombs from the corner of the screen. Does anyone know of a good way to do this? I'm open to any suggestion.
    "If I have seen further it is by standing on the shoulders of giants." Isaac Newton
    ------------------------------------------------------------------------------

  2. #2
    Impressive Click swcAndrew's Avatar
    Join Date
    Oct 2004
    Location
    USA
    Posts
    468
    why don't you attach the random code to the airplane. Then set the x and y position to that of the plane at the time.
    Andrew Webster
    Impressive Click

  3. #3
    Senior Member DayDream's Avatar
    Join Date
    Aug 2000
    Location
    Belgrade/ Serbia
    Posts
    370
    or simply get the _x of the plane dropping the bomb and use it as the starting point for the bomb when you attach it...

  4. #4
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    1,361
    This might help, if its what you want...
    code:

    //Do this when the game loads
    createEmptyMovieClip("airplanes");
    createEmptyMovieClip("bombs");
    maxtime=30

    //Do this when your creating the movies
    airplanes.attachMovie("aircraft", "aircraft" + p, p);
    airplanes["aircraft" + p].current=0
    airplanes["aircraft" + p].interval=random(maxtime)
    p++
    //Do this everyframe

    for(plane in airplanes){
    airplanes[plane]._x+=xspeed
    airplanes[plane].current++
    if(airplanes[plane].current==airplanes[plane].interval){
    bombs.attachMovie("bomb", "bomb" + p, p);
    bombs["bomb"+p]._x=airplanes[plane]._x
    bombs["bomb"+p]._y=airplanes[plane]._y
    airplanes[plane].interval=random(maxtime) }
    }

    for(bomb in bombs){
    bombs[bomb]._y+=bombyspeed
    //Do whatever actions bombs do
    }



    I think that should all work, if you need any clarfication just ask!

    Hope that Helps!

    Edit:Code Change
    Last edited by UnknownGuy; 02-23-2005 at 08:43 AM.

  5. #5
    Senior Member TheLostGuru's Avatar
    Join Date
    Aug 2004
    Location
    I live on this webpage...
    Posts
    784
    I think I might work with the code you gave me unknownguy. Where you say use this when you movie loads and stuff, does this code all go on the same frame? Does it go on a frame or a movieclip? Also in your code you switched from aircraft to plane. Did you mean to? Also where does P get increased? Should I put these things in functions?
    Last edited by TheLostGuru; 02-23-2005 at 12:32 AM.
    "If I have seen further it is by standing on the shoulders of giants." Isaac Newton
    ------------------------------------------------------------------------------

  6. #6
    Senior Member TheLostGuru's Avatar
    Join Date
    Aug 2004
    Location
    I live on this webpage...
    Posts
    784
    Alright, I give in... I really didn't want to end up posting my fla, but I'm sick of this bomb not dropping. My bomb dropping code is in my aircraft mc. Any help would be appreciated.
    "If I have seen further it is by standing on the shoulders of giants." Isaac Newton
    ------------------------------------------------------------------------------

  7. #7
    Senior Member TheLostGuru's Avatar
    Join Date
    Aug 2004
    Location
    I live on this webpage...
    Posts
    784
    fla
    "If I have seen further it is by standing on the shoulders of giants." Isaac Newton
    ------------------------------------------------------------------------------

  8. #8
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    1,361
    When I say when the movie loads I mean, it should just be executed once, while the next piece of code should be done when you create the fighter, and the last everyframe. It dooesn't matter if its in a frame or a movieclip(you might have to use root to get out of the movie).
    And no, its doesn't matter I switched from aircraft to plane, plane is a variable and holds data like aircraft1, aircraft2 etc...
    I forgot to increase p, so I've edited the code so it does.

    I don't have time to look at the .fla, but hopefully I will tonight.

    Hopefully that clarifies a few things...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center