Exemplo n.º 1
0
        private void CreateWalls()
        {
            var wallCoff = new Coefficients(0.8f, 0.95f);
            var wallLife = new Lifespan();

            var flrState = new PhysicsState(new ALVector2D((float)0.0, ((float)ActualWidth) * ((float)0.5), (float)ActualHeight + 100.0));
            var flrShape = new PolygonShape(VertexHelper.CreateRectangle(ActualWidth, 200), 2);
            var bdyFloor = new Body(flrState, flrShape, float.PositiveInfinity, wallCoff, wallLife);

            var ceiState = new PhysicsState(new ALVector2D((float)0.0, ((float)ActualWidth) * ((float)0.5), -100.0));
            var ceiShape = new PolygonShape(VertexHelper.CreateRectangle(ActualWidth, 200), 2);
            var bdyCeiling = new Body(ceiState, ceiShape, float.PositiveInfinity, wallCoff, wallLife);

            var lwlState = new PhysicsState(new ALVector2D((float)0.0, -100.0, ((float)ActualHeight) * ((float)0.5)));
            var lwlShape = new PolygonShape(VertexHelper.CreateRectangle(200, ActualHeight), 2);
            var bdyLeftWall = new Body(lwlState, lwlShape, float.PositiveInfinity, wallCoff, wallLife);

            var rwlState = new PhysicsState(new ALVector2D((float)0.0, (float)ActualWidth + 100.0, ((float)ActualHeight) * ((float)0.5)));
            var rwlShape = new PolygonShape(VertexHelper.CreateRectangle(200, ActualHeight), 2);
            var bdyRightWall = new Body(rwlState, rwlShape, float.PositiveInfinity, wallCoff, wallLife);

            engine.AddBody(bdyFloor);
            engine.AddBody(bdyCeiling);
            engine.AddBody(bdyLeftWall);
            engine.AddBody(bdyRightWall);
        }
Exemplo n.º 2
0
        private Body(Body copy)
        {
            Initialize();
            this.ignoresCollisionResponce = copy.ignoresCollisionResponce;
            this.shape            = copy.shape;
            this.massInfo         = copy.massInfo;
            this.coefficients     = copy.coefficients;
            this.collisionIgnorer = copy.collisionIgnorer;
            this.matrices         = copy.matrices.Duplicate();
            this.state            = copy.state.Duplicate();
            this.lifetime         = copy.lifetime.Duplicate();

            this.transformation = copy.transformation;
            this.linearDamping  = copy.linearDamping;
            this.angularDamping = copy.angularDamping;

            this.ignoresCollisionResponce = copy.ignoresCollisionResponce;
            this.ignoresGravity           = copy.ignoresGravity;
            this.ignoresPhysicsLogics     = copy.ignoresPhysicsLogics;
            this.isTransformed            = copy.isTransformed;
            this.isCollidable             = copy.isCollidable;
            this.isEventable = copy.isEventable;

            this.tag = copy.tag;
        }
