HTML and CSS Reference
In-Depth Information
reload time is checked, and only after the Enemy reloads its weapons does it check against a randomly gener-
ated number to see if it should fire .
If you load up the game, you should have enemies firing missiles as expected; however, all the enemies will
be firing just one missile at the same frequency.
To adjust the frequency of firing, you need to modify the enemy blueprints at the top of game.js . Modify
the enemies array to have the ltr and wiggle enemies each fire two missiles at a time (matching their
sprite image) and reduce the firePercentage of the straight and wiggle enemies to 0.001 to pre-
vent them from firing too many missiles at once, as shown here:
var enemies = {
straight: { x: 0, y: -50, sprite: 'enemy_ship', health: 10,
E: 100 , firePercentage: 0.001 },
ltr: { x: 0, y: -100, sprite: 'enemy_purple', health: 10,
B: 75, C: 1, E: 100, missiles: 2 },
circle: { x: 250, y: -50, sprite: 'enemy_circle', health: 10,
A: 0, B: -100, C: 1, E: 20,
F: 100, G: 1, H: Math.PI/2 },
wiggle: { x: 100, y: -50, sprite: 'enemy_bee', health: 20,
B: 50, C: 4, E: 100, firePercentage: 0.001,
missiles: 2 },
step: { x: 0, y: -50, sprite: 'enemy_circle', health: 10,
B: 150, C: 1.2, E: 75 }
With that, reload the game, and you should have a playable game with active enemies. You can also play the
game at .
It's been a whirlwind in the first three chapters, having gone from making the first few marks onto the canvas to
building a fully functional mobile space shooter. As a demo game, Alien Inva sion isn't bad, but as a full-fledged
space shooter there's still lots that could be done: high scores, ship animations, sounds, longer and varied levels,
new enemies, and boss fights. The good news is that the code on Github at
vasion can be forked and enhanced. If you've been following along, you've stepped through every line of the
game and should know it inside and out. Check the readme file for what others have done.
Search WWH ::

Custom Search