Esempio n. 1
0
        private static void CreateBullets(Body ship)
        {
            Func<Vector2, Body> createBullet = pos =>
            {
                var body = new Body(world);
                body.BodyType = BodyType.Dynamic;
                body.IsBullet = true;

                var shape = new FarseerCircleShape(0.15f / 4, 1);
                body.CreateFixture(shape);

                body.Position = ship.Position + ship.GetWorldVector(pos);
                body.Rotation = ship.Rotation;
                body.ApplyForce(body.GetWorldVector(new Vector2(0.0f, -15f)));

                body.OnCollision += (a, b, contact) =>
                {
                    world.RemoveBody(body);
                    return false;
                };

                return body;
            };

            createBullet(new Vector2(-0.575f, -0.20f));
            createBullet(new Vector2(0.575f, -0.20f));
        }
        private SensorTest()
        {
            {
                Body ground = BodyFactory.CreateBody(World);

                {
                    EdgeShape shape = new EdgeShape(new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
                    ground.CreateFixture(shape);
                }

                {
                    CircleShape shape = new CircleShape(5.0f, 1);
                    shape.Position = new Vector2(0.0f, 10.0f);

                    _sensor = ground.CreateFixture(shape);
                    _sensor.IsSensor = true;
                }
            }

            {
                CircleShape shape = new CircleShape(1.0f, 1);

                for (int i = 0; i < Count; ++i)
                {
                    _touching[i] = false;
                    _bodies[i] = BodyFactory.CreateBody(World);
                    _bodies[i].BodyType = BodyType.Dynamic;
                    _bodies[i].Position = new Vector2(-10.0f + 3.0f * i, 20.0f);
                    _bodies[i].UserData = i;

                    _bodies[i].CreateFixture(shape);
                }
            }
        }
Esempio n. 3
0
		public void LoadContent(ContentManager content, World world, Vector2 position, Vector2 size)
		{
			body = BodyFactory.CreateRectangle(world, size.X, size.Y, 1f);

			body.FixedRotation = true;

			body.FixtureList[0].UserData = 9000;

			body.Position = ConvertUnits.ToSimUnits(position);

			body.BodyType = BodyType.Dynamic;

            CircleShape circle1 = new CircleShape(size.X / 4, 1f);
            CircleShape circle2 = new CircleShape(size.Y / 6, 1f);
            CircleShape circle3 = new CircleShape(size.Y / 6, 1f);

            circle1.Position = new Vector2(0, -size.Y / 3);
            circle2.Position = new Vector2(-1.5f * size.X / 5, -size.Y / 10);
			circle3.Position = new Vector2(-0.4f * size.X / 5, -size.Y / 10);

			head = body.CreateFixture(circle1);
			hands[0] = body.CreateFixture(circle2);
			hands[1] = body.CreateFixture(circle3);

			head.UserData = (int)10000;
			hands[0].UserData = (int)11000;
			hands[1].UserData = (int)11000;

			image.LoadContent(content, "Graphics/tezka", Color.White, position);

			image.ScaleToMeters(size);

			image.position = ConvertUnits.ToDisplayUnits(body.Position);
		}
Esempio n. 4
0
        private static void CreateBullets(Body ship)
        {
            Func <Vector2, Body> createBullet = pos =>
            {
                var body = new Body(world);
                body.BodyType = BodyType.Dynamic;
                body.IsBullet = true;

                var shape = new FarseerCircleShape(0.15f / 4, 1);
                body.CreateFixture(shape);

                body.Position = ship.Position + ship.GetWorldVector(pos);
                body.Rotation = ship.Rotation;
                body.ApplyForce(body.GetWorldVector(new Vector2(0.0f, -15f)));

                body.OnCollision += (a, b, contact) =>
                {
                    world.RemoveBody(body);
                    return(false);
                };

                return(body);
            };

            createBullet(new Vector2(-0.575f, -0.20f));
            createBullet(new Vector2(0.575f, -0.20f));
        }
        private OneSidedPlatformTest()
        {
            //Ground
            BodyFactory.CreateEdge(World, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));

            // Platform
            {
                Body body = BodyFactory.CreateBody(World);
                body.Position = new Vector2(0.0f, 10.0f);

                PolygonShape shape = new PolygonShape(1);
                shape.SetAsBox(3.0f, 0.5f);
                _platform = body.CreateFixture(shape);

                _top = 10.0f + 0.5f;
            }

            // Actor
            {
                Body body = BodyFactory.CreateBody(World);
                body.BodyType = BodyType.Dynamic;
                body.Position = new Vector2(0.0f, 12.0f);

                _radius = 0.5f;
                CircleShape shape = new CircleShape(_radius, 20);
                _character = body.CreateFixture(shape);

                body.LinearVelocity = new Vector2(0.0f, -50.0f);
            }
        }
