flash on 2010-4-14

by kihon
♥0 | Line 43 | Modified 2010-04-14 00:14:32 | MIT License
play

ActionScript3 source code

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

package
{
	import flash.display.Sprite;
	import flash.events.Event;
 
	public class Main extends Sprite
	{
		private var ball:Ball;
 
		public function Main()
		{
			ball = new Ball();
			ball.x = 200;
			ball.y = 100;
			addChild(ball);
 
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}
 
		private function onEnterFrame(event:Event):void
		{
			ball.move();
		}
	}
}
 
import flash.display.Sprite;
 
class Ball extends Sprite
{
	public const RADIUS:int = 10;
	public var vx:int = 10;
	public var vy:int = 10;
 
	public function Ball()
	{
		graphics.beginFill(0x0);
		graphics.drawCircle(0, 0, RADIUS);
		graphics.endFill();
	}
 
	public function move():void
	{
		this.x += vx;
		this.y += vy;
 
		if (this.x - RADIUS < 0) this.x = RADIUS, vx = Math.random() * 10 + 5;
		if (this.y - RADIUS < 0) this.y = RADIUS, vy = Math.random() * 10 + 5;
		if (stage.stageWidth  <= this.x + RADIUS) this.x = stage.stageWidth  - RADIUS, vx = -(Math.random() * 10 + 5);
		if (stage.stageHeight <= this.y + RADIUS) this.y = stage.stageHeight - RADIUS, vy = -(Math.random() * 10 + 5);
	}
}