diff --git a/custom.js b/custom.js index cc513f0..029ae68 100755 --- a/custom.js +++ b/custom.js @@ -1,24 +1,30 @@ addShortcut(function(){ toggleFullScreen(); },[key.F]); - addShortcut(function(){ - userDir=-1; + userDir=-1; + if(userSpeed<0) + { + userSpeed=0; + } + userTimerCount=0; + userSpeed-=.25; },[key.UP]); addRemovalShortcut(function(){ - userDir=0; + userDir=0; + userTimerCount+=0.01; },[key.UP]); addRemovalShortcut(function(){ userDir=0; },[key.DOWN]); addShortcut(function(){ - userDir=1; -},[key.DOWN]); -addRemovalShortcut(function(){ - console.log(1); -},[key.DOWN]); -addShortcut(function(){ - console.log(2); + userDir=1; + if(userSpeed>0) + { + userSpeed=0; + } + userTimerCount=0; + userSpeed+=.25; },[key.DOWN]); diff --git a/gameScripts.js b/gameScripts.js index c3a3331..d934cf2 100755 --- a/gameScripts.js +++ b/gameScripts.js @@ -1,4 +1,5 @@ var score=0; +var difficulty=1; var isMute = false; //var kingAudio = new Audio('King.mp3'), knockAudio = new Audio('Knock.mp3'), matchAudio = new Audio('match.mp3'); @@ -12,12 +13,27 @@ var userDir=0; var compDir=0; var gameSpeed=2; +var userSpeed=0; +var compSpeed=0; +var ballSpeed=0; +var userTimerCount=0; +var compTimerCount=0; + var userLoc, compLoc, ballXLoc, ballYLoc; -var gameLoop +var gameLoop; function newGame() { + ballDir=1; + userDir=0; + compDir=0; + gameSpeed=2; + userSpeed=0; + compSpeed=0; + ballSpeed=0; + userTimerCount=0; + compTimerCount=0; canvas = document.getElementById("myCanvas"); canvas.width=screen.availWidth*.98; canvas.height=screen.availHeight*.899; @@ -26,7 +42,7 @@ function newGame() height = canvas.height; userLoc = height*.45-10; compLoc = height*.5-10; - ballXLoc = width*.06-10; + ballXLoc = width*.45-10; ballYLoc = height*.5-10; gameOver = false; drawBoard(); @@ -38,6 +54,7 @@ function newGame() // isMute = false; // multPossible = false; // gameLoop= setInterval(move,5); + } function toggleFullScreen() @@ -97,17 +114,54 @@ function drawUser() function drawComp() { ctx.fillStyle = "#000000"; + compLoc=compLoc+gameSpeed*difficulty/3*compDir; + if(compLoc>height*.95-175) + { + compLoc=height*.95-175; + } + else if(compLoc0.3) + { + userSpeed=0; + } + if(compTimerCount>0.3) + { + compSpeed=0; + } ctx.fillStyle = "#000000"; - if((ballYLoc-userLoc<=175&&userLoc-ballYLoc<=25&&Math.abs(ballXLoc-(width*.96-10))<3)||(ballYLoc-compLoc<=175&&compLoc-ballYLoc<=25&&Math.abs(ballXLoc-(width*.02+50))<3)) + if((ballYLoc-userLoc<=175&&userLoc-ballYLoc<=25&&Math.abs(ballXLoc-(width*.96-10))<3)) { ballDir*=-1; + ballSpeed+=userSpeed; + if(ballSpeed*userSpeed>=0) + { + // ballSpeed*=-1; + } + console.log(ballSpeed); + console.log(ballYLoc+ballSpeed); } + else if((ballYLoc-compLoc<=175&&compLoc-ballYLoc<=25&&Math.abs(ballXLoc-(width*.02+50))<3)) + { + ballDir*=-1; + ballSpeed+=compSpeed; + console.log(ballSpeed); + } + + if(Math.abs(ballYLoc-height*.05)<25||Math.abs(ballYLoc-height*.95)<25) + { + ballSpeed*=-1; + } + ballXLoc=ballXLoc + gameSpeed*ballDir; + ballYLoc+=ballSpeed; ctx.fillRect(ballXLoc,ballYLoc,25,25); if(ballXLoc>width||ballXLoc<-10) { @@ -122,7 +176,25 @@ function move() // compDir=0; // gameSpeed=5; //requestAnimationFrame(move); - + if(ballDir==-1) + { + moveAI(); + } + else + { + compDir=0; + } +} +function moveAI() +{ + if((ballYLoc>compLoc+175/2)&&(compLocheight*.05-175)) + { + compDir=-1; + } } function mute() { diff --git a/index.html b/index.html index f8cc814..e66ecc3 100755 --- a/index.html +++ b/index.html @@ -7,7 +7,7 @@
- + Your browser does not support the HTML5 canvas tag.
Try using a more modern browser, like Google Chrome,to play the game.