Advertisement
Guest User

Actionscript

a guest
Mar 4th, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //variables
  2. var allDown:Boolean=false
  3. if(rightDown=true && leftDown==true){
  4.     allDown=true
  5. }
  6. var allUp:Boolean=true
  7. if(rightDown=false && leftDown==false){
  8.     allUp=true
  9. }
  10. var rightDown:Boolean=false
  11. var leftDown:Boolean=false
  12. var playerXSpeed:int=0
  13. var playerYSpeed:int=0
  14. var maxPositiveSpeed:int=10
  15. var maxNegativeSpeed:int=maxPositiveSpeed-maxPositiveSpeed*2
  16. //event listeners
  17. stage.addEventListener(Event.ENTER_FRAME, updateGame);
  18. addEventListener(KeyboardEvent.KEY_DOWN, keyHandler);
  19. addEventListener(KeyboardEvent.KEY_UP, keyHandler);
  20. //functions
  21. function updateGame(event){
  22.     movePlayer();
  23.     updateSpeed();
  24. }
  25. function movePlayer(){
  26.     player.x+=playerXSpeed
  27. }
  28. function updateSpeed(){
  29.     if(rightDown==true && playerXSpeed>maxPositiveSpeed){
  30.         playerXSpeed+=1
  31.     }
  32.     if(leftDown==true && playerXSpeed>maxNegativeSpeed){
  33.         playerXSpeed-=1
  34. }
  35.     if(allUp==true && playerXSpeed<0){
  36.         playerXSpeed-=1
  37.     }
  38.     if(allUp==true && playerXSpeed>0){
  39.         playerXSpeed+=1
  40.     }
  41. }
  42. function keyHandler(event){
  43.     if(event.keyCode==68 || event.keyCode==39){
  44.         if(rightDown==true){
  45.             rightDown=false
  46.         }
  47.         else{
  48.             rightDown=true
  49.         }
  50.     }
  51.     if(event.keyCode==65 || event.keyCode==37){
  52.         if(leftDown==true){
  53.             leftDown=false
  54.         }
  55.         else{
  56.             leftDown=true
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement