Skip to content

Commit

Permalink
added more control over replay and screens
Browse files Browse the repository at this point in the history
  • Loading branch information
courtyenn committed May 25, 2016
1 parent 4d2006d commit e113d4b
Showing 1 changed file with 60 additions and 51 deletions.
111 changes: 60 additions & 51 deletions public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,25 @@ var kitty_jump = (function(){
this.isJumping = true;
},
jump: function(){
this.canJump = false;
this.velocityY = this.velocityY - ((this.initialVelocityY * this.time) - ((1/2) * gravity * Math.pow(this.time, 2)));
// this.velocityY = this.initialVelocityY;
if(this.isJumping){
if(this.y <= 0 || this.velocityY < 0 ){
this.isJumping = false;
this.isFalling = true;
this.time = 1;
}
else {
this.y -= (this.velocityY);
this.time = this.time + .22;
if(currentGameState !== 300){
this.canJump = false;
this.velocityY = this.velocityY - ((this.initialVelocityY * this.time) - ((1/2) * gravity * Math.pow(this.time, 2)));
// this.velocityY = this.initialVelocityY;
if(this.isJumping){
if(this.y <= 0 || this.velocityY < 0 ){
this.isJumping = false;
this.isFalling = true;
this.time = 1;
}
else {
this.y -= (this.velocityY);
this.time = this.time + .22;
}
}

}
},
fall: function(){
if(currentGameState !== 300){
this.velocityY = gravity * this.time;
this.y += (this.velocityY);
if(this.y >= (this.startY) ){
Expand All @@ -116,6 +118,7 @@ var kitty_jump = (function(){
this.time = this.time + .22;
}
}
}
};

(function(){
Expand All @@ -131,7 +134,7 @@ var kitty_jump = (function(){
if(previousGameState != currentGameState){
previousGameState = currentGameState;
$('#pause').removeClass('invisible');
gameSound.muted = true;
gameSound.pause();
}

// if(keydown.o){
Expand All @@ -156,7 +159,7 @@ var kitty_jump = (function(){
"150" : function(){
if(previousGameState != currentGameState){
previousGameState = currentGameState;
bgSound.muted = true;
bgSound.pause();
}
// if(keydown.m){
// keydown.m = false;
Expand All @@ -177,9 +180,10 @@ var kitty_jump = (function(){
"200" : function(){ // play game
if(previousGameState != currentGameState){
previousGameState = currentGameState;
if(!gameSound.muted){
gameSound.play();
}
}
bgSound.pause();
if(!gameSound.muted){
gameSound.play();
}
// if(keydown.p) {
// currentGameState = 0;
Expand Down Expand Up @@ -249,9 +253,9 @@ var kitty_jump = (function(){
previousGameState = currentGameState;
if(!gameSound.muted){
gameSound.pause();
if(!gameDead.muted){
gameDead.play();
}
}
if(!gameDead.muted){
gameDead.play();
}

$('#game-over').removeClass('invisible');
Expand Down Expand Up @@ -327,30 +331,24 @@ var kitty_jump = (function(){
soundFx.muted = !soundFx.muted;
bgSound.muted = !bgSound.muted;
gameDead.muted = !gameDead.muted;
if(gameSound.muted){
gameSound.pause();
}
else {
gameSound.play();
}
if(soundFx.muted){
soundFx.pause();
}
else{
soundFx.play();
}
if(bgSound.muted){
bgSound.pause();
}
else{
bgSound.pause();
}
if(gameDead.muted){
gameDead.pause();
}
else {
gameDead.pause();
}
// if(gameSound.muted){
// gameSound.pause();
// }
// else {
// gameSound.play();
// }
// if(soundFx.muted){
// soundFx.pause();
// }
// if(bgSound.muted){
// bgSound.pause();
// }
// else{
// bgSound.pause();
// }
// if(gameDead.muted){
// gameDead.pause();
// }
currentGameState = previousGameState;
}
}
Expand Down Expand Up @@ -494,7 +492,7 @@ var kitty_jump = (function(){
function handleCollisions() {
kibbles.forEach(function(kibble) {
if(collides(kibble, player)) {
// soundFx.play();
soundFx.play();
score++;
kibble.active = false;
if(score%10===0 && player.lives.count > 0)player.lives.count++;
Expand Down Expand Up @@ -546,14 +544,16 @@ var kitty_jump = (function(){
startScreen.setAttribute("style", "width:" + CANVAS_WIDTH + "px;height:" + CANVAS_HEIGHT + "px");
$('#start').addClass('visibile');

bgSound.volume = .30;

/* bgSound.addEventListener('ended', function() {
this.currentTime = 0;
this.play();
}, false); */
// bgSound.play();
soundFx.volume = .28;
gameDead.volume = .20;
bgSound.volume = .1;
gameSound.volume = .1;
soundFx.volume = .05;
gameDead.volume = .1;

KeyHandler.keyMap = keyCodes;
KeyHandler.setKeyDownAction('w', player.jumpOn.bind(player), checkIfPlayerShouldJump);
Expand Down Expand Up @@ -596,15 +596,21 @@ function loop(){
}

function init(){
player.lives.count > 0 ? player.lives.count : 9;
player.lives.count = 9;
player.y = player.startY;
player.canJump = true;
player.isJumping = false;
player.isFalling = false;
score = 0;
enemies = [];
kibbles = [];
currentGameState = 200;
}

$('.start-game').on('click', function(event){
if(currentGameState == 300)$('#game-over').addClass('invisible');
if(currentGameState == 300){
$('#game-over').addClass('invisible');
}
event.preventDefault();
currentGameState = 200;
$('#start').addClass('invisible');
Expand All @@ -618,6 +624,8 @@ $('.main-menu').on('click', function(event){
currentGameState = 100;
$('#start').removeClass('invisible');
$('#game-over').addClass('invisible');
$('#instructions').addClass('invisible');
$('#game').addClass('invisible');
});
$('#mute').on('click', function(event){
event.preventDefault();
Expand All @@ -632,6 +640,7 @@ $('.go-to-instructions').on('click', function(event){
currentGameState = 175;
$('#start').addClass('invisible');
$('#instructions').removeClass('invisible');
$('#game').addClass('invisible');
});

return {
Expand Down

0 comments on commit e113d4b

Please sign in to comment.