Copy link to clipboard
Copied
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;
}
}
}
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now