Esempio n. 6
0
        private CircleBenchmarkTest()
        {
            Body ground = BodyFactory.CreateBody(World);

            // Floor
            EdgeShape ashape = new EdgeShape(new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
            ground.CreateFixture(ashape);

            // Left wall
            ashape = new EdgeShape(new Vector2(-40.0f, 0.0f), new Vector2(-40.0f, 45.0f));
            ground.CreateFixture(ashape);

            // Right wall
            ashape = new EdgeShape(new Vector2(40.0f, 0.0f), new Vector2(40.0f, 45.0f));
            ground.CreateFixture(ashape);

            // Roof
            ashape = new EdgeShape(new Vector2(-40.0f, 45.0f), new Vector2(40.0f, 45.0f));
            ground.CreateFixture(ashape);

            CircleShape shape = new CircleShape(1.0f, 1);

            for (int i = 0; i < XCount; i++)
            {
                for (int j = 0; j < YCount; ++j)
                {
                    Body body = BodyFactory.CreateBody(World);
                    body.BodyType = BodyType.Dynamic;
                    body.Position = new Vector2(-38f + 2.1f * i, 2.0f + 2.0f * j);

                    body.CreateFixture(shape);
                }
            }
        }
        public ComputerControlledTank(
            ISoundManager soundManager,
            World world, 
            Collection<IDoodad> doodads, 
            Team team, 
            Vector2 position, 
            float rotation,
            Random random, 
            DoodadFactory doodadFactory,
            IEnumerable<Waypoint> waypoints)
            : base(soundManager, world, doodads, team, position, rotation, doodadFactory)
        {
            this.world = world;
            this.random = random;
            this.states = new Dictionary<Type, ITankState>();
            this.states.Add(typeof(MovingState), new MovingState(world, this.Body, this, waypoints, random));
            this.states.Add(typeof(AttackingState), new AttackingState(world, this.Body, this));
            this.states.Add(typeof(TurningState), new TurningState(this.Body, this));
            this.currentState = this.states[typeof(MovingState)];
            this.currentState.StateChanged += this.OnStateChanged;
            this.currentState.NavigateTo();

            this.sensor = BodyFactory.CreateBody(world, this.Position);

            var shape = new CircleShape(6, 0);
            Fixture sensorFixture = this.sensor.CreateFixture(shape);
            sensorFixture.Friction = 1f;
            sensorFixture.IsSensor = true;
            sensorFixture.CollisionCategories = PhysicsConstants.SensorCategory;
            sensorFixture.CollidesWith = PhysicsConstants.PlayerCategory | PhysicsConstants.ObstacleCategory |
                                         PhysicsConstants.MissileCategory;
        }
Esempio n. 8
0
File: Ship.cs Progetto: det/Rimbalzo
        public Ship(World world, SpawnData spawn, int id)
        {
            Ball = null;
            Id = id;
            IsThrusting = false;
            IsReversing = false;
            IsBoosting = false;
            IsLeftTurning = false;
            IsRightTurning = false;
            IsShooting = false;
            IsBlocked = false;
            IsBlockedFrame = false;

            Color = spawn.Color;
            var body = new Body(world);

            body.Rotation = FMath.Atan2(-spawn.Position.Y, -spawn.Position.X);
            body.Position = spawn.Position;
            var shape = new CircleShape(radius, 1f);
            body.BodyType = BodyType.Dynamic;
            body.FixedRotation = true;
            Fixture = body.CreateFixture(shape);
            Fixture.Restitution = restitution;

            var bodyGravity = new Body(world);
            bodyGravity.Position = spawn.Position;
            var shapeGravity = new CircleShape(radiusGravity, 1f);
            bodyGravity.FixedRotation = true;
            FixtureGravity = bodyGravity.CreateFixture(shapeGravity);
            FixtureGravity.IsSensor = true;
        }
        private bool LoadCollider()
        {
            /* find a mesh component to create box from */
            var meshComponent = this.GameObject.Components.FirstOrDefault(c => c is MeshComponent) as MeshComponent;
            if (meshComponent == null)
            {
                return false;
            }

            if (!meshComponent.IsLoaded) meshComponent.Load();

            float maxExtend = float.MinValue;

            foreach (var vertex in meshComponent.Vertices)
            {
                if (vertex.X * GameObject.Scale.X > maxExtend) maxExtend = vertex.X * GameObject.Scale.X;
                if (vertex.Y * GameObject.Scale.Y > maxExtend) maxExtend = vertex.Y * GameObject.Scale.Y;
                if (vertex.Z * GameObject.Scale.Z > maxExtend) maxExtend = vertex.Z * GameObject.Scale.Z;
            }

            float max = maxExtend;

            CollisionShape = new CircleShape(maxExtend, 1.0f);

            return true;
        }
        private bool LoadCollider()
        {
            /* find a mesh component to create box from */
            var meshComponent = this.GameObject.Components.FirstOrDefault(c => c is MeshComponent) as MeshComponent;
            if (meshComponent == null)
            {
                return false;
            }

            if (!meshComponent.IsLoaded) meshComponent.Load();

            Vector2 vMin = new Vector2(float.MaxValue, float.MaxValue);
            Vector2 vMax = new Vector2(float.MinValue, float.MinValue);

            foreach (var vertex in meshComponent.Vertices)
            {
                if (vertex.X * GameObject.Scale.X < vMin.X) vMin.X = vertex.X * GameObject.Scale.X;
                if (vertex.X * GameObject.Scale.X > vMax.X) vMax.X = vertex.X * GameObject.Scale.X;

                if (vertex.Y * GameObject.Scale.Y < vMin.Y) vMin.Y = vertex.Y * GameObject.Scale.Y;
                if (vertex.Y * GameObject.Scale.Y > vMax.Y) vMax.Y = vertex.Y * GameObject.Scale.Y;
            }

            Radius = (vMax.X - vMin.X) / 2.0f;

            CollisionShape = new CircleShape(Radius, 15.0f);

            return true;
        }
Esempio n. 11
0
        public Missile(
            ISoundManager soundManager, 
            World world, 
            Collection<IDoodad> doodads, 
            int numberOfBounces,
            Team team, 
            Vector2 position, 
            float rotation, 
            DoodadFactory doodadFactory)
        {
            this.soundManager = soundManager;
            this.doodadFactory = doodadFactory;
            this.world = world;
            this.doodads = doodads;
            this.numberOfBounces = numberOfBounces;
            this.body = BodyFactory.CreateBody(world, position, this);
            this.body.BodyType = BodyType.Dynamic;
            this.body.FixedRotation = true;

            CircleShape shape = new CircleShape(5 / Constants.PixelsPerMeter, 0.1f);
            Fixture fixture = body.CreateFixture(shape);
            fixture.Restitution = 1;
            fixture.Friction = 0;
            fixture.CollisionCategories = PhysicsConstants.MissileCategory;
            fixture.CollidesWith = PhysicsConstants.EnemyCategory | PhysicsConstants.PlayerCategory |
                                   PhysicsConstants.ObstacleCategory | PhysicsConstants.MissileCategory |
                                   PhysicsConstants.SensorCategory;
            obstacleCollisionCtr = 0;

            Vector2 force = new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation)) * 3;
            this.body.ApplyForce(force);
        }
Esempio n. 12
0
        protected Bullet(Ship parent, Vector2 offset, Vector2 speed, string texture)
            : base(parent, texture, parent.Size)
        {
            Sprite.Origin = new Vector2f(Sprite.Texture.Size.X / 2f, 0);

            #region Body Initialize
            Body = new Body(State.World);
            Body.BodyType = BodyType.Dynamic;
            Body.IsBullet = true;

            var shape = new CircleShape((0.15f / 4) * parent.Size, 0);
            Body.CreateFixture(shape);
            Body.Position = parent.Body.Position + parent.Body.GetWorldVector(offset);
            Body.Rotation = parent.Body.Rotation;

            Body.OnCollision += (a, b, contact) =>
            {
                if (!Collision(a, b, contact))
                    return false;

                Dead = true;
                return false;
            };

            Body.LinearVelocity = Parent.Body.LinearVelocity + Parent.Body.GetWorldVector(speed);
            Body.UserData = this;
            #endregion
        }
Esempio n. 13
0
 private void onGridSizeChanged(object sender, SizeChangedEventArgs e) {
   Debug.WriteLine("width: " + LayoutRoot.ActualWidth + " height: " + LayoutRoot.ActualHeight);
   if (ball == null) {
     float width = (float)LayoutRoot.ActualWidth;
     float height = (float)LayoutRoot.ActualHeight;
     ballBody = BodyFactory.CreateBody(world, new Vector2(ConvertUnits.ToSimUnits(width / 2f), ConvertUnits.ToSimUnits(height / 2f)));
     ballBody.BodyType = BodyType.Dynamic;
     ballBody.LinearDamping = 1f;
     CircleShape circleShape = new CircleShape(ConvertUnits.ToSimUnits(8f), 1f);
     Fixture fixture = ballBody.CreateFixture(circleShape);
     fixture.OnCollision += OnBalCollision;
     ball = new Ball(canvas, 8, new System.Windows.Point(width / 2f, height / 2f));
   }
   if (level == null) {
     level = new Level(currentLevel, canvas);
     Body wallBody;
     System.Windows.Point position;
     foreach (Wall wall in level.getWalls()) {
       position = wall.getPosition();
       wallBody = BodyFactory.CreateRectangle(
         world, 
         ConvertUnits.ToSimUnits(wall.getWidth()),
         ConvertUnits.ToSimUnits(wall.getHeight()),
         0.001f,
         new Vector2(ConvertUnits.ToSimUnits(position.X + wall.getWidth() / 2f), ConvertUnits.ToSimUnits(position.Y + wall.getHeight() / 2f))
       );
       wallBody.Restitution = 0.25f;
     }
     ballBody.Position = new Vector2(ConvertUnits.ToSimUnits(level.getStart().X), ConvertUnits.ToSimUnits(level.getStart().Y));
     ball.setPosition(new System.Windows.Point(ConvertUnits.ToDisplayUnits(ballBody.Position.X), ConvertUnits.ToDisplayUnits(ballBody.Position.Y)));
   }
 }
