var centerTile = gameControl.getObjectById(16); var explodingTileIds = shuffle([10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]); var numExplodingTiles = 15; var explodingTilesCount = 0;

var turretsDestroyed = 0; var speed = 0.05001; var timer = createTimer(30);

function setBossSpeed(vx) { for (var id = 10; id <= 30; id++) { gameControl.getObjectById(id).setSpeed(vx, 0); } }

function init() { // This is a hack to prevent the turrets from shooting themselves // in case the ship is flying above the boss. for (var x = 0; x < 40; x++) { gameControl.getLevel().getPlayGround().getMap().markAsForegroundTile(x, 4); }

setBossSpeed(-speed); }

function update(elapsedTime) { if (centerTile == null) return;

if (centerTile.getX() < 96) { setBossSpeed(speed); } if (centerTile.getX() > 640-96) { setBossSpeed(-speed); }

if (turretsDestroyed == 3 && explodingTilesCount < numExplodingTiles) { if (timer.action(elapsedTime)) { gameControl.getObjectById(explodingTileIds[explodingTilesCount++]).destroy(); timer.refresh(); } } }

function onDestroyed(object) { switch (object.getID()) { case 28: turretsDestroyed++; gameControl.getObjectById(25).destroy(); break; case 29: turretsDestroyed++; gameControl.getObjectById(26).destroy(); break; case 30: turretsDestroyed++; gameControl.getObjectById(27).destroy(); break; }

if (turretsDestroyed == 3) { addLandOnPlatformObjective(2); } }

function onObjectiveReached() { gameControl.finish(); }