Beispiel #1
0
 public Border(int width, int height, int borderWidth, Vector2 position)
 {
     _width = width;
     _height = height;
     _borderWidth = borderWidth;
     _position = position;
 }
Beispiel #2
0
        private void LoadBorderGeom(PhysicsSimulator physicsSimulator)
        {
            _borderGeom = new Geom[4];
            //left border
            Vector2 geometryOffset = new Vector2(-(_width * .5f - _borderWidth * .5f), 0);
            _borderGeom[0] = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _borderBody, _borderWidth,
                                                                      _height,
                                                                      geometryOffset, 0);
            _borderGeom[0].RestitutionCoefficient = .2f;
            _borderGeom[0].FrictionCoefficient = .5f;
            _borderGeom[0].CollisionGroup = 100;

            //right border (clone left border since geometry is same size)
            geometryOffset = new Vector2(_width * .5f - _borderWidth * .5f, 0);
            _borderGeom[1] = GeomFactory.Instance.CreateGeom(physicsSimulator, _borderBody, _borderGeom[0],
                                                             geometryOffset,
                                                             0);

            //top border
            geometryOffset = new Vector2(0, -(_height * .5f - _borderWidth * .5f));
            _borderGeom[2] = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _borderBody, _width,
                                                                      _borderWidth,
                                                                      geometryOffset, 0);
            _borderGeom[2].RestitutionCoefficient = .2f;
            _borderGeom[2].FrictionCoefficient = .2f;
            _borderGeom[2].CollisionGroup = 100;

            //bottom border (clone top border since geometry is same size)
            geometryOffset = new Vector2(0, _height * .5f - _borderWidth * .5f);
            _borderGeom[3] = GeomFactory.Instance.CreateGeom(physicsSimulator, _borderBody, _borderGeom[2],
                                                             geometryOffset,
                                                             0);
        }
 public CollisionBorder(float width, float height, float borderWidth, Vector2 position)
 {
     Width = width;
     Height = height;
     BorderWidth = borderWidth;
     _position = position;
 }
 public RectanglePlatform(int width, int height, Vector2 position, int collisionGroup)
 {
     _width = width;
     _height = height;
     _position = position;
     _collisionGroup = collisionGroup;
 }
Beispiel #5
0
 public Border(float width, float height, float borderWidth, Vector2 position)
 {
     this.width = width;
     this.height = height;
     this.borderWidth = borderWidth;
     this.position = position;
 }
 public RectanglePlatform(int width, int height, Vector2 position, Color color, Color borderColor,
     int collisionGroup)
 {
     _width = width;
     _height = height;
     _position = position;
     _color = color;
     _borderColor = borderColor;
     _collisionGroup = collisionGroup;
 }
Beispiel #7
0
 public Pyramid(Body referenceBody, Geom referenceGeom, float horizontalSpacing, float verticleSpacing,
     float blockWidth, float blockHeight, int bottomRowBlockCount, Vector2 bottomRightBlockPosition)
 {
     _referenceBody = referenceBody;
     _referenceGeom = referenceGeom;
     _horizontalSpacing = horizontalSpacing;
     _verticleSpacing = verticleSpacing;
     _blockWidth = blockWidth;
     _blockHeight = blockHeight;
     _bottomRowBlockCount = bottomRowBlockCount;
     _bottomRightBlockPosition = bottomRightBlockPosition;
 }
