flash on 2013-3-3
♥0 |
Line 80 |
Modified 2013-03-04 08:04:01 |
MIT License
archived:2017-03-20 14:03:47
ActionScript3 source code
/**
* Copyright ohisama ( http://wonderfl.net/user/ohisama )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/1TKb
*/
package
{
import Box2D.Common.Math.b2Vec2;
import com.actionsnippet.qbox.*;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Graphics;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.Vector3D;
import flash.text.TextField;
public class Main extends MovieClip
{
public function Main() : void
{
var CHK : Boolean = true ;
var DIRC : Boolean = false ;
var QB2 : QuickBox2D = new QuickBox2D(this, {gravityY : 1});
var BALL : QuickObject ;
//QB2.addBox({x : 0, y : 7, width : 1 , height : 20, density : 0});
QB2.addBox({x : 15.5, y : 7, width : 1 , height : 20, density : 0});
QB2.addBox({x : 7, y : 0, width : 20, height : 1, density : 0});
var S : Sprite = new Sprite;
addChild(S);
var TF : TextField = new TextField;
TF.x = 20;
TF.y = 20;
TF.text = "ten";
addChild(TF);
QB2.start();
stage.addEventListener(MouseEvent.MOUSE_DOWN, function(e : MouseEvent) :void
{
if (CHK)
{
DIRC = true;
}
});
stage.addEventListener(MouseEvent.MOUSE_UP, function(e : MouseEvent) :void
{
DIRC = false;
if (CHK)
{
CHK = false;
BALL = QB2.addCircle({x : 14, y : 2, radius : 0.5 , lineThickness : 8 , fillColor : 0xFFA0A0 , restitution : 1 , groupIndex : -1});
var X : Number = mouseX - 14 * 30;
var Y : Number = mouseY - 2 * 30;
var L : Number = Math.sqrt(X * X + Y * Y);
TF.text = mouseX + " " + mouseY;
if (L)
{
L = L / -50;
}
BALL.body.SetLinearVelocity(new b2Vec2(L, Y / X * L - 1));
TF.text = L + "";
}
});
addEventListener(Event.ENTER_FRAME, function(e : Event) : void
{
var G : Graphics = S.graphics;
G.clear();
if (DIRC)
{
G.lineStyle(1, 0xFF0000, 0.5);
G.moveTo(mouseX , mouseY);
G.lineTo(14 * 30 , 2 * 30);
}
if (BALL && 20 < BALL.y)
{
BALL.destroy();
BALL = null;
CHK = true;
DIRC = true;
}
});
}
}
}