Esempio n. 14
0
		public override void LoadContent(World world, ContentManager content, Vector2 position, PhysicsScene physicsScene)
		{
			base.LoadContent(world, content, position, physicsScene);

			Vector2 size = this.size * sizeRatio;

			CircleShape circle1 = new CircleShape(0.1f, 1f);
			CircleShape circle2 = new CircleShape(0.1f, 1f);
			CircleShape circle3 = new CircleShape(0.1f, 1f);
			CircleShape circle4 = new CircleShape(0.1f, 1f);

			circle1.Position = new Vector2(-((size.X / 2) + 0.2f), (size.Y + 0.1f) / 2);
			circle2.Position = new Vector2((size.X / 2) + 0.2f, (size.Y + 0.1f) / 2);
			circle3.Position = new Vector2(-((size.X / 2) + 0.2f), (size.Y - 0.3f) / 2);
			circle4.Position = new Vector2((size.X / 2) + 0.2f, (size.Y - 0.3f) / 2);

			sensors[0] = body.CreateFixture(circle1, (int)-(100 + id));
			sensors[1] = body.CreateFixture(circle2, (int)-(200 + id));
			sensors[2] = body.CreateFixture(circle3, (int)-(300 + id));
			sensors[3] = body.CreateFixture(circle4, (int)-(400 + id));

			sensors[0].IsSensor = true;
			sensors[1].IsSensor = true;
			sensors[2].IsSensor = true;
			sensors[3].IsSensor = true;
		}
Esempio n. 15
0
        public static Fixture AttachCircle(float radius, float density, Body body, object userData)
        {
            if (radius <= 0)
                throw new ArgumentOutOfRangeException("radius", "Radius must be more than 0 meters");

            CircleShape circleShape = new CircleShape(radius, density);
            return body.CreateFixture(circleShape, userData);
        }
        public override Shape Clone()
        {
            CircleShape shape = new CircleShape();
            shape.ShapeType = ShapeType;
            shape.Radius = Radius;
            shape.Position = Position;

            return shape;
        }
Esempio n. 17
0
		public static Fixture AttachCircle( float radius, float density, Body body, Vector2 offset, object userData = null )
		{
			if( radius <= 0 )
				throw new ArgumentOutOfRangeException( nameof( radius ), "Radius must be more than 0 meters" );

			var circleShape = new CircleShape( radius, density );
			circleShape.position = offset;
			return body.createFixture( circleShape, userData );
		}
Esempio n. 18
0
        private ControllerTest()
        {
            //Ground
            BodyFactory.CreateEdge(World, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));

            //Create the gravity controller
            GravityController gravity = new GravityController(20);
            gravity.DisabledOnGroup = 3;
            gravity.EnabledOnGroup = 2;
            gravity.DisabledOnCategories = Category.Cat2;
            gravity.EnabledOnCategories = Category.Cat3;

            World.AddController(gravity);

            Vector2 startPosition = new Vector2(-10, 2);
            Vector2 offset = new Vector2(2);

            //Create the planet
            Body planet = BodyFactory.CreateBody(World);
            planet.Position = new Vector2(0, 20);

            CircleShape planetShape = new CircleShape(2, 1);
            planet.CreateFixture(planetShape);

            //Add the planet as the one that has gravity
            gravity.AddBody(planet);

            //Create 10 smaller circles
            for (int i = 0; i < 10; i++)
            {
                Body circle = BodyFactory.CreateBody(World);
                circle.BodyType = BodyType.Dynamic;
                circle.Position = startPosition + offset * i;
                circle.SleepingAllowed = false;

                CircleShape circleShape = new CircleShape(1, 0.1f);
                Fixture fix = circle.CreateFixture(circleShape);
                fix.CollisionCategories = Category.Cat3;
                fix.CollisionGroup = 2;

                if (i == 4)
                {
                    circle.ControllerFilter.IgnoreController(ControllerType.GravityController);
                }

                if (i == 5)
                {
                    fix.CollisionCategories = Category.Cat2;
                }

                if (i == 6)
                {
                    fix.CollisionGroup = 3;
                }
            }
        }
Esempio n. 19
0
 public override Shape Clone()
 {
     CircleShape shape = new CircleShape();
     shape._radius = Radius;
     shape._density = _density;
     shape._position = _position;
     shape.ShapeType = ShapeType;
     shape.MassData = MassData;
     return shape;
 }
Esempio n. 20
0
        public override void Start()
        {
            m_params     = Engine.AssetManager.GetAsset <BallParameters>("Game/Ball.lua::Ball");
            m_properties = new BallProperties();

            m_effects = new List <BallEffect>();

            m_bodyCmp = new RigidBodyComponent();
            FarseerPhysics.Collision.Shapes.CircleShape bodyShape = new FarseerPhysics.Collision.Shapes.CircleShape(ConvertUnits.ToSimUnits(m_params.Content.Radius), 1.0f);
            Fixture fix = new Fixture(m_bodyCmp.Body, bodyShape);

            m_bodyCmp.Body.AngularDamping = m_params.Content.Physic.AngularDamping;
            m_bodyCmp.Body.Mass           = m_params.Content.Physic.Mass;
            m_bodyCmp.Body.LinearDamping  = m_params.Content.Physic.LinearDamping;
            m_bodyCmp.Body.Restitution    = m_params.Content.Physic.Restitution;
            m_bodyCmp.Body.IsBullet       = true;

            m_bodyCmp.Body.CollisionCategories = (Category)CollisionType.Gameplay | (Category)CollisionType.Ball;

            Owner.Attach(m_bodyCmp);

            if (Game.Arena.ColorScheme.Dark == true)
            {
                m_ballSprite = Sprite.Create("Graphics/ballSprite.lua::SpriteDark");
            }
            else
            {
                m_ballSprite = Sprite.Create("Graphics/ballSprite.lua::Sprite");
            }

            Owner.Attach(new SpriteComponent(m_ballSprite, "ArenaOverlay9"));

            m_ballBashSprite         = Sprite.Create("Graphics/ballSprite.lua::SpriteBash");
            m_ballBashSprite.Alpha   = 0;
            m_ballBashSprite.Playing = true;
            Owner.Attach(new SpriteComponent(m_ballBashSprite, "ArenaOverlay9"));


            m_ballTrail = new BallTrailFx(this);
            Owner.Attach(m_ballTrail);

            m_bodyCmp.Body.FixedRotation = true;

            m_bodyCmp.UserData.Add("Tag", "Ball");

            m_bodyCmp.OnCollision += new CollisionEvent(m_bodyCmp_OnCollision);

            m_player     = null;
            m_lastPlayer = null;

            m_audioCmpBallBounce = new AudioComponent("Audio/Sounds.lua::BallBounce");
            Owner.Attach(m_audioCmpBallBounce);
            m_audioCmpBallPlayerSnap = new AudioComponent("Audio/Sounds.lua::BallPlayerSnap");
            Owner.Attach(m_audioCmpBallPlayerSnap);
        }
Esempio n. 21
0
        public void DrawShape(Fixture fixture, Transform xf, Color color)
        {
            switch (fixture.Shape.ShapeType)
            {
            case ShapeType.Circle:
            {
                CircleShape circle = (CircleShape)fixture.Shape;

                Vector2 center = MathUtils.Mul(ref xf, circle.Position);
                float   radius = circle.Radius;
                Vector2 axis   = MathUtils.Mul(xf.q, new Vector2(1.0f, 0.0f));

                DrawSolidCircle(center, radius, axis, color);
            }
            break;

            case ShapeType.Polygon:
            {
                PolygonShape poly        = (PolygonShape)fixture.Shape;
                int          vertexCount = poly.Vertices.Count;
                Debug.Assert(vertexCount <= Settings.MaxPolygonVertices);

                for (int i = 0; i < vertexCount; ++i)
                {
                    _tempVertices[i] = MathUtils.Mul(ref xf, poly.Vertices[i]);
                }

                DrawSolidPolygon(_tempVertices, vertexCount, color);
            }
            break;


            case ShapeType.Edge:
            {
                EdgeShape edge = (EdgeShape)fixture.Shape;
                Vector2   v1   = MathUtils.Mul(ref xf, edge.Vertex1);
                Vector2   v2   = MathUtils.Mul(ref xf, edge.Vertex2);
                DrawSegment(v1, v2, color);
            }
            break;

            case ShapeType.Chain:
            {
                ChainShape chain = (ChainShape)fixture.Shape;

                for (int i = 0; i < chain.Vertices.Count - 1; ++i)
                {
                    Vector2 v1 = MathUtils.Mul(ref xf, chain.Vertices[i]);
                    Vector2 v2 = MathUtils.Mul(ref xf, chain.Vertices[i + 1]);
                    DrawSegment(v1, v2, color);
                }
            }
            break;
            }
        }
