flash on 2010-4-26

by 084
♥0 | Line 72 | Modified 2010-04-26 19:11:01 | MIT License
play

ActionScript3 source code

/**
 * Copyright 084 ( http://wonderfl.net/user/084 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/voRw
 */

package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
	public class Accleration3 extends Sprite {
		private var ball:Ball;
		private var vx:Number = 0;
		private var vy:Number = 0;
		private var ax:Number = 0;
		private var ay:Number = 0;
 var gravity:Number = 0.1;
		
		public function Accleration3() {
			init();
		}
		private function init():void {
			ball = new Ball();
			addChild(ball);
			ball.x = stage.stageWidth / 2;
			ball.y = stage.stageHeight / 2;
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
			stage.addEventListener(KeyboardEvent.KEY_DOWN, onDown);
			stage.addEventListener(KeyboardEvent.KEY_UP, onUp);
		}
		private function onDown(event:KeyboardEvent):void {
			switch(event.keyCode) {
				case Keyboard.LEFT:
				ax = -0.2;
				break;
				
				case Keyboard.RIGHT:
				ax = 0.2;
				break;
				
				case Keyboard.UP:
				ay = -0.2;
				break;
				
				case Keyboard.DOWN:
				ay = 0.2;
				break;
				
				default:
				break;
			}
		}
		private function onUp(event:KeyboardEvent):void {
			ax = 0;
			ay = 0;
		}
		
		private function onEnterFrame(event:Event):void {
			vx += ax;
			vy += ay;
			vy += gravity;
			ball.x += vx;
			ball.y += vy;
			
		}
	}
}

import flash.display.Sprite;
	 class Ball extends Sprite {
		public var radius:Number;
		public var color:uint;
		public var vx:Number = 0;
		public var vy:Number = 0;
			
		public function Ball(radius:Number = 40,color:uint=0xff0000 ):void {
			this.radius = radius;
			this.color = color;
		    init();
		}
		public function init():void {
			graphics.beginFill(color);
			graphics.drawCircle(0, 0, radius);
			graphics.endFill();
		}
	}