In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: flash on 2013-2-25

Get Adobe Flash player
by ohisama 27 Feb 2013
    Embed
/**
 * Copyright ohisama ( http://wonderfl.net/user/ohisama )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/pal9
 */

// forked from ohisama's flash on 2013-2-25
package
{
    import flash.events.Event;
    import org.papervision3d.view.*;
    import org.papervision3d.objects.*;
    import Box2D.Dynamics.*;
    import Box2D.Collision.*;
    import Box2D.Common.Math.*;
    import org.papervision3d.lights.PointLight3D;
    import Box2D.Collision.Shapes.b2PolygonDef;
    import Box2D.Collision.Shapes.b2CircleDef;
    import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
    import org.papervision3d.materials.utils.MaterialsList;
    import org.papervision3d.objects.primitives.Cube;
    import org.papervision3d.objects.parsers.DAE;
    import org.papervision3d.view.BasicView;
    [SWF(backgroundColor="#000000", width="475", height="475")]
    public class Main extends BasicView
    {
        private var m_iterations : int;
        private var m_timeStep : Number;
        private var m_world : b2World;
        private var cubs : Array = new Array();
        private var boys : Array = new Array();
        public function Main()
        {
            m_iterations = 0.01;
            m_timeStep = 1 / 20;
            var worldAABB : b2AABB = new b2AABB;
            worldAABB.lowerBound.Set(-100.0, -100.0);
            worldAABB.upperBound.Set(100.0, 100.0);
            var gravity : b2Vec2 = new b2Vec2(0, 0);
            m_world = new b2World(worldAABB, gravity, true);
            var wallShapeDef : b2PolygonDef = new b2PolygonDef();
            var wallBodyDef : b2BodyDef = new b2BodyDef();
            var wall : b2Body;
            wallShapeDef.SetAsBox(20, 1);      
            wallBodyDef.position.Set(0, 1);
            wall = m_world.CreateBody(wallBodyDef);
            wall.CreateShape(wallShapeDef);            
            wallBodyDef.position.Set(0, 29);
            wall = m_world.CreateBody(wallBodyDef);
            wall.CreateShape(wallShapeDef);
            
            wallShapeDef.SetAsBox(1, 30);
            wallBodyDef.position.Set(1, 0);
            wall = m_world.CreateBody(wallBodyDef);
            wall.CreateShape(wallShapeDef);            
            //wallBodyDef.position.Set(95, 0);
            //wall = m_world.CreateBody(wallBodyDef);
            //wall.CreateShape(wallShapeDef);
            
            wall.SetMassFromShapes();
            for (var i : int = 0; i < 7; i++)
            {
                var boxShape : b2PolygonDef = new b2PolygonDef();
                boxShape.SetAsBox(1, 1);
                boxShape.density = 8;
                boxShape.friction = 8;
                boxShape.restitution = 0.5;
                var bodyDef : b2BodyDef = new b2BodyDef();
                bodyDef.position.Set(8, i * 3 + 6);
                var body : b2Body = m_world.CreateBody(bodyDef);
                body.CreateShape(boxShape);
                body.SetMassFromShapes();
            }
            var ballshape : b2CircleDef = new b2CircleDef();
            ballshape.radius = 2;
            ballshape.density = 8;
            ballshape.friction = 8;
            ballshape.restitution = 0.9;
            var balldef : b2BodyDef = new b2BodyDef();
            balldef.position.Set(20, 15);
            //bodyDef.userData = {id : "", obj : obj3d};
            var ball : b2Body = m_world.CreateBody(balldef);
            ball.CreateShape(ballshape);
            var pow : b2Vec2 = new b2Vec2(-1, 0); 
            ball.SetLinearVelocity(pow);
            ball.SetMassFromShapes();
            var dbgDraw : b2DebugDraw = new b2DebugDraw();
            dbgDraw.m_sprite = this;
            dbgDraw.m_drawScale = 10.0;
            dbgDraw.m_fillAlpha = 0.8;
            dbgDraw.m_lineThickness = 0.3;
            dbgDraw.m_alpha = 0.3;
            dbgDraw.m_xformScale = 1.0
            dbgDraw.m_drawFlags = b2DebugDraw.e_shapeBit;
            m_world.SetDebugDraw(dbgDraw);
            startRendering();
        } 
        override protected function onRenderTick(event : Event = null) : void
        {
            m_world.Step(m_timeStep, m_iterations);
            super.onRenderTick(event);
        }
    }
}