コード例 #1
0
        public PhysicsPlayer(GamePhysics physicsSystem, Vector2 position)
            : base(physicsSystem, BodyType.Dynamic, position, 0f, true, Mass, GravityScale, Friction, Restitution)
        {
            var bodyPosition = new Vector2(BodyX, BodyY);
            var bodyHalf     = new Vector2(BodyWidth, BodyHeight) * 0.5f;
            var bodyShape    = new PolygonShape(1f)
            {
                Vertices = new Vertices(new[] {
                    bodyPosition + new Vector2(-bodyHalf.X, -bodyHalf.Y),
                    bodyPosition + new Vector2(bodyHalf.X, -bodyHalf.Y),
                    bodyPosition + new Vector2(bodyHalf.X, bodyHalf.Y),
                    bodyPosition + new Vector2(-bodyHalf.X, bodyHalf.Y)
                })
            };

            Body.CreateFixture(bodyShape);

            var footShape = new CircleShape(FootRadius, 1f)
            {
                Position = new Vector2(FootX, FootY)
            };

            Body.CreateFixture(footShape);

            groundSensor = new PlatformSensor(
                physicsSystem.World,
                new Vector2(GroundSensorWidth, GroundSensorHeight),
                new Vector2(GroundSensorX, GroundSensorY),
                new[] {
                new PlatformSensor.ScopeSensorData {
                    From = new Vector2(-GroundScopeSensorXOffset, GroundScopeSensorYFrom),
                    To   = new Vector2(-GroundScopeSensorXOffset, GroundScopeSensorYTo)
                },
                new PlatformSensor.ScopeSensorData {
                    From = new Vector2(0f, GroundScopeSensorYFrom),
                    To   = new Vector2(0f, GroundScopeSensorYTo)
                },
                new PlatformSensor.ScopeSensorData {
                    From = new Vector2(GroundScopeSensorXOffset, GroundScopeSensorYFrom),
                    To   = new Vector2(GroundScopeSensorXOffset, GroundScopeSensorYTo)
                }
            }
                );
            leftWallSensor = new PlatformSensor(
                physicsSystem.World,
                new Vector2(LeftWallSensorWidth, LeftWallSensorHeight),
                new Vector2(LeftWallSensorX, LeftWallSensorY)
                );
            rightWallSensor = new PlatformSensor(
                physicsSystem.World,
                new Vector2(RightWallSensorWidth, RightWallSensorHeight),
                new Vector2(RightWallSensorX, RightWallSensorY)
                );
        }
コード例 #2
0
 public PhysicsDynamicBody(
     GamePhysics physics,
     BodyType bodyType    = BodyType.Dynamic,
     Vector2 position     = default(Vector2),
     float rotation       = 0f,
     bool isFixedRotation = false,
     float mass           = 20f,
     float gravityScale   = 1f,
     float friction       = 0.2f,
     float restitution    = 0f
     ) : base(physics, bodyType, position, rotation, isFixedRotation, mass, gravityScale, friction, restitution)
 {
 }
コード例 #3
0
        public PhysicsPlatform(GamePhysics physicsSystem, Platform platform)
            : base(physicsSystem, BodyType.Static, platform.Position.Vector2, 0f, isFixedRotation: true)
        {
            var vertices = new Vector2[platform.Vertices.Count];

            for (var i = 0; i < platform.Vertices.Count; i++)
            {
                vertices[i] = platform.Vertices[i].Vector2;
            }

            var bodyShape = new PolygonShape(1f)
            {
                Vertices = new Vertices(vertices)
            };

            Fixture          = Body.CreateFixture(bodyShape);
            Fixture.UserData = new PhysicsBodyData()
            {
                IsPlatform = true
            };
        }
コード例 #4
0
        public PhysicsBody(
            GamePhysics physics,
            BodyType bodyType    = BodyType.Static,
            Vector2 position     = default(Vector2),
            float rotation       = 0f,
            bool isFixedRotation = false,
            float mass           = 20f,
            float gravityScale   = 1f,
            float friction       = 0.2f,
            float restitution    = 0f
            )
        {
            this.physics = physics;

            physics.Objects.Add(this);

            Body               = BodyFactory.CreateBody(physics.World, position, rotation);
            Body.BodyType      = bodyType;
            Body.FixedRotation = isFixedRotation;
            Body.Mass          = mass;
            Body.GravityScale  = gravityScale;
            Body.Friction      = friction;
            Body.Restitution   = restitution;
        }