HTML and CSS Reference
In-Depth Information
5. Loop though playerMissiles and check against the saucers , and then loop through
the saucers to check against the player .
6. When all the collision-detection routines are complete, reloop through each object
array (backward this time) and remove all the objects with true as a hit attribute.
We have used both methods—and variations—on each. While the second method is
a little cleaner, this final loop through all of the objects might add more processor
overhead when dealing with a large number of objects. We will leave the implementa-
tion of this second method to you as an exercise, in case you wish to test it.
The Geo Blaster Basic Full Source
Example 8-12 shows the entire set of code for our game. You can download this and
the entire set of example files from the topic's website.
Example 8-12. The Geo Blaster Basic full source listing
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Geo Blaster Basic Game</title>
<script type="text/javascript">
window.addEventListener('load', eventWindowLoaded, false);
function eventWindowLoaded() {
canvasApp();
}
function canvasApp(){
var theCanvas = document.getElementById("canvas");
if (!theCanvas || !theCanvas.getContext) {
return;
}
var context = theCanvas.getContext("2d");
if (!context) {
return;
}
//application states
const GAME_STATE_TITLE = 0;
const GAME_STATE_NEW_GAME = 1;
const GAME_STATE_NEW_LEVEL = 2;
const GAME_STATE_PLAYER_START = 3;
const GAME_STATE_PLAY_LEVEL = 4;
const GAME_STATE_PLAYER_DIE = 5;
const GAME_STATE_GAME_OVER = 6;
var currentGameState = 0;
var currentGameStateFunction = null;
Search WWH ::




Custom Search