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

How to limit the number of movie clips on stage?

New Here ,
Nov 26, 2013 Nov 26, 2013

I am making a game where tempEnemy in an array of enemies gets made on random. Every time the player advances a level, more insects appear. This is how I want it to be, but when the user is high on a level, too many enemies get made that are impossible for the user to kill. How can I limit the number of enemies being displayed on stage, but not hinder the randomness of the enemy production?


function makeEnemies():void
{
   
var chance:Number = Math.floor(Math.random() * 150);
   
if (chance <=  + level)
   
{

        tempEnemy
= new Enemy();
       
//Math.random(); gets a random number from 0.0-1.0
        tempEnemy
.x = Math.round(Math.random() * 550);
        addChild
(tempEnemy);
        enemies
.push(tempEnemy);

        tempEnemy
.speed = enemyBaseSpeed + ((level - 1) * speedLevelInc);
        
if (tempEnemy.speed > MAX_SPEED)
        
{
        tempEnemy
.speed = MAX_SPEED;

       
}


   
}

}

TOPICS
ActionScript
289
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 ,
Nov 27, 2013 Nov 27, 2013
LATEST

Keep a total count of the enemies that are present versus whatever maximum is currently allowed for a level and do not produce any more than the difference between the maximum and the current number of them.

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