/**
* Copyright murata1988 ( http://wonderfl.net/user/murata1988 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/gXQx
*/
package {
import flash.text.TextField;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
// write as3 code here..
var t:TextField = new TextField();
t.text = "当たり判定のテスト(作業中)";
t.width = 200;
addChild( t );
var l:GraphicLineSegment = new GraphicLineSegment();
l.line.min = 10;
l.line.max = 200;
l.line.begin.x = 0;
l.line.begin.y = 0;
l.line.direction.x = 2;
l.line.direction.y = 1;
l.updateGraphic();
addChild( l );
var r:GraphicRect = new GraphicRect( 120, 120, 200, 160 );
r.rect.rotation = Math.PI / 3;
r.rect.center.x = 35;
r.rect.center.y = 25;
t.text = r.rect.toString();
r.updateGraphic();
addChild( r );
}
}
}
import flash.display.Sprite;
import flash.geom.Rectangle;
import flash.external.ExternalInterface;
class Rect extends Rectangle
{
public var rotation:Number = 0;
public var center:Vector2D = null;
public function Rect( initialLeft:Number, initialTop:Number, initialRight:Number, initialBottom:Number )
{
left = initialLeft;
top = initialTop;
right = initialRight;
bottom = initialBottom;
center.x = ( right - left ) / 2;
center.y = ( bottom - top ) / 2;
}
}
class GraphicRect extends Sprite
{
public var rect:Rect;
public function GraphicRect( left:Number, top:Number, right:Number, bottom:Number )
{
super();
rect = new Rect( left, top, right, bottom );
}
public function updateGraphic():void
{
// graphics.clear();
// graphics.beginFill( 0xFF0000 );
// graphics.drawRect( rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top );
// rotation = rect.rotation / Math.PI * 180;
}
}
class Vector2D{
public var x:Number = 0;
public var y:Number = 0;
public function Vector2D( initialX:Number = 0, initialY:Number = 0 )
{
x = initialX;
y = initialY;
}
public function length():Number
{
return Math.sqrt( Math.pow( x, 2 ) + Math.pow( y, 2 ) );
}
}
class Line
{
public var begin:Vector2D = null;
public var direction:Vector2D = null;
public function Line()
{
begin = new Vector2D;
direction = new Vector2D;
}
}
class LineSegment extends Line
{
public var min:Number = 0;
public var max:Number = 0;
public function LineSegment()
{
}
public function getX( t:Number ):Number
{
return begin.x + direction.x * t;
}
public function getY( t:Number ):Number
{
return begin.y + direction.y * t;
}
}
class GraphicLineSegment extends Sprite
{
public var line:LineSegment = null;
public function GraphicLineSegment(){
line = new LineSegment();
}
public function updateGraphic():void
{
graphics.clear();
graphics.lineStyle( 1, 0x00FF00 );
graphics.moveTo( line.getX( line.min ), line.getY( line.min ) );
graphics.lineTo( line.getX( line.max ), line.getY( line.max ) );
}
}