Wednesday 15 September 2010

javascript - Canvas game increase enemies spawn -


I have a game I'm making:

What do I want to be able to do

  Function loop () {if (playbacking =) This part works in my loop function:  

But when I wake up, = true) {updateLevel (); // This level updates but it calls every frame which can be spoiled Player1.draw (); DrawAllEnemies (); UpdateStats (); RequestAnimFrame (Loop); }

Update level function:

  function update level () {if (Player1.enemiesKilled & lt; 3) {level = 1; } And if (player 1. animated & gt; 3 & amp; amp; player1; emo & lt; = 9) {level = 2; } And if (player 1. animated> 9 & amp; amp; player1; emo & lt; = 18} {level = 3; } And if (Player 1. Enniskel> 18 & amp; Player1.enemiesKilled & lt; = 38) {level = 4; } And if (Player 1. Enniskel> 38 & amp; amp; player 1. Emotions & lt; = 70) {level = 5; S} else if (Player1.ememiesKilled> 120) {level = 6; } If (level == 1) {spawnAmount = 1; } And if (level == 2) {spawnAmount = 2; } And if (level == 3) {spawnAmount = 3; } And if (level == 4) {spawnAmount = 4; } And if (level == 5) {spawnAmount = 5; } And if (level == 6) {spawnAmount = 6; Spanish enemy function:  
  function spawn anime (number) // total enemy starts with 0 and every time you add to the array (for var x = 0; x & lt; Number; x ++) {Enemy [Enemy. Length] = new enemy (); }}   

My init:

  function init () {spawnEnemy (spawnAmount); DrawMenu (); SndIntro.play (); Document.addEventListener ('click', mouse click, wrong); }   

I tried to add: Span anime (spawn amount); After I change the amount of egg in the updated level, but as it is called every frame, after that hundreds of enemies fly near me. How can I solve this problem?

If I try something like hundreds of enemies, then I believe because it is called every frame:

  if (level == 1) {spawn amounts = 1; SpawnEnemy (spawnAmount); }    

If your intention is to increase the egg rate at all levels, then I want to suggest that you start a spawnRate beforehand. Let spawnRate represent the number of game updates among enemy spawns. Every time an enemy is born, reduce another variable ( spawnRateCountdown ), unless they reach the variable, then an enemy is born. Reset the Variable from spawnRate Rinse and repeat.

  spawnRate = 60; / * An enemy every 60 updates * / SpawnRateCountdown = spawnRate; Function Update Loop () {spawnRateCountdown--; If (spawn rate countdown == 0) {spawnRateCountdown = spawnRate; SpawnEnemy (); }}   

After this, you can just update your spawnRate variable as you are seeing.

No comments:

Post a Comment