Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Randomize frames

Guest
Jan 09, 2014 Jan 09, 2014

Im a highschool student making a game for my CPT using flash CS6 (Coding with action script 3).  I was wondering what the code would be for something hitting a target, and from there going to a random frame.  Each frame has a question on it. So I want it to be a different question everytime they hit the target.  So the Projectile hits the target, and a random question pops up.

Thanks for the help

Aaron

TOPICS
ActionScript
568
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 09, 2014 Jan 09, 2014

Put the frame numbers in an array and then shuffle the array so it is in random order.  Then you can just go thru the array one item at a time.  For the hitting a target aspect, look into using the hitTestObject() method.  What you would do is continuously check if there is a hit until whatever passes that would signify the end of a need to check (like the end of the journey for the missile or the missile hitting the target)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 09, 2014 Jan 09, 2014

Don't forget to remove the frame number from the array after it has been visited if you don't want to be repeatedly going to the same questions.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 09, 2014 Jan 09, 2014

Thanks for the help! I will try this

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 09, 2014 Jan 09, 2014
LATEST

You're welcome.  You do not need to remove anything from the array if you go thru it from start to finish one item at a time.  You won't repeat any frames until you finish going thru it and start at the beginning again.  When you complete the array you could shuffle it again if you like or just leave it alone and repeat.

Here is a function you can use for shuffing the array into a random order...

function shuffle(a:Array) {
    var p:int;
    var t:*;
    var ivar:int;
    for (ivar = a.length-1; ivar>=0; ivar--) {
        p=Math.floor((ivar+1)*Math.random());
        t = a[ivar];
        a[ivar] = a

;
        a

= t;
    }
}

// Usage:
shuffle(anArray);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines