flash on 2010-4-14
♥0 |
Line 41 |
Modified 2010-04-14 00:13:23 |
MIT License
archived:2017-03-10 03:40:23
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/56jT
*/
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 = 100;
ball.y = 200;
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 = 30;
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 < 0 || stage.stageWidth <= this.x) vx = -vx;
if (this.y < 0 || stage.stageHeight <= this.y) vy = -vy;
}
}