Jump to content

Help with random enemy counter


ibb671
 Share

Recommended Posts

Hello I was hoping someone can help me. In my code I was able to generate a random number of enemies (randomEnemyNumber) from 1-4 with the number of enemies set to 0 and incrementing by 1 within a timer and its inside the update function. I wanted to kill off the enemies when the the random amount of enemies (randomEnemyNumber) generated equals to the number of enemies on screen. But i noticed randomEnemyNumber will update and the current number of enemies will keep incrementing and will not equal. Below is my current code that i have to try and fix it, but I wanted to ask if there is a better way to approach it? Thank you guys again in advance for taking the time.

               this.enemy++;
				console.log(this.enemy + "This is the current number of enemies");

				var randomEnemyNumber = this.game.rnd.integerInRange(1,4);
				console.log(randomEnemyNumber + "Current random enemy number");

				if(this.enemy==randomEnemyNumber && this.enemy<6){
					this.enemy=0;
					this.enemyGroup.forEachAlive(function(element){
						this.tweenFunction(element);//A tween that will kill the enemy onComplete
						

					},this);

				}else if(this.enemy>5){
					this.enemy=0;
					this.enemyGroup.forEachAlive(function(element){
					this.tweenFunction(element);//A tween that will kill the enemy onComplete
				},this);
					
				}

 

Below is the screen shot of console.log.

Capture.PNG

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...