Online Book Reader

Home Category

HTML5 Canvas [177]

By Root 6467 0
score = 0;

var level = 0;

var extraShipAtEach = 10000;

var extraShipsEarned = 0;

var playerShips = 3;

//playfield

var xMin = 0;

var xMax = 400;

var yMin = 0;

var yMax = 400;

//score values

var bigRockScore = 50;

var medRockScore = 75;

var smlRockScore = 100;

var saucerScore = 300;

//rock scale constants

const ROCK_SCALE_LARGE = 1;

const ROCK_SCALE_MEDIUM = 2;

const ROCK_SCALE_SMALL = 3;

//create game objects and arrays

var player = {};

var rocks = [];

var saucers = [];

var playerMissiles = [];

var particles = [];

var saucerMissiles = [];

var particlePool = [];

var maxParticles = 200;

var newParticle;

var tempParticle;

//level specific

var levelRockMaxSpeedAdjust = 1;

var levelSaucerMax = 1;

var levelSaucerOccurrenceRate = 25;

var levelSaucerSpeed = 1;

var levelSaucerFireDelay = 300;

var levelSaucerFireRate = 30;

var levelSaucerMissileSpeed = 1;

//keyPresses

var keyPressList=[];

//tile sheets

var shipTiles;

var shipTiles2;

var saucerTiles;

var largeRockTiles;

var mediumRockTiles;

var smallRockTiles;

var particleTiles;

function itemLoaded(event) {

loadCount++;

//console.log("loading:" + loadCount)

if (loadCount >= itemsToLoad) {

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

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

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

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

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

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

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

saucershootSound2.removeEventListener("canplaythrough",itemLoaded,

false);

saucershootSound3.removeEventListener("canplaythrough",itemLoaded,

false);

soundPool.push({name:"explode1", element:explodeSound, played:false});

soundPool.push({name:"explode1", element:explodeSound2, played:false});

soundPool.push({name:"explode1", element:explodeSound3, played:false});

soundPool.push({name:"shoot1", element:shootSound, played:false});

soundPool.push({name:"shoot1", element:shootSound2, played:false});

soundPool.push({name:"shoot1", element:shootSound3, played:false});

soundPool.push({name:"saucershoot", element:saucershootSound,

played:false});

soundPool.push({name:"saucershoot", element:saucershootSound2,

played:false});

soundPool.push({name:"saucershoot", element:saucershootSound3,

played:false});

switchGameState(GAME_STATE_TITLE)

}

}

function playSound(sound,volume) {

ConsoleLog.log("play sound" + sound);

var soundFound = false;

var soundIndex = 0;

var tempSound;

if (soundPool.length> 0) {

while (!soundFound && soundIndex < soundPool.length) {

var tSound = soundPool[soundIndex];

if ((tSound.element.ended || !tSound.played) && tSound.name == sound) {

soundFound = true;

tSound.played = true;

} else {

soundIndex++;

}

}

} if (soundFound) {

ConsoleLog.log("sound found");

tempSound = soundPool[soundIndex].element;

//tempSound.setAttribute("src", sound + "." + audioType);

//tempSound.loop = false;

//tempSound.volume = volume;

tempSound.play();

} else if (soundPool.length < MAX_SOUNDS){

ConsoleLog.log("sound not found");

tempSound = document.createElement("audio");

tempSound.setAttribute("src", sound + "." + audioType);

tempSound.volume = volume;

tempSound.play();

soundPool.push({name:sound, element:tempSound, type:audioType,

played:true});

}

}

function runGame(){

currentGameStateFunction();

}

function switchGameState(newState) {

currentGameState = newState;

switch (currentGameState) {

case GAME_STATE_INIT:

currentGameStateFunction = gameStateInit;

break;

case GAME_STATE_WAIT_FOR_LOAD:

currentGameStateFunction = gameStateWaitForLoad;

break;

case GAME_STATE_TITLE:

currentGameStateFunction = gameStateTitle;

break;

case GAME_STATE_NEW_GAME:

currentGameStateFunction = gameStateNewGame;

break;

case GAME_STATE_NEW_LEVEL:

currentGameStateFunction = gameStateNewLevel;

break;

Return Main Page Previous Page Next Page

®Online Book Reader