Beispiel #8
0
        private void CreatePyramid()
        {
            Vector2 rowOffset = new Vector2((_blockWidth/2) + (_horizontalSpacing/2), -(_blockHeight + _verticleSpacing));
            Vector2 colOffset = new Vector2(_horizontalSpacing + _blockWidth, 0);
            int blockCounter = 0;

            for (int i = 0; i < _bottomRowBlockCount; i++)
            {
                Vector2 position = _bottomRightBlockPosition + rowOffset*i;
                for (int j = 0; j < _bottomRowBlockCount - i; j++)
                {
                    Vector2 rowPosition = position + colOffset*j;
                    _blockBody[blockCounter].Position = rowPosition;
                    blockCounter += 1;
                }
            }
        }
 public void Update()
 {
     if (LinearSpring == null) return;
     Endpoint1 = LinearSpring.Body1.GetWorldPosition(LinearSpring.AttachPoint1);
     Endpoint2 = LinearSpring.Body2.GetWorldPosition(LinearSpring.AttachPoint2);
 }
        public void Load(SimulatorView view, PhysicsSimulator physicsSimulator)
        {
            int radius;
            if (_attachPoint == 0 | _attachPoint == 2)
            {
                radius = _rectangleHeight;
            }
            else
            {
                radius = _rectangleWidth;
            }

            //body is created as rectangle so that it has the moment of inertia closer to the final shape of the object.
            _angleSpringleverBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _rectangleWidth,
                                                                             _rectangleHeight, 1f);
            view.AddRectangleToCanvas(_angleSpringleverBody, Colors.White,
                                      new Vector2(_rectangleWidth, _rectangleHeight));

            _rectangleGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _angleSpringleverBody,
                                                                      _rectangleWidth, _rectangleHeight);
            _rectangleGeom.FrictionCoefficient = .5f;
            _rectangleGeom.CollisionGroup = _collisionGroup;

            Vector2 offset = Vector2.Zero;
            switch (_attachPoint)
            {
                case 0:
                    {
                        offset = new Vector2(-_rectangleWidth/2f, 0); //offset to rectangle to left
                        break;
                    }
                case 1:
                    {
                        offset = new Vector2(0, -_rectangleHeight/2f); //offset to rectangle to top
                        break;
                    }
                case 2:
                    {
                        offset = new Vector2(_rectangleWidth/2f, 0); //offset to rectangle to right
                        break;
                    }
                case 3:
                    {
                        offset = new Vector2(0, _rectangleHeight/2f); //offset to rectangle to bottom
                        break;
                    }
            }

            _angleSpringleverBody.Position = _position - offset;
            CircleBrush circle = view.AddCircleToCanvas(null, Colors.White, 20);
            circle.Extender.Position = _position;
            _circleGeom = GeomFactory.Instance.CreateCircleGeom(physicsSimulator, _angleSpringleverBody, radius, 20,
                                                                offset, 0);
            _circleGeom.FrictionCoefficient = .5f;
            _circleGeom.CollisionGroup = _collisionGroup;

            JointFactory.Instance.CreateFixedRevoluteJoint(physicsSimulator, _angleSpringleverBody,
                                                           _position);
            SpringFactory.Instance.CreateFixedAngleSpring(physicsSimulator, _angleSpringleverBody,
                                                          _springConstant, _dampningConstant);
        }
 public void Update()
 {
     if (FixedLinearSpring == null) return;
     Endpoint1 = FixedLinearSpring.Body.GetWorldPosition(FixedLinearSpring.BodyAttachPoint);
     Endpoint2 = FixedLinearSpring.WorldAttachPoint;
 }
Beispiel #12
0
 public void ApplyForce(Vector2 force)
 {
     agentBody.ApplyForce(force);
 }
Beispiel #13
0
 public Agent(Vector2 position)
 {
     _position = position;
 }
        private void LoadPhysics(PhysicsSimulator physicsSimulator)
        {
            Geom = new Geom[4];
            //left border
            Vector2 geomOffset = new Vector2(-Width * .5f - BorderWidth * .5f, 0);
            Geom[0] = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, Body, BorderWidth, Height + BorderWidth,
                                                               geomOffset, 0);
            Geom[0].RestitutionCoefficient = .2f;
            Geom[0].FrictionCoefficient = 0f;
            Geom[0].CollisionGroup = 100;

            //right border (clone left border since geom is same size)
            geomOffset = new Vector2(Width * .5f + BorderWidth * .5f, 0);
            Geom[1] = GeomFactory.Instance.CreateGeom(physicsSimulator, Body, Geom[0], geomOffset, 0);

            //top border
            geomOffset = new Vector2(0, -Height * .5f - BorderWidth * .5f);
            Geom[2] = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, Body, Width + BorderWidth, BorderWidth,
                                                               geomOffset, 0, 20);
            Geom[2].RestitutionCoefficient = 0f;
            Geom[2].FrictionCoefficient = 1f;
            Geom[2].CollisionGroup = 100;

            //bottom border (clone top border since geom is same size)
            geomOffset = new Vector2(0, Height * .5f + BorderWidth * .5f);
            Geom[3] = GeomFactory.Instance.CreateGeom(physicsSimulator, Body, Geom[2], geomOffset, 0);
        }
Beispiel #15
0
 public Ragdoll(Vector2 position)
 {
     _position = position;
 }
Beispiel #16
0
        private void LoadCircles()
        {
            //Cat1=Red, Cat2=Green, Cat3=Blue, Cat4=Black, Cat5=Agent
            Vector2 startPosition = new Vector2(100, 100);
            Vector2 endPosition = new Vector2(100, ScreenHeight - 100);
            _redCircles1 = new Circles(startPosition, endPosition, 15, 15, Color.FromArgb(175, 200, 0, 0));
            _redCircles1.CollisionCategories = (CollisionCategory.Cat1);
            _redCircles1.CollidesWith = (CollisionCategory.Cat1 | CollisionCategory.Cat4 | CollisionCategory.Cat5);
            _redCircles1.Load(this, physicsSimulator);

            startPosition = new Vector2(200, 200);
            endPosition = new Vector2(200, ScreenHeight - 200);
            _redCircles2 = new Circles(startPosition, endPosition, 15, 12, Color.FromArgb(175, 200, 0, 0));
            _redCircles2.CollisionCategories = (CollisionCategory.Cat1);
            _redCircles2.CollidesWith = (CollisionCategory.Cat1 | CollisionCategory.Cat4 | CollisionCategory.Cat5);
            _redCircles2.Load(this, physicsSimulator);

            startPosition = new Vector2(300, 300);
            endPosition = new Vector2(300, ScreenHeight - 300);
            _redCircles3 = new Circles(startPosition, endPosition, 10, 9, Color.FromArgb(175, 200, 0, 0));
            _redCircles3.CollisionCategories = (CollisionCategory.Cat1);
            _redCircles3.CollidesWith = (CollisionCategory.Cat1 | CollisionCategory.Cat4 | CollisionCategory.Cat5);
            _redCircles3.Load(this, physicsSimulator);

            startPosition = new Vector2(200, 100);
            endPosition = new Vector2(ScreenWidth - 200, 100);
            _greenCircles1 = new Circles(startPosition, endPosition, 15, 15, Color.FromArgb(175, 0, 200, 0));
            _greenCircles1.CollisionCategories = (CollisionCategory.Cat2);
            _greenCircles1.CollidesWith = (CollisionCategory.Cat2 | CollisionCategory.Cat4 | CollisionCategory.Cat5);
            _greenCircles1.Load(this, physicsSimulator);

            startPosition = new Vector2(300, 200);
            endPosition = new Vector2(ScreenWidth - 300, 200);
            _greenCircles2 = new Circles(startPosition, endPosition, 15, 12, Color.FromArgb(175, 0, 200, 0));
            _greenCircles2.CollisionCategories = (CollisionCategory.Cat2);
            _greenCircles2.CollidesWith = (CollisionCategory.Cat2 | CollisionCategory.Cat4 | CollisionCategory.Cat5);
            _greenCircles2.Load(this, physicsSimulator);

            startPosition = new Vector2(400, 300);
            endPosition = new Vector2(ScreenWidth - 400, 300);
            _greenCircles3 = new Circles(startPosition, endPosition, 10, 9, Color.FromArgb(175, 0, 200, 0));
            _greenCircles3.CollisionCategories = (CollisionCategory.Cat2);
            _greenCircles3.CollidesWith = (CollisionCategory.Cat2 | CollisionCategory.Cat4 | CollisionCategory.Cat5);
            _greenCircles3.Load(this, physicsSimulator);

            startPosition = new Vector2(ScreenWidth - 100, 100);
            endPosition = new Vector2(ScreenWidth - 100, ScreenHeight - 100);
            _blueCircles1 = new Circles(startPosition, endPosition, 15, 15, Color.FromArgb(175, 0, 0, 200));
            _blueCircles1.CollisionCategories = (CollisionCategory.Cat3);
            _blueCircles1.CollidesWith = (CollisionCategory.Cat3 | CollisionCategory.Cat4 | CollisionCategory.Cat5);
            _blueCircles1.Load(this, physicsSimulator);

            startPosition = new Vector2(ScreenWidth - 200, 200);
            endPosition = new Vector2(ScreenWidth - 200, ScreenHeight - 200);
            _blueCircles2 = new Circles(startPosition, endPosition, 15, 12, Color.FromArgb(175, 0, 0, 200));
            _blueCircles2.CollisionCategories = (CollisionCategory.Cat3);
            _blueCircles2.CollidesWith = (CollisionCategory.Cat3 | CollisionCategory.Cat4 | CollisionCategory.Cat5);
            _blueCircles2.Load(this, physicsSimulator);

            startPosition = new Vector2(ScreenWidth - 300, 300);
            endPosition = new Vector2(ScreenWidth - 300, ScreenHeight - 300);
            _blueCircles3 = new Circles(startPosition, endPosition, 10, 9, Color.FromArgb(175, 0, 0, 200));
            _blueCircles3.CollisionCategories = (CollisionCategory.Cat3);
            _blueCircles3.CollidesWith = (CollisionCategory.Cat3 | CollisionCategory.Cat4 | CollisionCategory.Cat5);
            _blueCircles3.Load(this, physicsSimulator);

            startPosition = new Vector2(200, ScreenHeight - 100);
            endPosition = new Vector2(ScreenWidth - 200, ScreenHeight - 100);
            _blackCircles1 = new Circles(startPosition, endPosition, 15, 15, Color.FromArgb(200, 0, 0, 0));
            _blackCircles1.CollisionCategories = CollisionCategory.Cat4;
            _blackCircles1.CollidesWith = CollisionCategory.All & ~CollisionCategory.Cat5; //Collide with all but Cat5
            _blackCircles1.Load(this, physicsSimulator);

            startPosition = new Vector2(300, ScreenHeight - 200);
            endPosition = new Vector2(ScreenWidth - 300, ScreenHeight - 200);
            _blackCircles2 = new Circles(startPosition, endPosition, 15, 12, Color.FromArgb(200, 0, 0, 0));
            _blackCircles2.CollisionCategories = CollisionCategory.Cat4;
            _blackCircles2.CollidesWith = CollisionCategory.All & ~CollisionCategory.Cat5; //Collide with all but Cat5
            _blackCircles2.Load(this, physicsSimulator);

            startPosition = new Vector2(400, ScreenHeight - 300);
            endPosition = new Vector2(ScreenWidth - 400, ScreenHeight - 300);
            _blackCircles3 = new Circles(startPosition, endPosition, 10, 9, Color.FromArgb(200, 0, 0, 0));
            _blackCircles3.CollisionCategories = CollisionCategory.Cat4;
            _blackCircles3.CollidesWith = CollisionCategory.All & ~CollisionCategory.Cat5; //Collide with all but Cat5
            _blackCircles3.Load(this, physicsSimulator);
        }