Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import flash.events.Event;
- import flash.events.MouseEvent;
- var ball:Ball=new Ball;
- var drag:Boolean=false;
- addChild(ball);
- ball.x=stage.stageWidth*.5;
- ball.y=stage.stageHeight*.5;
- ball.gravity=5;ball.friction=.97;
- var oldx:Number;var oldy:Number;
- var vx:Number;var vy:Number;
- var bounce=.9;
- addEventListener("enterFrame",enterFrame);
- stage.addEventListener("mouseDown",mouseDown);
- stage.addEventListener("mouseUp",mouseUp);
- function mouseDown(event:MouseEvent){
- drag=true;
- }
- function mouseUp(event:MouseEvent){
- drag=false;
- ball.vx=vx;
- ball.vy=vy;
- }
- function enterFrame(event:Event):void{
- if(drag){
- ball.x=mouseX;ball.y=mouseY;
- ball.vx=0;ball.vy=0;
- vx=ball.x-oldx;
- vy=ball.y-oldy;
- oldx=ball.x;
- oldy=ball.y;
- }else ball.update();
- if(ball.x+.5*ball.width>stage.stageWidth){
- ball.vx*=-bounce;ball.x=stage.stageWidth-.5*ball.width;
- }
- if(ball.y+.5*ball.height>stage.stageHeight){
- ball.vy*=-bounce;ball.y=stage.stageHeight-.5*ball.height;
- }
- if(ball.x-.5*ball.width<0){
- ball.vx*=-bounce;ball.x=.5*ball.width;
- }
- if(ball.y-.5*ball.height<0){
- ball.vy*=-bounce;ball.y=.5*ball.height;
- }
- }
Add Comment
Please, Sign In to add comment