Skip to main content
Known Participant
November 27, 2013
Question

How to limit the number of movie clips on stage?

  • November 27, 2013
  • 1 reply
  • 310 views

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;

       
}


   
}

}

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
November 27, 2013

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.