public function Main(): void
{
new Boot();
….........................
}
* This source code was highlighted with Source Code Highlighter .
public function Main(): void
{
new Boot();
….........................
}
* This source code was highlighted with Source Code Highlighter .
// .
var gravity:Vec2 = new Vec2(0, 250);
// . , .
var world:UniformSleepSpace = new UniformSleepSpace( new AABB(0,0, 800, 600), 25, gravity);
* This source code was highlighted with Source Code Highlighter .
// .
var gravity:Vec2 = new Vec2(0, 250);
// . , .
var world:UniformSleepSpace = new UniformSleepSpace( new AABB(0,0, 800, 600), 25, gravity);
* This source code was highlighted with Source Code Highlighter .
physObject = Tools.createBox(400, 500, 700, 20, 0, 0, 0, true , Material.Steel);
world.addObject(physObject); //
addChild(physObject.graphic); //
* This source code was highlighted with Source Code Highlighter .
physObject = Tools.createBox(400, 500, 700, 20, 0, 0, 0, true , Material.Steel);
world.addObject(physObject); //
addChild(physObject.graphic); //
* This source code was highlighted with Source Code Highlighter .
public class Actor extends EventDispatcher
{
//
protected var _body:PhysObj;
// (, )
protected var _costume:DisplayObject;
public function Actor(myBody:PhysObj, myCostume:DisplayObject)
{
_body = myBody;
_costume = myCostume;
if (_body != null )
{
updateLook();
}
}
public function Update(): void
{
// , ,
if (!_body.sleep)
{
updateLook();
}
}
//
private function updateLook(): void
{
var PosX:Number = _body.px;
var PosY:Number = _body.py;
_costume.x = PosX * Main.SCALE;
_costume.y = PosY * Main.SCALE;
}
}
* This source code was highlighted with Source Code Highlighter .
public class Actor extends EventDispatcher
{
//
protected var _body:PhysObj;
// (, )
protected var _costume:DisplayObject;
public function Actor(myBody:PhysObj, myCostume:DisplayObject)
{
_body = myBody;
_costume = myCostume;
if (_body != null )
{
updateLook();
}
}
public function Update(): void
{
// , ,
if (!_body.sleep)
{
updateLook();
}
}
//
private function updateLook(): void
{
var PosX:Number = _body.px;
var PosY:Number = _body.py;
_costume.x = PosX * Main.SCALE;
_costume.y = PosY * Main.SCALE;
}
}
* This source code was highlighted with Source Code Highlighter .
public class Head extends Actor
{
public var head:PhysObj;
[Embed(source = '../../../../lib/ragdol.swf' , symbol = 'Ragdoll' )]
public var _headSprite: Class;
public function Head(parent:DisplayObjectContainer , location:Point, dimension:Point, initVel:Point)
{
var radius:Number = dimension.y / 2;
// HEAD -------------------------------------------------------------------------------
var headSprite:Sprite = new _headSprite();
headSprite.scaleX = radius * 2 / headSprite.width;
headSprite.scaleY = radius * 2 / headSprite.height;
//
if (!Main.gebug) parent.addChild(headSprite);
//
head = Tools.createCircle(location.x, location.y, radius, 0, 0, 0, false , true , Main.RagdolMaterial);
//
Main.world.addObject(head);
parent.addChild(head.graphic);
//
super(head, headSprite);
}
}
* This source code was highlighted with Source Code Highlighter .
public class Head extends Actor
{
public var head:PhysObj;
[Embed(source = '../../../../lib/ragdol.swf' , symbol = 'Ragdoll' )]
public var _headSprite: Class;
public function Head(parent:DisplayObjectContainer , location:Point, dimension:Point, initVel:Point)
{
var radius:Number = dimension.y / 2;
// HEAD -------------------------------------------------------------------------------
var headSprite:Sprite = new _headSprite();
headSprite.scaleX = radius * 2 / headSprite.width;
headSprite.scaleY = radius * 2 / headSprite.height;
//
if (!Main.gebug) parent.addChild(headSprite);
//
head = Tools.createCircle(location.x, location.y, radius, 0, 0, 0, false , true , Main.RagdolMaterial);
//
Main.world.addObject(head);
parent.addChild(head.graphic);
//
super(head, headSprite);
}
}
* This source code was highlighted with Source Code Highlighter .
public class Ragdol extends Actor
{
//
public var _actors:Array;
// .
private var pj:PivotJoint;
// . .
public var rost:Number = 200.0;
// . .
public function Ragdol(parent:DisplayObjectContainer , loc:Point, initVel:Point)
{
// . .
var maxBias:Number = 0.1;
var maxForce:Number = 1e+9;
// .
//
_actors.push( new Head(parent, new Point( head_x, head_y ), new Point(0, dhead), new Point(0, 0)));
_actors.push( new Torso1(parent, new Point( torso1_x, torso1_y ), new Point(ttorso, dtorso1), new Point(0, 0)));
_actors.push( new Torso2(parent, new Point( torso2_x, torso2_y ), new Point(ttorso, dtorso2), new Point(0, 0)));
_actors.push( new Torso3(parent, new Point( torso3_x, torso3_y ), new Point(ttorso, dtorso3), new Point(0, 0)));
_actors.push( new ArmLup(parent, new Point( l_arm_up_x, l_arm_up_y ), new Point(tarm, darm), new Point(0, 0)));
_actors.push( new ArmLmid(parent, new Point( l_arm_low_x, l_arm_low_y ), new Point(tarm, darm), new Point(0, 0)));
_actors.push( new ArmRup(parent, new Point( r_arm_up_x, r_arm_up_y ), new Point(tarm, darm), new Point(0, 0)));
_actors.push( new ArmRmid(parent, new Point( r_arm_low_x, r_arm_low_y ), new Point(tarm, darm), new Point(0, 0)));
_actors.push( new LegLup(parent, new Point(l_leg_up_x, l_leg_up_y), new Point(tleg, dleg), new Point(0, 0)));
_actors.push( new LegLlow(parent, new Point(l_leg_low_x, l_leg_low_y), new Point(tleg, dleg), new Point(0, 0)));
_actors.push( new LegRup(parent, new Point(r_leg_up_x, r_leg_up_y), new Point(tleg, dleg), new Point(0, 0)));
_actors.push( new LegRlow(parent, new Point(r_leg_low_x, r_leg_low_y), new Point(tleg, dleg), new Point(0, 0)));
//
//Head to torso1
pj = new PivotJoint(_actors[0].head, _actors[1].torso1, new Vec2(head_x, head_y + dhead/2));
pj.maxBias = maxBias;
pj.maxForce = maxForce;
Main.world.addConstraint(pj);
// .
// . .
super( null , null );
}
}
* This source code was highlighted with Source Code Highlighter .
public class Ragdol extends Actor
{
//
public var _actors:Array;
// .
private var pj:PivotJoint;
// . .
public var rost:Number = 200.0;
// . .
public function Ragdol(parent:DisplayObjectContainer , loc:Point, initVel:Point)
{
// . .
var maxBias:Number = 0.1;
var maxForce:Number = 1e+9;
// .
//
_actors.push( new Head(parent, new Point( head_x, head_y ), new Point(0, dhead), new Point(0, 0)));
_actors.push( new Torso1(parent, new Point( torso1_x, torso1_y ), new Point(ttorso, dtorso1), new Point(0, 0)));
_actors.push( new Torso2(parent, new Point( torso2_x, torso2_y ), new Point(ttorso, dtorso2), new Point(0, 0)));
_actors.push( new Torso3(parent, new Point( torso3_x, torso3_y ), new Point(ttorso, dtorso3), new Point(0, 0)));
_actors.push( new ArmLup(parent, new Point( l_arm_up_x, l_arm_up_y ), new Point(tarm, darm), new Point(0, 0)));
_actors.push( new ArmLmid(parent, new Point( l_arm_low_x, l_arm_low_y ), new Point(tarm, darm), new Point(0, 0)));
_actors.push( new ArmRup(parent, new Point( r_arm_up_x, r_arm_up_y ), new Point(tarm, darm), new Point(0, 0)));
_actors.push( new ArmRmid(parent, new Point( r_arm_low_x, r_arm_low_y ), new Point(tarm, darm), new Point(0, 0)));
_actors.push( new LegLup(parent, new Point(l_leg_up_x, l_leg_up_y), new Point(tleg, dleg), new Point(0, 0)));
_actors.push( new LegLlow(parent, new Point(l_leg_low_x, l_leg_low_y), new Point(tleg, dleg), new Point(0, 0)));
_actors.push( new LegRup(parent, new Point(r_leg_up_x, r_leg_up_y), new Point(tleg, dleg), new Point(0, 0)));
_actors.push( new LegRlow(parent, new Point(r_leg_low_x, r_leg_low_y), new Point(tleg, dleg), new Point(0, 0)));
//
//Head to torso1
pj = new PivotJoint(_actors[0].head, _actors[1].torso1, new Vec2(head_x, head_y + dhead/2));
pj.maxBias = maxBias;
pj.maxForce = maxForce;
Main.world.addConstraint(pj);
// .
// . .
super( null , null );
}
}
* This source code was highlighted with Source Code Highlighter .
private function onClick(e:MouseEvent): void
{
_ragdolActors.push( new Ragdol( this , new Point(mouseX, mouseY), new Point(0, 0)));
}
* This source code was highlighted with Source Code Highlighter .
private function onClick(e:MouseEvent): void
{
_ragdolActors.push( new Ragdol( this , new Point(mouseX, mouseY), new Point(0, 0)));
}
* This source code was highlighted with Source Code Highlighter .
private function update(e:Event): void
{
//
world.step(timeStep);
//
for ( var i: int = 0; i < _ragdolActors.length; i++ ) {
for ( var r: int = 0; r < _ragdolActors[i]._actors.length; r++ ) {
_ragdolActors[i]._actors[r].Update();
}
}
}
* This source code was highlighted with Source Code Highlighter .
private function update(e:Event): void
{
//
world.step(timeStep);
//
for ( var i: int = 0; i < _ragdolActors.length; i++ ) {
for ( var r: int = 0; r < _ragdolActors[i]._actors.length; r++ ) {
_ragdolActors[i]._actors[r].Update();
}
}
}
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/104176/
All Articles