Esempio n. 22
0
        public virtual void CreateFixtureFromRadius(float radius)
        {
            float hx = (Sprite.Size.X / 2f);
            float hy = (Sprite.Size.Y / 2f);

            Sprite.Origin = new Vector2(hx, hy);

            CircleShape c = new CircleShape(radius, 1);
            c.Position += new Vector2(radius, radius);
            CreateFixture(c);
        }
Esempio n. 23
0
        private static Body CreateAsteroid()
        {
            var body = new Body(world);
            body.BodyType = BodyType.Dynamic;
            body.LinearDamping = 1f;
            body.AngularDamping = 1f;

            var shape = new FarseerCircleShape(1, 10);
            body.CreateFixture(shape);
            return body;
        }
Esempio n. 24
0
        private RevoluteTest()
        {
            //Ground
            var ground = BodyFactory.CreateEdge(World, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));

            {
                //The big fixed wheel
                CircleShape shape = new CircleShape(5.0f, 5);

                Body body = BodyFactory.CreateBody(World);
                body.Position = new Vector2(-10.0f, 15.0f);
                body.BodyType = BodyType.Dynamic;

                body.CreateFixture(shape);

                _fixedJoint = new FixedRevoluteJoint(body, Vector2.Zero, body.Position);
                _fixedJoint.MotorSpeed = 0.25f * Settings.Pi;
                _fixedJoint.MaxMotorTorque = 5000.0f;
                _fixedJoint.MotorEnabled = true;
                World.AddJoint(_fixedJoint);

                // The small gear attached to the big one
                Body body1 = BodyFactory.CreateGear(World, 1.5f, 10, 0.1f, 1, 1);
                body1.Position = new Vector2(-10.0f, 12.0f);
                body1.BodyType = BodyType.Dynamic;

                _joint = new RevoluteJoint(body, body1, body.GetLocalPoint(body1.Position),
                                           Vector2.Zero);
                _joint.MotorSpeed = 1.0f * Settings.Pi;
                _joint.MaxMotorTorque = 5000.0f;
                _joint.MotorEnabled = true;
                _joint.CollideConnected = false;

                World.AddJoint(_joint);

                CircleShape circle_shape = new CircleShape(3.0f, 5);
                var circleBody = BodyFactory.CreateBody(World);
                circleBody.Position = new Vector2(5.0f, 30.0f);
                circleBody.BodyType = BodyType.Dynamic;
                circleBody.CreateFixture(circle_shape);
                PolygonShape polygonShape = new PolygonShape(2.0f);
                polygonShape.SetAsBox(10.0f, 0.2f, new Vector2(-10.0f, 0.0f), 0.0f);
                var polygon_body = BodyFactory.CreateBody(World);
                polygon_body.Position = new Vector2(20.0f, 10.0f);
                polygon_body.BodyType = BodyType.Dynamic;
                polygon_body.IsBullet = true;
                polygon_body.CreateFixture(polygonShape);
                RevoluteJoint rjd = new RevoluteJoint(ground, polygon_body, new Vector2(20.0f, 10.0f));
                rjd.LowerLimit = -0.25f * Settings.Pi;
                rjd.UpperLimit = 0.0f;
                rjd.LimitEnabled = true;
                World.AddJoint(rjd);
            }
        }
 public RoundPhysicsObject(World world, Vector2 position, float density,float restitution, Sprite sprite)
     : base(sprite)
 {
     body = new Body(world);
     CircleShape circleShape = new CircleShape(ConvertUnits.ToSimUnits(sprite.Height/2),density);
     body.CreateFixture(circleShape);
     body.BodyType = BodyType.Dynamic;
     body.Position = ConvertUnits.ToSimUnits(position);
     body.Friction = 0.4f;
     body.Restitution = restitution;
 }
Esempio n. 26
0
        public override void OnCreated(AsgardBase instance, Entity entity)
        {
            var world = instance.LookupSystem<Midgard>();
            var manager = world.EntityManager;
            var body = world.CreateComponent(entity, BodyDef).Body;

            CircleShape shape = new CircleShape(1, 1);
            var fix = body.CreateFixture(shape);
            fix.Restitution = 1;
            fix.Friction = 1;
        }
