Online Book Reader

Home Category

HTML5 Canvas [178]

By Root 6510 0

case GAME_STATE_PLAYER_START:

currentGameStateFunction = gameStatePlayerStart;

break;

case GAME_STATE_PLAY_LEVEL:

currentGameStateFunction = gameStatePlayLevel;

break;

case GAME_STATE_PLAYER_DIE:

currentGameStateFunction = gameStatePlayerDie;

break;

case GAME_STATE_GAME_OVER:

currentGameStateFunction = gameStateGameOver;

break;

}

}

function gameStateWaitForLoad(){

//do nothing while loading events occur

console.log("doing nothing...")

}

function createObjectPools(){

for (var ctr=0;ctrvar newParticle = {};

particlePool.push(newParticle)

}

console.log("particlePool=" + particlePool.length)

}

function gameStateInit() {

createObjectPools();

loadCount = 0;

itemsToLoad = 16;

explodeSound = document.createElement("audio");

document.body.appendChild(explodeSound);

audioType = supportedAudioFormat(explodeSound);

explodeSound.setAttribute("src", "explode1." + audioType);

explodeSound.addEventListener("canplaythrough",itemLoaded,false);

explodeSound2 = document.createElement("audio");

document.body.appendChild(explodeSound2);

explodeSound2.setAttribute("src", "explode1." + audioType);

explodeSound2.addEventListener("canplaythrough",itemLoaded,false);

explodeSound3 = document.createElement("audio");

document.body.appendChild(explodeSound3);

explodeSound3.setAttribute("src", "explode1." + audioType);

explodeSound3.addEventListener("canplaythrough",itemLoaded,false);

shootSound = document.createElement("audio");

audioType = supportedAudioFormat(shootSound);

document.body.appendChild(shootSound);

shootSound.setAttribute("src", "shoot1." + audioType);

shootSound.addEventListener("canplaythrough",itemLoaded,false);

shootSound2 = document.createElement("audio");

document.body.appendChild(shootSound2);

shootSound2.setAttribute("src", "shoot1." + audioType);

shootSound2.addEventListener("canplaythrough",itemLoaded,false);

shootSound3 = document.createElement("audio");

document.body.appendChild(shootSound3);

shootSound3.setAttribute("src", "shoot1." + audioType);

shootSound3.addEventListener("canplaythrough",itemLoaded,false);

saucershootSound = document.createElement("audio");

audioType = supportedAudioFormat(saucershootSound);

document.body.appendChild(saucershootSound);

saucershootSound.setAttribute("src", "saucershoot." + audioType);

saucershootSound.addEventListener("canplaythrough",itemLoaded,false);

saucershootSound2 = document.createElement("audio");

document.body.appendChild(saucershootSound2);

saucershootSound2.setAttribute("src", "saucershoot." + audioType);

saucershootSound2.addEventListener("canplaythrough",itemLoaded,false);

saucershootSound3 = document.createElement("audio");

document.body.appendChild(saucershootSound3);

saucershootSound3.setAttribute("src", "saucershoot." + audioType);

saucershootSound3.addEventListener("canplaythrough",itemLoaded,false);

shipTiles = new Image();

shipTiles.src = "ship_tiles.png";

shipTiles.onload = itemLoaded;

shipTiles2 = new Image();

shipTiles2.src = "ship_tiles2.png";

shipTiles2.onload = itemLoaded;

saucerTiles= new Image();

saucerTiles.src = "saucer.png";

saucerTiles.onload = itemLoaded;

largeRockTiles = new Image();

largeRockTiles.src = "largerocks.png";

largeRockTiles.onload = itemLoaded;

mediumRockTiles = new Image();

mediumRockTiles.src = "mediumrocks.png";

mediumRockTiles.onload = itemLoaded;

smallRockTiles = new Image();

smallRockTiles.src = "smallrocks.png";

smallRockTiles.onload = itemLoaded;

particleTiles = new Image();

particleTiles.src = "parts.png";

particleTiles.onload = itemLoaded;

switchGameState(GAME_STATE_WAIT_FOR_LOAD);

}

function gameStateTitle() {

if (titleStarted !=true){

fillBackground();

setTextStyleTitle();

context.fillText ("Geo Blaster X-ten-d", 120, 70);

setTextStyle();

context.fillText ("Press Space To Play", 130, 140);

setTextStyleCredits();

context.fillText ("An HTML5 Example Game", 125, 200);

context.fillText ("From our upcoming HTML5 Canvas", 100, 215);

context.fillText ("book on O'Reilly

Return Main Page Previous Page Next Page

®Online Book Reader