Game Development Reference
In-Depth Information
if (tempEnemy.y > gameHeight-tempShip.height-tempEnemy.height-shipYPadding) {
enemyPoint = new Point(tempEnemy.x, tempEnemy.y);
if (tempShip.image.bitmapData.hitTest(
sPoint,255,tempEnemy.image.bitmapData,enemyPoint)) {
Figure 5-10. Testing enemy planes only when they reach the y location of the ships
If we detect a collision, we do a few things differently from previous collisions. First, we remove
the Enemy plane. Unlike Flak , which stays around until its animation sequence is complete, the
Enemy plane blows up along with the Ship . Second, we dispatch CustomEventSound.PLAY_SOUND to
play Main.SOUND_EXPLODE_SHIP . Next, we make three Explosion objects. This is simply to drive
home to the player that a Ship has been destroyed. One Explosion would have made it seem like
the Enemy was destroyed, and that would not be enough of a visual cue for the player. We next
remove the Ship by calling removeItemFromArray(), decrement the ships variable and dispatch
an event to the ScoreBoard telling it to update the text. Finally, we call break ship . Again, this is
done because we have removed the Ship from shipArray , and we do not need to test it again
against any more Enemy planes.
removeItemFromArray(tempEnemy,enemyArray);
dispatchEvent( new CustomEventSound(CustomEventSound.PLAY_SOUND,
Main.SOUND_EXPLODE_SHIP,false,1,0,1));
makeExplosion(tempEnemy.x,tempEnemy.y);
makeExplosion(tempShip.x+25,tempShip.y+5);
makeExplosion(tempShip.x+tempShip.width-40,tempShip.y+10);
makeExplosion(tempShip.x+tempShip.width/2,tempShip.y+3);
removeItemFromArray(tempShip,shipArray);
ships--;
dispatchEvent(new CustomEventScoreBoardUpdate(
CustomEventScoreBoardUpdate.UPDATE_TEXT,Main.SCORE_BOARD_SHIPS,
String(ships)));
break ship;
}
}
}
}
}
Search WWH ::




Custom Search