Esempio n. 27
0
        private PathTest()
        {
            //Single body that moves around path
            _movingBody = BodyFactory.CreateBody(World);
            _movingBody.Position = new Vector2(-25, 25);
            _movingBody.BodyType = BodyType.Dynamic;
            _movingBody.CreateFixture(new PolygonShape(PolygonTools.CreateRectangle(0.5f, 0.5f), 1));

            //Static shape made up of bodies
            _path = new Path();
            _path.Add(new Vector2(0, 20));
            _path.Add(new Vector2(5, 15));
            _path.Add(new Vector2(20, 18));
            _path.Add(new Vector2(15, 1));
            _path.Add(new Vector2(-5, 14));
            _path.Closed = true;

            CircleShape shape = new CircleShape(0.25f, 1);

            PathManager.EvenlyDistributeShapesAlongPath(World, _path, shape, BodyType.Static, 100);

            //Smaller shape that is movable. Created from small rectangles and circles.
            Vector2 xform = new Vector2(0.5f, 0.5f);
            _path.Scale(ref xform);
            xform = new Vector2(5, 5);
            _path.Translate(ref xform);

            List<Shape> shapes = new List<Shape>(2);
            shapes.Add(new PolygonShape(PolygonTools.CreateRectangle(0.5f, 0.5f, new Vector2(-0.1f, 0), 0), 1));
            shapes.Add(new CircleShape(0.5f, 1));

            List<Body> bodies = PathManager.EvenlyDistributeShapesAlongPath(World, _path, shapes, BodyType.Dynamic, 20);

            //Attach the bodies together with revolute joints
            PathManager.AttachBodiesWithRevoluteJoint(World, bodies, new Vector2(0, 0.5f), new Vector2(0, -0.5f), true,
                                                      true);

            xform = new Vector2(-25, 0);
            _path.Translate(ref xform);

            Body body = BodyFactory.CreateBody(World);
            body.BodyType = BodyType.Static;

            //Static shape made up of edges
            PathManager.ConvertPathToEdges(_path, body, 25);
            body.Position -= new Vector2(0, 10);

            xform = new Vector2(0, 15);
            _path.Translate(ref xform);

            PathManager.ConvertPathToPolygon(_path, body, 1, 50);
        }
Esempio n. 28
0
        private static Body CreateAsteroid()
        {
            var body = new Body(world);

            body.BodyType       = BodyType.Dynamic;
            body.LinearDamping  = 1f;
            body.AngularDamping = 1f;

            var shape = new FarseerCircleShape(1, 10);

            body.CreateFixture(shape);
            return(body);
        }
Esempio n. 29
0
        private void CreateCircle()
        {
            const float radius = 2f;
            CircleShape shape = new CircleShape(radius, 1);
            shape.Position = Vector2.Zero;

            Body body = BodyFactory.CreateBody(World);
            body.BodyType = BodyType.Dynamic;
            body.Position = new Vector2(Rand.RandomFloat(), 3.0f + Rand.RandomFloat());

            Fixture fixture = body.CreateFixture(shape);
            fixture.Friction = 0;
        }
Esempio n. 30
0
        public GamePage()
        {
            InitializeComponent();

            name.Text = Player.GetInstance.name;
            score.Text = Player.GetInstance.score.ToString();

            World world = new World(new Vector2(0, -1));
            Body myBody = BodyFactory.CreateBody(world, new Vector2(10, 0));
            CircleShape circleShape = new CircleShape(0.5f,1.0f);

            Fixture fixture = myBody.CreateFixture(circleShape);
        }
Esempio n. 31
0
        public override void LoadContent()
        {
            base.LoadContent();

            World.Gravity = new Vector2(0, 140);
            projection = Matrix.CreateOrthographicOffCenter(0f, ScreenManager.GraphicsDevice.Viewport.Width, ScreenManager.GraphicsDevice.Viewport.Height, 0f, 0f, 1f);
            hookpointmanager = new HookPointManager(World);

            MaterialType hookpointmaterial = MaterialType.Blank;

            swingerbody = BodyFactory.CreateBody(World, new Vector2(3, 10));
            swinger = FixtureFactory.AttachCircle(1, 40, swingerbody);
            swinger.Body.BodyType = BodyType.Dynamic;
            swinger.Friction = 0;

            body3 = BodyFactory.CreateBody(World, new Vector2(-4, -10));
            body3.IsStatic = true;
            CircleShape circleShape3 = new CircleShape(.4f, .3f);
            Fixture fixture3 = body3.CreateFixture(circleShape3, hookpointmaterial);
            body3.IgnoreGravity = true;
            fixture3.Body.BodyType = BodyType.Static;

            body2 = BodyFactory.CreateBody(World, new Vector2(-8, -10));
            body2.IsStatic = true;
            CircleShape circleShape2 = new CircleShape(.4f, .3f);
            fixture2 = body2.CreateFixture(circleShape2, hookpointmaterial);
            body2.IgnoreGravity = true;
            fixture2.Body.BodyType = BodyType.Static;


            joint1 = JointFactory.CreateSliderJoint(World, swingerbody, fixture3.Body, Vector2.Zero, Vector2.Zero, 4, 5);

            _border = new Border(World, this, ScreenManager.GraphicsDevice.Viewport);

            //SetUserAgent(swingerbody, 100f, 100f);
  
            // create sprite based on body
            swingersprite = new Sprite(ScreenManager.Assets.TextureFromShape(swingerbody.FixtureList[0].Shape,
                                                                                MaterialType.Dots,
                                                                                Color.Red, 2f));

            body3sprite = new Sprite(ScreenManager.Assets.TextureFromShape(swingerbody.FixtureList[0].Shape,
                                                                                MaterialType.Dots,
                                                                                Color.Red, 2f));

            body2sprite = new Sprite(ScreenManager.Assets.TextureFromShape(swingerbody.FixtureList[0].Shape,
                                                                                MaterialType.Dots,
                                                                                Color.Red, 2f));
       
        }
