Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is that you don't create new enemies from time to time, but just shift the same enemy further away on its explosion (i.e. call <code>recycleEnemy</code> method). This single enemy is spawned only once: <code>spawnEnemy</code> function is called in <code>init</code> method only with argument <code>1</code>.</p> <p>You should rework enemy spawning algorithm. Below is a pretty good sample, which increases enemy spawning rate:</p> <ol> <li><p>Remove <code>number</code> argument from <code>spawnEnemy</code> function: spawn only one enemy</p></li> <li><p>Change <code>Enemy.prototype.recycleEnemy</code> function to remove <code>this</code> from <code>enemies</code>. Be cautious: if you'll call this function inside a loop by <code>enemies</code>, you will need to decrease counter to make sure that you won't skip next enemy: <code>--i</code></p></li> <li><p>Add a <code>function getSpawnCooldown() { return 100 / spawnAmount; }</code> (100 is approximate constant, you can variate it to change initial spawning rate)</p></li> <li><p>Add a variable <code>time</code> which means the number of effective <code>Loop</code> calls from the beginning, defaults to 0</p></li> <li><p>Add a variable <code>lastSpawnTime</code>, set it to 0</p></li> <li><p>Inside <code>if</code> block of <code>Loop</code> function, add lines:</p> <ol> <li><p><code>++time</code></p></li> <li><p><code>if (time &gt;= lastSpawnTime + getSpawnCooldown()) spawnEnemy();</code></p></li> </ol></li> <li><p>In <code>spawnEnemy</code> function, add a line: <code>lastSpawnTime += getSpawnCooldown()</code></p></li> </ol> <p>Generally, you should better structurize your code. At least, split it to several js files which are responsible for different parts of your application.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload