2.2.7 Cycle 7 - Add Boss Wave
Design
Objectives
In this cycle I aim to add another type of more difficult enemy, that moves faster and adds an extra challenge to the experience. This could be done through an enemy with more health, speed, smaller size etc.
This will add to the challenge of the game, and this will help to make it more challenging.
Usability Features
Key Variables
specialEnemies
This is the group that hold each specialEnemy
specialEnemy
This is each individual sprite in the larger group
deployEnemyShips
This is the function that deploys the enemy ships (both special and normal)
specialEnemyXSpawn
This is the variable that defines the base places for the specialEnemies to spawn at
Pseudocode
procedure create
add specialEnemies to new group
enable specialEnemies
create multiple specialEnemies as specialEnemy
check bound of specialEnemies
if specialEnemies collide with player
player takes damage
if specialEnemies collide with laser
destroy specialEnemy
end procedure
procedure deployEnemyShips
...
if switchToNewPattern == 30
run deploySpecialEnemy procedure
end procedure
procedure deploySpecialEnemy
specialEnemies exists first = false
if specialEnemy = true
add specialEnemies = specialEnemyXSpawn
Development
Outcome
function preload(){
...
game.load.image('specialEnemy', 'assets/images/newEnemyShip.gif');
...
}
function create(){
...
specialEnemies = game.add.group();
specialEnemies.enableBody = true;
game.physics.arcade.enable(specialEnemies, Phaser.Physics.ARCADE);
specialEnemies.createMultiple(100, 'specialEnemy');
specialEnemies.setAll('anchor.x', 0.5);
specialEnemies.setAll('anchor.y', 0.5);
specialEnemies.setAll('scale.x', 1.3);
specialEnemies.setAll('scale.y', 1.3);
specialEnemies.setAll('outOfBoundsKill', true);
specialEnemies.setAll('checkWorldBounds', true);
specialEnemies.setAll('angle', 180);
...
}
let spawnSpecialEnemy = false;
function deployEnemyShips() {
...
} else if (switchToNewPattern === 30) {
spawnSpecialEnemy = true;
switchXSpawn = 0;
switchToNewPattern = 0;
enemyXSpawn = 200;
ENEMY_X = 0;
deploySpecialEnemy();
}
}
}
let specialCount = 0;
let specialEnemyXSpawn = 200;
function deploySpecialEnemy() {
// Figure out how to get rid of normal enemies while special enemy is in play
if (spawnSpecialEnemy) {
let specialEnemy = specialEnemies.getFirstExists(false);
if (specialEnemy && specialCount != 3) {
specialEnemy.reset(specialEnemyXSpawn, 0);
specialEnemy.body.velocity.y = 800;
specialEnemy.body.drag.x = 0;
game.time.events.add(500, function() {
deploySpecialEnemy();
if (specialEnemyXSpawn === 200) {
specialEnemyXSpawn = 100;
} else if (specialEnemyXSpawn === 100) {
specialEnemyXSpawn = 300;
} else if (specialEnemyXSpawn === 300) {
specialEnemyXSpawn = 200;
setInterval(function() {
deployEnemyShips();
}, 5000);
}
});
}
}
}
Challenges
The most challenging part of this cycle was figuring out how to get it so that only the special ships would spawn whilst they were being deployed, and so that the normal enemy ships would stop for the duration of the special ships. I was trying to overcomplicate this to begin with, but I realised that I could just defer the function that calls new normal enemy ships by an amount of time so that it wouldn't be called, and this meant that the normal ships wouldn't spawn for the time that the special enemies were.
Testing
Evidence for testing
Tests
1
Simply load the game
The basic enemies move down the screen both randomly and also in set patterns.
As expected
2
Survive long enough to get the special enemies
The special enemies spawn in, move faster and basic enemies aren't spawned for duration.
As expected
Evidence

What next?
Next I want to add the ability to pick up health
This should enable the player to live for longer
Last updated