Game Development Reference
In-Depth Information
break mines;
break projectiles;
}
}
if (circleCheck(player.point.x, tempMine.point.x, player.point.y,
tempMine.point.y, 12, 12)) {
dispatchEvent(new CustomEventSound(CustomEventSound.PLAY_SOUND,
Main.SOUND_MINE_EXPLODE, false, 0, 8, 1));
createExplode(tempMine.x+16, tempMine.y+16, particleManager.
particlesPerExplode*frameRateMultiplier);
tempMine=null;
mineManager.mines.splice(mineCtr, 1);
score += 5 * level;
//trace("hit");
if (!player.shieldRender) {
//trace("start shield");
shield--;
if (shield < 0) {
shield = 0;
gameOver = true;
}else {
dispatchEvent(new CustomEventSound(CustomEventSound.PLAY_SOUND,
Main.SOUND_PLAYER_HIT, false, 0, 8, 1));
player.shieldRender = true;
player.shieldCount = 0;
}
}else {
//trace("shield already started");
}
}
}
}
Let's now step through what's happening in the preceding code:
1.
First, we loop though all of the mines and check them against all of the projectiles with
a circle-to-circle mathematical check. We do this, because they are roughly circle
shaped. They are removed if a hit occurs, and the player's score is updated. The
particles and projectiles are placed back in their respective pools for reuse.
2.
The player ship and the mines are checked for collisions using BitmapData pixel-
perfect collisions. We use this type of collision detection because the player's ship is a
triangle and the circle-to-circle check is far too inaccurate.
3.
If the player's ship is hit by a Mine instance, its shield is displayed for a few frame ticks.
If the player.shieldCount variable is less than 1 , the gameOver Boolean is set to true .
Search WWH ::




Custom Search