Advertisement
Guest User

acceleration problem

a guest
Oct 11th, 2013
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. document.addEventListener('keydown',function Down(e) {
  2.         e.preventDefault();
  3.         if(e.keyCode == 37){
  4.             //left
  5.                     e.preventDefault();
  6.             goLeftVar = setInterval(function GoLeft(){if(-3<drawX){ClearAndDraw();
  7.             drawX = drawX - VelocityOfJetVarTWO;}/*left*/},VelocityOfJet);
  8.         }
  9.         if(e.keyCode == 38){
  10.             //up
  11.                     e.preventDefault();
  12.             goUpVar = setInterval(function GoUp(){if(drawY>-1){ClearAndDraw();
  13.             drawY = drawY - VelocityOfJetVarTWO;}/*Up*/},VelocityOfJet);
  14.         }
  15.            
  16.         if(e.keyCode == 39){
  17.             //right
  18.                     e.preventDefault();
  19.             goRightVar = setInterval(function GoRight(){if(701 > drawX){ClearAndDraw();
  20.             drawX = drawX + VelocityOfJetVarTWO;}/*right*/},VelocityOfJet);        
  21.         }
  22.            
  23.         if(e.keyCode == 40){
  24.             //down
  25.                     e.preventDefault();
  26.             goDownVar = setInterval(function GoDown() {if(drawY < 461){ClearAndDraw();
  27.             drawY = drawY + VelocityOfJetVarTWO;}/*down*/},VelocityOfJet);
  28.         }
  29.         },false);
  30.  
  31. document.addEventListener('keyup',function Up(e) {
  32.     e.preventDefault();
  33.     if(e.keyCode == 37)
  34.         //left
  35.         {clearInterval(goLeftVar);}//left
  36.     if(e.keyCode == 38)
  37.         //up
  38.         {clearInterval(goUpVar);}//up
  39.     if(e.keyCode == 39)
  40.         //right
  41.         {clearInterval(goRightVar);}//right
  42.     if(e.keyCode == 40)
  43.         //down
  44.         {clearInterval(goDownVar);}//down
  45. }   ,false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement