Advertisement
Yung_Hotwheel

Untitled

Mar 9th, 2014
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import flash.media.SoundChannel;
  2.  
  3. var shadow:DropShadowFilter = new DropShadowFilter();
  4. shadow.blurX=15
  5. shadow.blurY=shadow.blurX
  6.  
  7. var bird:_bird=new _bird();
  8. bird.x=spawnPoint.x;
  9. bird.y=spawnPoint.y;
  10. addChild(bird);
  11. bird.filters=[shadow];
  12.  
  13. spawnPoint.visible=false;
  14.  
  15. //hides the mouse
  16. Mouse.hide();
  17. //input stuff;
  18. stage.addEventListener(KeyboardEvent.KEY_DOWN, start);
  19.  
  20. function newBird(){
  21.     var bird:_bird=new _bird();
  22.     bird.x=spawnPoint.x;
  23.     bird.y=spawnPoint.y;
  24.     addChild(bird);
  25.     bird.filters=[shadow];
  26. }
  27.  
  28. function start(event):void{
  29.     if (event.keyCode==32){
  30.         startGame();
  31.     }
  32. }
  33. function startGame():void{
  34.     var canFlap:Boolean=true;
  35.     var flap:_flap=new _flap();
  36.     var mouseHidden:Boolean=true;
  37.     var yVelocity:int=-30;
  38.     var yVelocityCap:int=36;
  39.    
  40.     stage.removeEventListener(KeyboardEvent.KEY_DOWN, start);
  41.  
  42.     stage.addEventListener(Event.ENTER_FRAME, update);
  43.     stage.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);
  44.     stage.addEventListener(KeyboardEvent.KEY_UP, handleKeyUp);
  45.  
  46.     function update(event):void{
  47.         bird.y+=yVelocity;
  48.         //gravity
  49.         if (yVelocity<yVelocityCap){
  50.             yVelocity+=6;
  51.         }
  52.         //rotation
  53.         if (bird.rotation < 100 && bird.rotation>-50 && yVelocity>0){
  54.             bird.rotation+=yVelocity*0.7;
  55.         }
  56.         if (bird.rotation<100 && bird.rotation>-100 && yVelocity<0){
  57.             bird.rotation+=yVelocity*2;
  58.         }
  59.         if (bird.rotation>=100){
  60.             bird.rotation=99;
  61.         }
  62.         if (bird.rotation<-50){
  63.             bird.rotation=-49;
  64.         }
  65.     }
  66.     //flying
  67.     function handleKeyDown(event):void{
  68.         if (event.keyCode==32 && canFlap){
  69.             canFlap=false;
  70.             yVelocity=-30;
  71.             bird.gotoAndPlay(1);
  72.             playFlapSound();
  73.         }
  74.     }
  75.     function handleKeyUp(event):void{
  76.         if (event.keyCode==32){
  77.             canFlap=true;
  78.         }
  79.     }
  80.     function playFlapSound():void{
  81.         var flapChannel:SoundChannel=flap.play();
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement