Running the code through jslint.com showed that the script had become wild and wooly. Several parts of it have been refactored to bring things back under control.
The addPirates method is now called managePirates, which in turn calls addPirates and addAsteroids
The pirate ships themselves are also obtained now using an object oriented technique, which is more in keeping towards the OO nature of the game.
Before:
Code: Select all
allPirates = system.shipsWithPrimaryRole("hardpirate", player.ship, 60E3);
function newPirates(entity) {return ((clock.absoluteSeconds - entity.spawnTime) < 5)}; // remove old pirates from list.
pirates = allPirates.filter(newPirates);
Code: Select all
pirates = system
.shipsWithPrimaryRole("hardpirate", player.ship, 60E3)
.filter(function newPirates(entity) {
// remove old pirates from list.
return (clock.absoluteSeconds - entity.spawnTime) < 5;
}
);