HTML and CSS Reference
In-Depth Information
Controlling enemy waves
In this task, we add a leveling system to the game. We will use a dedicated object to manage
diferent combinaions of enemies and their spawning frequency.
Prepare for lift off
In this task, we will create a new file for controlling the enemy waves. Let's call it waves.js
and include it in the HTML:
<script src="scripts/waves.js"></script>
Engage thrusters
Let's work on leveling:
Note that we will show only three waves here. The three waves in the
topic are presented for demonstraion purposes. In reality, we have much
more waves that are declared. They are just diferent combinaions with
different amounts. So, we don't want to paste the whole waves' data
here with duplicated content. Please check the code example for the full
waves' data code.
1. First, we will work on the waves.js file. The waves object is simply a literal object
because we only want one instance to manage all of the leveling:
// controlling waves
;(function(game, cjs){
game.waves = {};
game.waves.nextWave = 0;
game.waves.isActive = false;
game.waves.enemySummonOrders = ['EnemyDummy', 'Enemy1',
'Enemy2', 'Enemy3', 'Boss', 'Boss2'];
game.waves.data = [
{ // wave 1
'EnemyDummy': 1, // summon 1 EnemyDummy during wave
frequency: 10
},
{ // wave 2
'EnemyDummy': 8, // summon 8 EnemyDummy, one by one
'Enemy1' : 5, // summon 5 Enemy1 after EnemyDummy
'Enemy2' : 5,
'Boss' : 2,
 
Search WWH ::




Custom Search