Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import flash.media.SoundChannel;
- var shadow:DropShadowFilter = new DropShadowFilter();
- shadow.blurX=15
- shadow.blurY=shadow.blurX
- var bird:_bird=new _bird();
- bird.x=spawnPoint.x;
- bird.y=spawnPoint.y;
- addChild(bird);
- bird.filters=[shadow];
- spawnPoint.visible=false;
- //hides the mouse
- Mouse.hide();
- //input stuff;
- stage.addEventListener(KeyboardEvent.KEY_DOWN, start);
- function newBird(){
- var bird:_bird=new _bird();
- bird.x=spawnPoint.x;
- bird.y=spawnPoint.y;
- addChild(bird);
- bird.filters=[shadow];
- }
- function start(event):void{
- if (event.keyCode==32){
- startGame();
- }
- }
- function startGame():void{
- var canFlap:Boolean=true;
- var flap:_flap=new _flap();
- var mouseHidden:Boolean=true;
- var yVelocity:int=-30;
- var yVelocityCap:int=36;
- stage.removeEventListener(KeyboardEvent.KEY_DOWN, start);
- stage.addEventListener(Event.ENTER_FRAME, update);
- stage.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);
- stage.addEventListener(KeyboardEvent.KEY_UP, handleKeyUp);
- function update(event):void{
- bird.y+=yVelocity;
- //gravity
- if (yVelocity<yVelocityCap){
- yVelocity+=6;
- }
- //rotation
- if (bird.rotation < 100 && bird.rotation>-50 && yVelocity>0){
- bird.rotation+=yVelocity*0.7;
- }
- if (bird.rotation<100 && bird.rotation>-100 && yVelocity<0){
- bird.rotation+=yVelocity*2;
- }
- if (bird.rotation>=100){
- bird.rotation=99;
- }
- if (bird.rotation<-50){
- bird.rotation=-49;
- }
- }
- //flying
- function handleKeyDown(event):void{
- if (event.keyCode==32 && canFlap){
- canFlap=false;
- yVelocity=-30;
- bird.gotoAndPlay(1);
- playFlapSound();
- }
- }
- function handleKeyUp(event):void{
- if (event.keyCode==32){
- canFlap=true;
- }
- }
- function playFlapSound():void{
- var flapChannel:SoundChannel=flap.play();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement