forked from: 2010-6-6 円のランダム移動(+座標壁反射)
♥0 |
Line 48 |
Modified 2010-06-07 22:18:04 |
MIT License
archived:2017-03-20 20:23:54
ActionScript3 source code
/**
* Copyright ameo ( http://wonderfl.net/user/ameo )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/awpN
*/
// forked from ameo's 2010-6-6 円のランダム移動
package {
import flash.display.*;
import flash.events.Event;
[SWF(frameRate="30", width="465", height="465")]
public class Animation extends Sprite {
private var _circle:Circle;
public function Animation(){
//インスタンス
_circle = new Circle(10);
//透明度
_circle.alpha = 0.5;
//移動方向ランダム(+)
_circle.vx = Math.round(Math.random()*10);
_circle.vy = Math.round(Math.random()*10);
//初期位置
_circle.x = 100;
_circle.y = 100;
//表示
addChild(_circle);
addEventListener(Event.ENTER_FRAME,enterFrameHandler);
addEventListener(Event.ENTER_FRAME,zahyou);
}
private function enterFrameHandler(e:Event):void {
_circle.move();
}
private function zahyou(e:Event):void {
if (_circle.x > 464) {
_circle.move();
_circle.vx = -Math.round(Math.random()*10);
}
if (_circle.y > 464) {
_circle.move();
_circle.vy = -Math.round(Math.random()*10);
}
}
}
}
import flash.display.Sprite;
class Circle extends Sprite{
public var vx:Number;
public var vy:Number;
public var radius:Number;
public function Circle(_radius:Number,_fillColor:uint = 0xcd5e3c){
graphics.beginFill(_fillColor);
graphics.drawCircle(0,0,_radius);
graphics.endFill();
radius = _radius
}
public function move():void{
x += vx;
y += vy;
}
}