import flash.display.Bitmap; import flash.display.BitmapData; /** * 矢印のオブジェクトです。 * @author Yasunobu Ikeda */ class Arrow extends Bitmap { private var vx:Float = 0.0; private var vy:Float = 0.0; private var ax:Float = 0.0; private var ay:Float = 0.0; private var friction:Float; public function new(bmd:BitmapData) { super(bmd); this.friction = 0.0001 * Math.random() + 0.0001; } /** * エンターフレーム内での計算ロジックです。 * @param colorA X方向の色成分です。0~255の整数を想定しています。 * @param colorB Y方向の色成分です。0~255の整数を想定しています。 */ public function step(colorA:UInt, colorB:UInt):Void { var diffX:Int = colorA - 128; var diffY:Int = colorB - 128; this.ax += diffX * this.friction; this.ay += diffY * this.friction; this.vx += this.ax; this.vy += this.ay; this.x += this.vx; this.y += this.vy; this.rotation = Math.atan2(this.ay, this.ax) * 180 / Math.PI; this.ax *= .98; this.ay *= .98; this.vx *= .94; this.vy *= .94; ( this.x > Main.stageW ) ? this.x = 0 : (( this.x < 0 ) ? this.x = Main.stageW : 0 ); ( this.y > Main.stageH ) ? this.y = 0 : (( this.y < 0 ) ? this.y = Main.stageH : 0 ); } }