Guest User

acceleration problem

a guest
Oct 11th, 2013
55
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(); drawY = drawY - VelocityOfJetVarTWO;}/*Up*/},VelocityOfJet);
  13.         }
  14.            
  15.         if(e.keyCode == 39){
  16.             //right
  17.                     e.preventDefault();
  18.             goRightVar = setInterval(function GoRight(){if(701 > drawX){ClearAndDraw();
  19.             drawX = drawX + VelocityOfJetVarTWO;}/*right*/},VelocityOfJet);        
  20.         }
  21.            
  22.         if(e.keyCode == 40){
  23.             //down
  24.                     e.preventDefault();
  25.             goDownVar = setInterval(function GoDown() {if(drawY < 461){ClearAndDraw();
  26.             drawY = drawY + VelocityOfJetVarTWO;}/*down*/},VelocityOfJet);
  27.         }
  28.         },false);
  29.  
  30. document.addEventListener('keyup',function Up(e) {
  31.     e.preventDefault();
  32.     if(e.keyCode == 37)
  33.         //left
  34.         {clearInterval(goLeftVar);}//left
  35.     if(e.keyCode == 38)
  36.         //up
  37.         {clearInterval(goUpVar);}//up
  38.     if(e.keyCode == 39)
  39.         //right
  40.         {clearInterval(goRightVar);}//right
  41.     if(e.keyCode == 40)
  42.         //down
  43.         {clearInterval(goDownVar);}//down
  44. }   ,false);
Advertisement
Add Comment
Please, Sign In to add comment