Exemplo n.º 3
0
        public override void Init(PrototypingFramework.engine.GameEngine game)
        {
            base.Init(game);
            world = new PhysicsEngine();
            world.BroadPhase = new Physics2DDotNet.Detectors.SelectiveSweepDetector();
            world.Solver = new Physics2DDotNet.Solvers.SequentialImpulsesSolver();

            PhysicsTimer timer = new PhysicsTimer(world.Update, .01f);
            timer.IsRunning = true;

            rs = new RectangleShape(new SFML.Window.Vector2f(10, 10));
            rs.FillColor = Color.Black;
            rs.Position = new SFML.Window.Vector2f(10, 5);

            Coefficients coffecients = new Coefficients(/*restitution*/1, /*friction*/.5f);
            IShape shape2 = new PolygonShape(VertexHelper.CreateRectangle(10, 20), 3);
             body2 = new Body(new PhysicsState(new ALVector2D(0,10,5)), shape2, 5, coffecients, new Lifespan());

            world.AddBody(body2);

            PhysicsLogic logGravity;

            logGravity = (PhysicsLogic)new GravityField(new Vector2D(0f, 200f), new Lifespan());
            //pretty basic, create a downward force

            world.AddLogic(logGravity);

            Body bdyFloor;
            PhysicsState flrState;
            PolygonShape flrShape;
            Coefficients flrCoff;
            Lifespan flrLife;

            flrState = new PhysicsState(new ALVector2D((float)0.0, 0, (float)_game.Window.Size.Y-64));
            //create the state, centering the x-axis on screen and bottom of the y-axis

            flrShape = new PolygonShape(VertexHelper.CreateRectangle(_game.Window.Size.X, 64), 2);
            //create form.widthX64 rectangle (sq) with grid spacing at 2

            flrCoff = new Coefficients(0.5f, 0.4f, 0.4f);
            //might require tuning to your liking...

            flrLife = new Lifespan();
            //forever and ever

            bdyFloor = new Body(flrState, flrShape, float.PositiveInfinity, flrCoff, flrLife);
            //never ending mass means it isn't going to move on impact

            bdyFloor.IgnoresGravity = true;
            //make sure the floor stays

            world.AddBody(bdyFloor);

            floor = new RectangleShape(new SFML.Window.Vector2f( _game.Window.Size.X,64));
            floor.Position = new SFML.Window.Vector2f(0, _game.Window.Size.Y - 64);
            floor.FillColor = Color.Red;
        }
Exemplo n.º 4
0
        public BaseModelBody(PhysicsState state, IShape shape, MassInfo massInfo, Coefficients coefficients, Lifespan lifetime, Guid modelId)
            : base(state, shape, massInfo, coefficients, lifetime)
        {
            if (modelId == Guid.Empty)
            {
                throw new ArgumentException("'guid' cannot be empty!");
            }

            ModelId = modelId;
        }
Exemplo n.º 5
0
 /// <summary>
 /// Creates a new Body Instance.
 /// </summary>
 /// <param name="state">The State of the Body.</param>
 /// <param name="shape">The Shape of the Body.</param>
 /// <param name="mass">The mass of the Body The inertia will be aquired from the Shape.</param>
 /// <param name="coefficients">A object containing coefficients.</param>
 /// <param name="lifeTime">A object Describing how long the object will be in the engine.</param>
 public Body(
     PhysicsState state,
     IShape shape,
     Scalar mass,
     Coefficients coefficients,
     Lifespan lifetime)
     : this(
         state, shape,
         GetMassInfo(mass, shape),
         coefficients, lifetime)
 {
 }
Exemplo n.º 6
0
 public Bullet()
 {
     Coefficients coffecients = new Coefficients(/*restitution*/1, /*friction*/.5f);
     CircleShape circleShape = new CircleShape(6f, 7);
     float mass = 1f;
     Body = new Body(new PhysicsState(), circleShape, mass, coffecients, new Lifespan());
     Body.IsCollidable = true;
     Body.CollisionIgnorer = new BulletIgnorer();
     Body.Tag = "BulletTag";
     Body.Collided += new System.EventHandler<CollisionEventArgs>(Body_Collided);
     Origin.X = 14;
     Origin.Y = 15;
 }
Exemplo n.º 7
0
 public Player()
 {
     Coefficients coffecients = new Coefficients(/*restitution*/1, /*friction*/.5f);
     CircleShape circleShape = new CircleShape(80, 9);
     float mass = 10000;
     Body = new Body(new PhysicsState(), circleShape, mass, coffecients, new Lifespan());
     Body.IsCollidable = true;
     Body.CollisionIgnorer = new PlayerIgnorer();
     Body.Tag = "PlayerTag";
     Body.Collided += new System.EventHandler<CollisionEventArgs>(Body_Collided);
     Origin.X = 73;
     Origin.Y = 73;
     Health = 1000;
 }
