HTML5 Canvas [179]
context.fillText ("Game Code - Jeff Fulton", 130, 260);
context.fillText ("Sound Manager - Steve Fulton", 120, 275);
titleStarted = true;
}else{
//wait for space key click
if (keyPressList[32]==true){
ConsoleLog.log("space pressed");
switchGameState(GAME_STATE_NEW_GAME);
titleStarted = false;
}
}
}
function gameStateNewGame(){
ConsoleLog.log("gameStateNewGame")
//set up new game
level = 0;
score = 0;
playerShips = 3;
player.maxVelocity = 5;
player.width = 32;
player.height = 32;
player.halfWidth = 16;
player.halfHeight = 16;
player.hitWidth = 24;
player.hitHeight = 24;
player.rotationalVelocity = 10; //how many degrees to turn the ship
player.thrustAcceleration = .05;
player.missileFrameDelay = 5;
player.thrust = false;
player.alpha = 1;
player.rotation = 0;
player.x = 0;
player.y = 0;
fillBackground();
renderScoreBoard();
switchGameState(GAME_STATE_NEW_LEVEL)
}
function gameStateNewLevel(){
rocks = [];
saucers = [];
playerMissiles = [];
particles = [];
saucerMissiles = [];
level++;
levelRockMaxSpeedAdjust = level*.25;
if (levelRockMaxSpeedAdjust > 3){
levelRockMaxSpeed = 3;
}
levelSaucerMax = 1+Math.floor(level/10);
if (levelSaucerMax > 5){
levelSaucerMax = 5;
}
levelSaucerOccurrenceRate = 10+3*level;
if (levelSaucerOccurrenceRate > 35){
levelSaucerOccurrenceRate = 35;
}
levelSaucerSpeed = 1+.5*level;
if (levelSaucerSpeed>5){
levelSaucerSpeed = 5;
}
levelSaucerFireDelay = 120-10*level;
if (levelSaucerFireDelay<20) {
levelSaucerFireDelay = 20;
}
levelSaucerFireRate = 20 + 3*level;
if (levelSaucerFireRate<50) {
levelSaucerFireRate = 50;
}
levelSaucerMissileSpeed = 1+.2*level;
if (levelSaucerMissileSpeed > 4){
levelSaucerMissileSpeed = 4;
}
//create level rocks
for (var newRockctr=0;newRockctr newRock.scale = 1; //scale //1 = large //2 = medium //3 = small //these will be used as the divisor for the new size //50/1 = 50 //50/2 = 25 //50/3 = 16 newRock.width = 64; newRock.height = 64; newRock.halfWidth = 32; newRock.halfHeight = 32; newRock.hitWidth = 48; newRock.hitHeight = 48; //start all new rocks in upper left for ship safety newRock.x = Math.floor(Math.random()*50); //ConsoleLog.log("newRock.x=" + newRock.x); newRock.y = Math.floor(Math.random()*50); //ConsoleLog.log("newRock.y=" + newRock.y); newRock.dx = (Math.random()*2)+levelRockMaxSpeedAdjust; if (Math.random()<.5){ newRock.dx *= -1; } newRock.dy=(Math.random()*2)+levelRockMaxSpeedAdjust; if (Math.random()<.5){ newRock.dy *= -1; } //rotation speed and direction if (Math.random()<.5){ newRock.rotationInc = -1; }else{ newRock.rotationInc = 1; } newRock.animationDelay = Math.floor(Math.random()*3+1); newRock.animationCount = 0; newRock.scoreValue = bigRockScore; newRock.rotation = 0; rocks.push(newRock); //ConsoleLog.log("rock created rotationInc=" + newRock.rotationInc); } resetPlayer(); switchGameState(GAME_STATE_PLAYER_START); } function gameStatePlayerStart(){ fillBackground(); renderScoreBoard(); if (player.alpha < 1){ player.alpha += .01; ConsoleLog.log("player.alpha=" + context.globalAlpha) }else{ switchGameState(GAME_STATE_PLAY_LEVEL); player.safe = false; // added chapter 9 } //renderPlayerShip(player.x, player.y,270,1); context.globalAlpha = 1; //new in chapter 9 checkKeys(); update(); render(); //added chapter 9 checkCollisions(); checkForExtraShip(); checkForEndOfLevel(); frameRateCounter.countFrames(); } function gameStatePlayLevel(){ checkKeys(); update(); render(); checkCollisions(); checkForExtraShip(); checkForEndOfLevel(); frameRateCounter.countFrames(); } function resetPlayer() { player.rotation = 270; player.x = .5*xMax; player.y = .5*yMax; player.facingX = 0; player.facingY = 0; player.movingX = 0; player.movingY = 0; player.alpha = 0; player.missileFrameCount = 0; //added chapter 9 player.safe = true; } function checkForExtraShip() { if (Math.floor(score/extraShipAtEach)