Esempio n. 32
0
        private GearsTest()
        {
            {
                // First circle
                CircleShape circle1 = new CircleShape(1.0f, 5);
                Body body1 = BodyFactory.CreateBody(World);
                body1.BodyType = BodyType.Dynamic;
                body1.Position = new Vector2(-3.0f, 12.0f);
                body1.CreateFixture(circle1);

                // Second circle
                CircleShape circle2 = new CircleShape(2.0f, 5);
                Body body2 = BodyFactory.CreateBody(World);
                body2.BodyType = BodyType.Dynamic;
                body2.Position = new Vector2(0.0f, 12.0f);
                body2.CreateFixture(circle2);

                // Rectangle
                Vertices box = PolygonTools.CreateRectangle(0.5f, 5.0f);
                PolygonShape polygonBox = new PolygonShape(box, 5);
                Body body3 = BodyFactory.CreateBody(World);
                body3.BodyType = BodyType.Dynamic;
                body3.Position = new Vector2(2.5f, 12.0f);
                body3.CreateFixture(polygonBox);

                // Fix first circle
                _joint1 = new FixedRevoluteJoint(body1, Vector2.Zero, body1.Position);
                World.AddJoint(_joint1);

                // Fix second circle
                _joint2 = new FixedRevoluteJoint(body2, Vector2.Zero, body2.Position);
                World.AddJoint(_joint2);

                // Fix rectangle
                _joint3 = new FixedPrismaticJoint(body3, body3.Position, new Vector2(0.0f, 1.0f));
                _joint3.LowerLimit = -5.0f;
                _joint3.UpperLimit = 5.0f;
                _joint3.LimitEnabled = true;
                World.AddJoint(_joint3);

                // Attach first and second circle together with a gear joint
                _joint4 = new GearJoint(_joint1, _joint2, circle2.Radius / circle1.Radius);
                World.AddJoint(_joint4);

                // Attach second and rectangle together with a gear joint
                _joint5 = new GearJoint(_joint2, _joint3, -1.0f / circle2.Radius);
                World.AddJoint(_joint5);
            }
        }
Esempio n. 33
0
File: Ball.cs Progetto: det/Rimbalzo
 public Ball(Simulation sim, BallData spawn)
 {
     simulation = sim;
     var body = new Body(sim.World);
     var shape = new CircleShape(radius, 1f);
     body.BodyType = BodyType.Dynamic;
     body.FixedRotation = true;
     body.LinearDamping = drag;
     body.IsBullet = true;
     Fixture = body.CreateFixture(shape);
     Fixture.Restitution = restitution;
     Fixture.Friction = 0f;
     Carrier = null;
     SpawnPos = spawn.Position;
     Spawn();
 }
        public override void Keyboard(KeyboardManager keyboardManager)
        {
            if (keyboardManager.IsNewKeyPress(Keys.C) && _fixture2 == null)
            {
                CircleShape shape = new CircleShape(3.0f, 10);
                shape.Position = new Vector2(0.5f, -4.0f);
                _fixture2 = _body.CreateFixture(shape);
                _body.Awake = true;
            }

            if (keyboardManager.IsNewKeyPress(Keys.D) && _fixture2 != null)
            {
                _body.DestroyFixture(_fixture2);
                _fixture2 = null;
                _body.Awake = true;
            }
        }
Esempio n. 35
0
 /// <summary>
 /// Compare the circle to another circle
 /// </summary>
 /// <param name="shape">The other circle</param>
 /// <returns>True if the two circles are the same size and have the same position</returns>
 public bool CompareTo(CircleShape shape)
 {
     return(Radius == shape.Radius && Position == shape.Position);
 }
Esempio n. 36
0
 /// <summary>
 /// Compare the circle to another circle
 /// </summary>
 /// <param name="shape">The other circle</param>
 /// <returns>True if the two circles are the same size and have the same position</returns>
 public bool CompareTo(CircleShape shape)
 {
     return(radius == shape.radius && position == shape.position);
 }