Exemplo n.º 8
0
        /// <summary>
        /// Creates a new Body Instance.
        /// </summary>
        /// <param name="state">The State of the Body.</param>
        /// <param name="shape">The Shape of the Body.</param>
        /// <param name="massInfo">A object describing the mass and inertia of the Body.</param>
        /// <param name="coefficients">A object containing coefficients.</param>
        /// <param name="lifeTime">A object Describing how long the object will be in the engine.</param>
        public Body(
            PhysicsState state,
            IShape shape,
            MassInfo massInfo,
            Coefficients coefficients,
            Lifespan lifetime)
        {
            if (state == null)
            {
                throw new ArgumentNullException("state");
            }
            if (shape == null)
            {
                throw new ArgumentNullException("shape");
            }
            if (massInfo == null)
            {
                throw new ArgumentNullException("massInfo");
            }
            if (coefficients == null)
            {
                throw new ArgumentNullException("coefficients");
            }
            if (lifetime == null)
            {
                throw new ArgumentNullException("lifetime");
            }
            Initialize();
            this.matrices       = new Matrices();
            this.transformation = Matrix2x3.Identity;

            this.state          = new PhysicsState(state);
            this.Shape          = shape;
            this.massInfo       = massInfo;
            this.coefficients   = coefficients;
            this.lifetime       = lifetime;
            this.linearDamping  = 1;
            this.angularDamping = 1;
            this.isCollidable   = true;
            this.isEventable    = true;
            this.ApplyPosition();
        }
Exemplo n.º 9
0
        private Body(Body copy)
        {
            this.proxies = new LinkedList <BodyProxy>();
            this.ignoresCollisionResponce = copy.ignoresCollisionResponce;
            this.shape            = copy.shape;
            this.massInfo         = copy.massInfo;
            this.coefficients     = copy.coefficients;
            this.collisionIgnorer = copy.collisionIgnorer;
            this.matrices         = copy.matrices.Duplicate();
            this.state            = copy.state.Duplicate();
            this.lifetime         = copy.lifetime.Duplicate();

            this.transformation = copy.transformation;
            this.linearDamping  = copy.linearDamping;
            this.angularDamping = copy.angularDamping;

            this.ignoresCollisionResponce = copy.ignoresCollisionResponce;
            this.ignoresGravity           = copy.ignoresGravity;
            this.isCollidable             = copy.isCollidable;
            this.ignoresGravity           = copy.ignoresGravity;
            this.isTransformed            = copy.isTransformed;

            this.tag = (copy.tag is ICloneable) ? (((ICloneable)copy.tag).Clone()) : (copy.tag);
        }
Exemplo n.º 10
0
        void DemoW()
        {
            BeginDemoChange();
            Reset(false);
            AddGravityField();
            Coefficients o = coefficients;
            coefficients = new Coefficients(1, .5f);
            AddFloor(new ALVector2D(0, new Vector2D(700, 750)));
            Body b1 = AddRectangle(750, 100, Scalar.PositiveInfinity, new ALVector2D(0, 0, 750 / 2));
            b1.IgnoresGravity = true;
            Body b2 = AddRectangle(750, 100, Scalar.PositiveInfinity, new ALVector2D(0, 1024, 750 / 2));
            b2.IgnoresGravity = true;
            coefficients = new Coefficients(.7f, .05f);


            for (int x = 60; x < 80; x += 10)
            {
                for (int y = -2000; y < 700; y += 12)
                {
                    Body g = AddCircle(5, 7, 3, new ALVector2D(0, x, y));
                    g.State.Velocity.Angular = 1;
                  //  g.State.Velocity.Linear = new Vector2D(0, 500);
                }
            }
            coefficients = o;

            EndDemoChange();
        }
Exemplo n.º 11
0
 public BaseModelBody(PhysicsState state, IShape shape, double mass, Coefficients coefficients, Lifespan lifetime, Guid modelId)
     : this(state, shape, new MassInfo { Mass = mass }, coefficients, lifetime, modelId)
 {
 }
Exemplo n.º 12
0
 public BoneBody(PhysicsState state, IShape shape, MassInfo massInfo, Coefficients coefficients, Lifespan lifetime, Guid modelId)
     : base(state, shape, massInfo, coefficients, lifetime, modelId)
 {
 }
Exemplo n.º 13
0
 public ChainMember(PhysicsState state, IShape shape, MassInfo mass, Coefficients coefficients, Lifespan lifetime, Guid modelId)
     : base(state, shape, mass, coefficients, lifetime, modelId)
 {
 }