예제 #1
0
        public override void LoadContent()
        {
            _chainTexture = DrawingHelper.CreateRectangleTexture(ScreenManager.GraphicsDevice, 20, 20, Color.White,
                                                                 Color.Black);
            _chainOrigin = new Vector2(_chainTexture.Width / 2f, _chainTexture.Height / 2f);


            _chain = ComplexFactory.Instance.CreateChain(PhysicsSimulator, new Vector2(150, 100), new Vector2(200, 300), 20.0f, 10.0f, 1, true, false, LinkType.RevoluteJoint);
            _chain.CreateGeoms(PhysicsSimulator, 1);

            _chainPin = ComplexFactory.Instance.CreateChain(PhysicsSimulator, new Vector2(250, 100), new Vector2(300, 300), 20.0f, 10.0f, 1, true, false, LinkType.PinJoint);
            _chainPin.CreateGeoms(PhysicsSimulator, 2);

            ComplexFactory.Instance.SpringConstant         = 150; // values inside let us setup additional parameters
            ComplexFactory.Instance.DampingConstant        = 10;
            ComplexFactory.Instance.SpringRestLengthFactor = 1f;
            _chainSpring = ComplexFactory.Instance.CreateChain(PhysicsSimulator, new Vector2(350, 100), new Vector2(400, 300), 20.0f, 10.0f, 1, true, false, LinkType.LinearSpring);
            _chainSpring.CreateGeoms(PhysicsSimulator, 3);

            ComplexFactory.Instance.Min = 0;
            ComplexFactory.Instance.Max = 15;
            _chainSlide = ComplexFactory.Instance.CreateChain(PhysicsSimulator, new Vector2(450, 100), new Vector2(500, 300), 20.0f, 10.0f, 1, true, false, LinkType.SliderJoint);
            _chainSlide.CreateGeoms(PhysicsSimulator, 4);


            ComplexFactory.Instance.SpringConstant         = 300; // values inside let us setup additional parameters
            ComplexFactory.Instance.DampingConstant        = 10;
            ComplexFactory.Instance.SpringRestLengthFactor = 0.1f;
            _chainSpring2 = ComplexFactory.Instance.CreateChain(PhysicsSimulator, new Vector2(650, 100), new Vector2(600, 600), 20.0f, 10.0f, 40.0f, 1, true, false, LinkType.LinearSpring);
            _chainSpring2.CreateGeoms(PhysicsSimulator, 5);

            base.LoadContent();
        }
예제 #2
0
        public override void LoadContent()
        {
            _platform = new Box(300, 20, 10, new Vector2(ScreenManager.ScreenWidth / 2f, 500), Color.White, Color.Black, 1);
            _platform.Load(ScreenManager.GraphicsDevice, PhysicsSimulator);

            _refTexture = DrawingHelper.CreateRectangleTexture(ScreenManager.GraphicsDevice, 32, 32, 2, 0, 0,
                                                               Color.White, Color.Black);

            _refBody = BodyFactory.Instance.CreateRectangleBody(32, 32, 3f);
            _refGeom = GeomFactory.Instance.CreateRectangleGeom(_refBody, 32, 32);
            _refGeom.FrictionCoefficient = .2f;

            //create the _pyramid near the bottom of the screen.
            _pyramid = new Pyramid(_refBody, _refGeom, 32f / 3f, 32f / 3f, 32, 32, _pyramidBaseBodyCount,
                                   new Vector2(ScreenManager.ScreenCenter.X - _pyramidBaseBodyCount * .5f * (32 + 32 / 3) + 20,
                                               ScreenManager.ScreenHeight - 300));

            _pyramid.Load(PhysicsSimulator);

            //Add the geometries to the watermodel's fluiddragcontroller to make them float.
            _waterModel.FluidDragController.AddGeom(_platform.Geom);

            foreach (Geom geom in _pyramid.Geoms)
            {
                _waterModel.FluidDragController.AddGeom(geom);
            }

            // load a font
            _font = ScreenManager.ContentManager.Load <SpriteFont>("Content/Fonts/detailsfont");

            base.LoadContent();
        }
예제 #3
0
        public override void LoadContent()
        {
            _lineBrush.Load(ScreenManager.GraphicsDevice);

            _rectangleTexture = DrawingHelper.CreateRectangleTexture(ScreenManager.GraphicsDevice, 32, 32, 2, 0, 0,
                                                                     Color.White, Color.Black);

            _rectangleBody = BodyFactory.Instance.CreateRectangleBody(32, 32, 1f);             //template
            _rectangleGeom = GeomFactory.Instance.CreateRectangleGeom(_rectangleBody, 32, 32); //template
            _rectangleGeom.FrictionCoefficient    = .4f;
            _rectangleGeom.RestitutionCoefficient = 0f;

            //create the _pyramid near the bottom of the screen.
            _pyramid = new Pyramid(_rectangleBody, _rectangleGeom, 32f / 3f, 32f / 3f, 32, 32, pyramidBaseBodyCount,
                                   new Vector2(ScreenManager.ScreenCenter.X - pyramidBaseBodyCount * .5f * (32 + 32 / 3),
                                               ScreenManager.ScreenHeight - 125));
            _pyramid.Load(PhysicsSimulator);

            _floor = new Floor(ScreenManager.ScreenWidth, 100,
                               new Vector2(ScreenManager.ScreenCenter.X, ScreenManager.ScreenHeight - 50));
            _floor.Load(ScreenManager.GraphicsDevice, PhysicsSimulator);

            //_agent = new Agent(ScreenManager.ScreenCenter - new Vector2(320, 300));
            //_agent.Load(ScreenManager.GraphicsDevice, PhysicsSimulator);

            base.LoadContent();
        }
        public void Load(GraphicsDevice graphicsDevice, PhysicsSimulator physicsSimulator)
        {
            _rectangleTexture = DrawingHelper.CreateRectangleTexture(graphicsDevice, _rectangleWidth, _rectangleHeight,
                                                                     Color.White, Color.Black);

            _linearSpring     = new LinearSpring[_rectangleCount - 1];
            _rectangleBody    = new Body[_rectangleCount];
            _rectangleBody[0] = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _rectangleWidth,
                                                                         _rectangleHeight, _rectangleMass);
            _rectangleBody[0].Position = _position;
            for (int i = 1; i < _rectangleBody.Length; i++)
            {
                _rectangleBody[i]          = BodyFactory.Instance.CreateBody(physicsSimulator, _rectangleBody[0]);
                _rectangleBody[i].Position = _rectangleBody[i - 1].Position + new Vector2(0, _springLength);
            }

            _rectangleGeom    = new Geom[_rectangleCount];
            _rectangleGeom[0] = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _rectangleBody[0],
                                                                         _rectangleWidth, _rectangleHeight);
            _rectangleGeom[0].CollisionGroup = _collisionGroup;
            for (int j = 1; j < _rectangleGeom.Length; j++)
            {
                _rectangleGeom[j] = GeomFactory.Instance.CreateGeom(physicsSimulator, _rectangleBody[j],
                                                                    _rectangleGeom[0]);
            }

            for (int k = 0; k < _linearSpring.Length; k++)
            {
                _linearSpring[k] = SpringFactory.Instance.CreateLinearSpring(physicsSimulator, _rectangleBody[k],
                                                                             Vector2.Zero, _rectangleBody[k + 1],
                                                                             Vector2.Zero, _springConstant,
                                                                             _dampningConstant);
            }
        }
예제 #5
0
        public void LoadObstacles()
        {
            _obstacleTexture = DrawingHelper.CreateRectangleTexture(ScreenManager.GraphicsDevice, 128, 32, Color.White,
                                                                    Color.Black);
            _obstacleOrigin = new Vector2(_obstacleTexture.Width / 2f, _obstacleTexture.Height / 2f);

            _obstacleBody = new Body[5];
            _obstacleGeom = new Geom[5];
            for (int i = 0; i < _obstacleBody.Length; i++)
            {
                _obstacleBody[i]          = BodyFactory.Instance.CreateRectangleBody(PhysicsSimulator, 128, 32, 1);
                _obstacleBody[i].IsStatic = true;

                if (i == 0)
                {
                    _obstacleGeom[i] = GeomFactory.Instance.CreateRectangleGeom(PhysicsSimulator, _obstacleBody[i], 128,
                                                                                32);
                    _obstacleGeom[i].RestitutionCoefficient = .2f;
                    _obstacleGeom[i].FrictionCoefficient    = .2f;
                }
                else
                {
                    _obstacleGeom[i] = GeomFactory.Instance.CreateGeom(PhysicsSimulator, _obstacleBody[i],
                                                                       _obstacleGeom[0]);
                }
            }

            _obstacleBody[0].Position = ScreenManager.ScreenCenter + new Vector2(-50, -200);
            _obstacleBody[1].Position = ScreenManager.ScreenCenter + new Vector2(150, -100);
            _obstacleBody[2].Position = ScreenManager.ScreenCenter + new Vector2(100, 50);
            _obstacleBody[3].Position = ScreenManager.ScreenCenter + new Vector2(-100, 200);
            _obstacleBody[4].Position = ScreenManager.ScreenCenter + new Vector2(-170, 0);
        }
 private void LoadPerformancePanelContent(GraphicsDevice graphicsDevice, ContentManager content)
 {
     _performancePanelTexture = DrawingHelper.CreateRectangleTexture(graphicsDevice, _performancePanelWidth,
                                                                     _performancePanelHeight,
                                                                     new Color(0, 0, 0, 155));
     _spriteFont = content.Load <SpriteFont>(@"Content\Fonts\diagnosticFont");
 }
예제 #7
0
        public override void LoadContent()
        {
            _rectangleTexture = DrawingHelper.CreateRectangleTexture(ScreenManager.GraphicsDevice, 32, 32, 2, 0, 0,
                                                                     Color.White, Color.Black);

            _rectangleBody = BodyFactory.Instance.CreateRectangleBody(32, 32, 1f);             //template
            _rectangleGeom = GeomFactory.Instance.CreateRectangleGeom(_rectangleBody, 32, 32); //template
            _rectangleGeom.FrictionCoefficient    = .4f;
            _rectangleGeom.RestitutionCoefficient = 0f;

            //create the pyramid near the bottom of the screen.
            _multithreadedPyramid = new MultithreadedPyramid(_rectangleBody, _rectangleGeom, 32f / 8f, 32f / 8f, 32, 32, pyramidBaseBodyCount,
                                                             new Vector2(ScreenManager.ScreenCenter.X - pyramidBaseBodyCount * .5f * (32 + 32 / 3),
                                                                         ScreenManager.ScreenHeight - 80));
            // POINT OF INTEREST
            // It needs the processor to register the links
            _multithreadedPyramid.Load(PhysicsSimulator, _physicsProcessor);

            _agent = new Agent(ScreenManager.ScreenCenter - new Vector2(320, 300));
            _agent.Load(ScreenManager.GraphicsDevice, PhysicsSimulator);
            // POINT OF INTEREST
            // Link the agent to the processor
            _agent.LinkToProcessor(_physicsProcessor);

            base.LoadContent();
        }
예제 #8
0
        public override void LoadContent()
        {
            if (_contentManager == null)
            {
                _contentManager = new ContentManager(ScreenManager.Game.Services);
            }
            _lineBrush.Load(ScreenManager.GraphicsDevice);

            _rectangleTexture = DrawingHelper.CreateRectangleTexture(ScreenManager.GraphicsDevice, 128, 128, Color.Gold,
                                                                     Color.Black);
            _rectangleOrigin = new Vector2(_rectangleTexture.Width / 2f, _rectangleTexture.Height / 2f);

            _circleTexture = DrawingHelper.CreateCircleTexture(ScreenManager.GraphicsDevice, 64, Color.White,
                                                               Color.Black);
            _circleOrigin = new Vector2(_circleTexture.Width / 2f, _circleTexture.Height / 2f);

            _rectangleBody          = BodyFactory.Instance.CreateRectangleBody(PhysicsSimulator, 128, 128, 1);
            _rectangleBody.Position = new Vector2(256, 384);
            _rectangleGeom          = GeomFactory.Instance.CreateRectangleGeom(PhysicsSimulator, _rectangleBody, 128, 128);

            _circleBody          = BodyFactory.Instance.CreateCircleBody(PhysicsSimulator, 64, 1); //fix
            _circleBody.Position = new Vector2(725, 384);
            _circleGeom          = GeomFactory.Instance.CreateCircleGeom(PhysicsSimulator, _circleBody, 64, 20);

            base.LoadContent();
        }
예제 #9
0
        public void LoadAgent()
        {
            _agentTexture = DrawingHelper.CreateCircleTexture(ScreenManager.GraphicsDevice, 16, Color.Gold, Color.Black);
            _agentOrigin  = new Vector2(_agentTexture.Width / 2f, _agentTexture.Height / 2f);

            _agentCrossBeamTexture = DrawingHelper.CreateRectangleTexture(ScreenManager.GraphicsDevice, 16, 120,
                                                                          Color.DarkGray, Color.Black);
            _agentCrossBeamOrigin = new Vector2(_agentCrossBeamTexture.Width / 2f, _agentCrossBeamTexture.Height / 2f);

            _agentBody          = BodyFactory.Instance.CreateRectangleBody(PhysicsSimulator, 80, 80, 5);
            _agentBody.Position = new Vector2(ScreenManager.ScreenCenter.X, 110);

            _agentGeom    = new Geom[7];
            _agentGeom[0] = GeomFactory.Instance.CreateCircleGeom(PhysicsSimulator, _agentBody, 16, 10,
                                                                  new Vector2(-40, -40), 0);
            _agentGeom[0].RestitutionCoefficient = .2f;
            _agentGeom[0].FrictionCoefficient    = .2f;
            _agentGeom[0].CollisionGroup         = 1;
            _agentGeom[1] = GeomFactory.Instance.CreateGeom(PhysicsSimulator, _agentBody, _agentGeom[0],
                                                            new Vector2(-40, 40), 0);
            _agentGeom[2] = GeomFactory.Instance.CreateGeom(PhysicsSimulator, _agentBody, _agentGeom[0],
                                                            new Vector2(40, -40), 0);
            _agentGeom[3] = GeomFactory.Instance.CreateGeom(PhysicsSimulator, _agentBody, _agentGeom[0],
                                                            new Vector2(40, 40), 0);
            _agentGeom[4] = GeomFactory.Instance.CreateGeom(PhysicsSimulator, _agentBody, _agentGeom[0],
                                                            new Vector2(0, 0),
                                                            0);

            _agentGeom[5] = GeomFactory.Instance.CreateRectangleGeom(PhysicsSimulator, _agentBody, 16, 130, Vector2.Zero,
                                                                     MathHelper.PiOver4);
            _agentGeom[5].CollisionGroup = 1;
            _agentGeom[6] = GeomFactory.Instance.CreateRectangleGeom(PhysicsSimulator, _agentBody, 16, 130, Vector2.Zero,
                                                                     -MathHelper.PiOver4);
            _agentGeom[6].CollisionGroup = 1;
        }
예제 #10
0
        public override void LoadContent()
        {
            _panelTexture = DrawingHelper.CreateRectangleTexture(ScreenManager.GraphicsDevice, panelWidth, panelHeight,
                                                                 _panelColor);
            LeftBorder = ScreenManager.Camera.ScreenCenter.X - panelWidth / 2f + leftBorder;

            _textPanelTexture = DrawingHelper.CreateRectangleTexture(ScreenManager.GraphicsDevice, textPanelWidth,
                                                                     textPanelHeight, _textPanelColor);

            base.LoadContent();
        }
예제 #11
0
        public override void LoadContent()
        {
            _chainTexture = DrawingHelper.CreateRectangleTexture(ScreenManager.GraphicsDevice, 20, 10, Color.White,
                                                                 Color.Black);

            _obstaclesTexture = DrawingHelper.CreateRectangleTexture(ScreenManager.GraphicsDevice, 40, 40, Color.Brown,
                                                                     Color.Black);

            _wheelTexture = DrawingHelper.CreateCircleTexture(ScreenManager.GraphicsDevice, 45, 2, Color.White, Color.Black);

            _chainOrigin     = new Vector2(_chainTexture.Width / 2f, _chainTexture.Height / 2f);
            _wheelOrigin     = new Vector2(_wheelTexture.Width / 2f, _wheelTexture.Height / 2f);
            _obstaclesOrigin = new Vector2(_obstaclesTexture.Width / 2f, _obstaclesTexture.Height / 2f);
            Vector2 center = new Vector2(400, 500);

            _controlPoints = new Vertices();
            _controlPoints.Add(new Vector2(-15, -50) + center);
            _controlPoints.Add(new Vector2(-50, -50) + center);
            _controlPoints.Add(new Vector2(-100, -25) + center);
            _controlPoints.Add(new Vector2(-100, 25) + center);
            _controlPoints.Add(new Vector2(-50, 50) + center);
            _controlPoints.Add(new Vector2(50, 50) + center);
            _controlPoints.Add(new Vector2(100, 25) + center);
            _controlPoints.Add(new Vector2(100, -25) + center);
            _controlPoints.Add(new Vector2(50, -50) + center);
            _controlPoints.Add(new Vector2(-10, -50) + center);

            _track = ComplexFactory.Instance.CreateTrack(PhysicsSimulator, _controlPoints, 20.0f, 10.0f, 3.0f, true, 2, LinkType.RevoluteJoint);

            foreach (Geom g in _track.Geoms)
            {
                g.FrictionCoefficient = 1.0f;
            }

            _wheel1          = BodyFactory.Instance.CreateCircleBody(PhysicsSimulator, 45, 30);
            _wheel1.Position = new Vector2(-50, 0) + center;
            _wheel2          = BodyFactory.Instance.CreateCircleBody(PhysicsSimulator, 45, 30);
            _wheel2.Position = new Vector2(50, 0) + center;

            _wheelg = GeomFactory.Instance.CreateCircleGeom(PhysicsSimulator, _wheel1, 45, 36);
            _wheelg.FrictionCoefficient = 1.0f;
            _wheelg = GeomFactory.Instance.CreateCircleGeom(PhysicsSimulator, _wheel2, 45, 36);
            _wheelg.FrictionCoefficient = 1.0f;

            _spring             = SpringFactory.Instance.CreateLinearSpring(PhysicsSimulator, _wheel1, new Vector2(), _wheel2, new Vector2(), 5200, 3050);
            _spring.RestLength += 20;

            _obstacles  = new GenericList <Body>();
            _obstaclesg = new GenericList <Geom>();

            base.LoadContent();
        }
예제 #12
0
        public override void LoadContent()
        {
            //load texture that will visually represent the physics body
            _bodyTexture = DrawingHelper.CreateRectangleTexture(ScreenManager.GraphicsDevice, 128, 128, Color.Gold,
                                                                Color.Black);
            _origin = new Vector2(_bodyTexture.Width / 2f, _bodyTexture.Height / 2f);

            //use the body factory to create the physics body
            _rectangleBody          = BodyFactory.Instance.CreateRectangleBody(PhysicsSimulator, 128, 128, 1);
            _rectangleBody.Position = ScreenManager.ScreenCenter;

            base.LoadContent();
        }
예제 #13
0
        public void Load(GraphicsDevice graphicsDevice, PhysicsSimulator physicsSimulator)
        {
            _floorTexture = DrawingHelper.CreateRectangleTexture(graphicsDevice, _width, _height, 0, 1, 1, Color.White,
                                                                 Color.Black);
            _floorOrigin = new Vector2(_floorTexture.Width / 2f, _floorTexture.Height / 2f);

            //use the body factory to create the physics body
            _floorBody          = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _width, _height, 1);
            _floorBody.IsStatic = true;
            _floorGeom          = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _floorBody, _width, _height);
            _floorGeom.RestitutionCoefficient = .4f;
            _floorGeom.FrictionCoefficient    = .4f;
            _floorBody.Position = _position;
        }
예제 #14
0
        public void Load(GraphicsDevice graphicsDevice, PhysicsSimulator physicsSimulator)
        {
            _platformTexture = DrawingHelper.CreateRectangleTexture(graphicsDevice, _width, _height, 2, 0, 0, _color,
                                                                    _borderColor);
            _platformOrigin = new Vector2(_platformTexture.Width / 2f, _platformTexture.Height / 2f);
            //use the body factory to create the physics body
            _platformBody          = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _width, _height, 1);
            _platformBody.IsStatic = true;
            _platformBody.Position = _position;

            _platformGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _platformBody, _width, _height);
            _platformGeom.CollisionGroup      = 100;
            _platformGeom.CollisionGroup      = _collisionGroup;
            _platformGeom.FrictionCoefficient = 1;
        }
예제 #15
0
        public void LoadFloor()
        {
            //load texture that will visually represent the physics body
            _floorTexture = DrawingHelper.CreateRectangleTexture(ScreenManager.GraphicsDevice, ScreenManager.ScreenWidth,
                                                                 100, Color.White, Color.Black);
            _floorOrigin = new Vector2(_floorTexture.Width / 2f, _floorTexture.Height / 2f);

            //use the body factory to create the physics body
            _floorBody          = BodyFactory.Instance.CreateRectangleBody(PhysicsSimulator, ScreenManager.ScreenWidth, 100, 1);
            _floorBody.IsStatic = true;
            _floorGeom          = GeomFactory.Instance.CreateRectangleGeom(PhysicsSimulator, _floorBody,
                                                                           ScreenManager.ScreenWidth,
                                                                           100);
            _floorGeom.RestitutionCoefficient = .2f;
            _floorGeom.FrictionCoefficient    = .2f;
            _floorBody.Position = new Vector2(ScreenManager.ScreenCenter.X, ScreenManager.ScreenHeight - 50);
        }
예제 #16
0
        public void Load(GraphicsDevice graphicsDevice, PhysicsSimulator physicsSimulator)
        {
            _agentTexture = DrawingHelper.CreateCircleTexture(graphicsDevice, 16, Color.Gold, Color.Black);
            _agentOrigin  = new Vector2(_agentTexture.Width / 2f, _agentTexture.Height / 2f);

            _agentCrossBeamTexture = DrawingHelper.CreateRectangleTexture(graphicsDevice, 16, 120, Color.DarkGray,
                                                                          Color.Black);
            _agentCrossBeamOrigin = new Vector2(_agentCrossBeamTexture.Width / 2f, _agentCrossBeamTexture.Height / 2f);

            _agentBody          = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, 80, 80, 5);
            _agentBody.Position = _position;

            _agentGeom    = new Geom[7];
            _agentGeom[0] = GeomFactory.Instance.CreateCircleGeom(physicsSimulator, _agentBody, 16, 10,
                                                                  new Vector2(-40, -40), 0);
            _agentGeom[0].RestitutionCoefficient = .4f;
            _agentGeom[0].FrictionCoefficient    = .2f;
            _agentGeom[0].CollisionGroup         = 1;
            _agentGeom[0].CollisionCategories    = _collisionCategory;
            _agentGeom[0].CollidesWith           = _collidesWith;
            _agentGeom[1] = GeomFactory.Instance.CreateGeom(physicsSimulator, _agentBody, _agentGeom[0],
                                                            new Vector2(-40, 40), 0);
            _agentGeom[2] = GeomFactory.Instance.CreateGeom(physicsSimulator, _agentBody, _agentGeom[0],
                                                            new Vector2(40, -40), 0);
            _agentGeom[3] = GeomFactory.Instance.CreateGeom(physicsSimulator, _agentBody, _agentGeom[0],
                                                            new Vector2(40, 40), 0);
            _agentGeom[4] = GeomFactory.Instance.CreateGeom(physicsSimulator, _agentBody, _agentGeom[0],
                                                            new Vector2(0, 0),
                                                            0);

            _agentGeom[5] = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _agentBody, 16, 120, Vector2.Zero,
                                                                     MathHelper.PiOver4);
            _agentGeom[5].CollisionGroup      = 1;
            _agentGeom[5].CollisionCategories = _collisionCategory;
            _agentGeom[5].CollidesWith        = _collidesWith;

            _agentGeom[6] = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _agentBody, 16, 120, Vector2.Zero,
                                                                     -MathHelper.PiOver4);
            _agentGeom[6].CollisionGroup      = 1;
            _agentGeom[6].CollisionCategories = _collisionCategory;
            _agentGeom[6].CollidesWith        = _collidesWith;
        }
예제 #17
0
        public void Load(GraphicsDevice graphicsDevice, PhysicsSimulator physicsSimulator)
        {
            _borderTexture = new Texture2D[4];

            _borderTexture[0] = DrawingHelper.CreateRectangleTexture(graphicsDevice, _borderWidth, _height, 2, 0, 0,
                                                                     new Color(200, 200, 200, 150), Color.White);
            _borderTexture[1] = DrawingHelper.CreateRectangleTexture(graphicsDevice, _borderWidth, _height, 2, 0, 0,
                                                                     new Color(200, 200, 200, 150), Color.White);
            _borderTexture[2] = DrawingHelper.CreateRectangleTexture(graphicsDevice, _width, _borderWidth, 2, 0, 0,
                                                                     new Color(200, 200, 200, 150), Color.White);
            _borderTexture[3] = DrawingHelper.CreateRectangleTexture(graphicsDevice, _width, _borderWidth, 2, 0, 0,
                                                                     new Color(200, 200, 200, 150), Color.White);

            //use the body factory to create the physics body
            _borderBody          = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _width, _height, 1);
            _borderBody.IsStatic = true;
            _borderBody.Position = _position;

            LoadBorderGeom(physicsSimulator);
        }
예제 #18
0
        public override void LoadContent()
        {
            //We load the grenade texture here instead of inside Grenade class. Load once, use multiple times.
            _grenadeTexture = ScreenManager.ContentManager.Load <Texture2D>("Content/Grenade");

            _rectangleTexture = DrawingHelper.CreateRectangleTexture(ScreenManager.GraphicsDevice, 32, 32, 2, 0, 0,
                                                                     Color.White, Color.Black);

            _rectangleBody = BodyFactory.Instance.CreateRectangleBody(32, 32, 1f);
            _rectangleGeom = GeomFactory.Instance.CreateRectangleGeom(_rectangleBody, 32, 32);
            _rectangleGeom.FrictionCoefficient    = .4f;
            _rectangleGeom.RestitutionCoefficient = 0.0f;

            _pyramid = new Pyramid(_rectangleBody, _rectangleGeom, 32f / 5f, 32f / 5f, 32, 32, pyramidBaseBodyCount,
                                   new Vector2(ScreenManager.ScreenCenter.X - pyramidBaseBodyCount * .5f * (32 + 32 / 3),
                                               ScreenManager.ScreenHeight - 125));

            _pyramid.Load(PhysicsSimulator);

            _hairDryer = new HairDryer(new Vector2(100, 100), PhysicsSimulator);
            _hairDryer.Load(ScreenManager.ContentManager.Load <Texture2D>("Content/HairDryer"));

            base.LoadContent();
        }
예제 #19
0
        public override void LoadContent()
        {
            _panelTexture = DrawingHelper.CreateRectangleTexture(ScreenManager.GraphicsDevice, 290, 100, new Color(0, 0, 0, 155));

            base.LoadContent();
        }
예제 #20
0
        public void Load(GraphicsDevice graphicsDevice, PhysicsSimulator physicsSimulator)
        {
            _rectangleTexture = DrawingHelper.CreateRectangleTexture(graphicsDevice, _rectangleWidth, _rectangleHeight,
                                                                     Color.White, Color.Black);
            int radius;

            if (_attachPoint == 0 | _attachPoint == 2)
            {
                radius = _rectangleHeight;
            }
            else
            {
                radius = _rectangleWidth;
            }
            _circleTexture = DrawingHelper.CreateCircleTexture(graphicsDevice, radius, Color.White, Color.Black);

            //body is created as rectangle so that it has the moment of inertia closer to the final shape of the object.
            _angleSpringleverBody = BodyFactory.Instance.CreateBody(physicsSimulator, 1,
                                                                    BodyFactory.MOIForRectangle(_rectangleWidth,
                                                                                                _rectangleHeight, 1f));

            _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;

            _circleGeom = GeomFactory.Instance.CreateCircleGeom(physicsSimulator, _angleSpringleverBody, radius, 20,
                                                                offset, 0);
            _circleGeom.FrictionCoefficient = .5f;
            _circleGeom.CollisionGroup      = _collisionGroup;

            _revoluteJoint = JointFactory.Instance.CreateFixedRevoluteJoint(physicsSimulator, _angleSpringleverBody,
                                                                            _position);
            physicsSimulator.Add(_revoluteJoint);
            ControllerFactory.Instance.CreateFixedAngleSpring(physicsSimulator, _angleSpringleverBody,
                                                              _springConstant, _dampningConstant);
        }
예제 #21
0
        public void Load(GraphicsDevice graphicsDevice, PhysicsSimulator physicsSimulator)
        {
            _spiderTexture = DrawingHelper.CreateCircleTexture(graphicsDevice, spiderBodyRadius, Color.White,
                                                               Color.Black);
            _spiderOrigin = new Vector2(_spiderTexture.Width / 2f, _spiderTexture.Height / 2f);

            _upperLegTexture = DrawingHelper.CreateRectangleTexture(graphicsDevice, (int)_upperLegSize.X,
                                                                    (int)_upperLegSize.Y, Color.White, Color.Black);
            _upperLegOrigin = new Vector2(_upperLegTexture.Width / 2f, _upperLegTexture.Height / 2f);

            _lowerLegTexture = DrawingHelper.CreateRectangleTexture(graphicsDevice, (int)_lowerLegSize.X,
                                                                    (int)_lowerLegSize.Y, Color.Red, Color.Black);
            _lowerLegOrigin = new Vector2(_lowerLegTexture.Width / 2f, _lowerLegTexture.Height / 2f);

            //Load bodies
            _spiderBody          = BodyFactory.Instance.CreateCircleBody(physicsSimulator, spiderBodyRadius, 1);
            _spiderBody.Position = _position;
            _spiderBody.IsStatic = false;

            _leftUpperLegBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _upperLegSize.X,
                                                                         _upperLegSize.Y,
                                                                         1);
            _leftUpperLegBody.Position = _spiderBody.Position - new Vector2(spiderBodyRadius, 0) -
                                         new Vector2(_upperLegSize.X / 2, 0);

            _leftLowerLegBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _lowerLegSize.X,
                                                                         _lowerLegSize.Y,
                                                                         1);
            _leftLowerLegBody.Position = _spiderBody.Position - new Vector2(spiderBodyRadius, 0) -
                                         new Vector2(_upperLegSize.X, 0) - new Vector2(_lowerLegSize.X / 2, 0);

            _rightUpperLegBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _upperLegSize.X,
                                                                          _upperLegSize.Y, 1);
            _rightUpperLegBody.Position = _spiderBody.Position + new Vector2(spiderBodyRadius, 0) +
                                          new Vector2(_upperLegSize.X / 2, 0);

            _rightLowerLegBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _lowerLegSize.X,
                                                                          _lowerLegSize.Y, 1);
            _rightLowerLegBody.Position = _spiderBody.Position + new Vector2(spiderBodyRadius, 0) +
                                          new Vector2(_upperLegSize.X, 0) + new Vector2(_lowerLegSize.X / 2, 0);

            //load geometries
            _spiderGeom       = GeomFactory.Instance.CreateCircleGeom(physicsSimulator, _spiderBody, spiderBodyRadius, 14);
            _leftUpperLegGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _leftUpperLegBody,
                                                                         _upperLegSize.X, _upperLegSize.Y);
            _leftLowerLegGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _leftLowerLegBody,
                                                                         _lowerLegSize.X, _lowerLegSize.Y);
            _rightUpperLegGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _rightUpperLegBody,
                                                                          _upperLegSize.X, _upperLegSize.Y);
            _rightLowerLegGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _rightLowerLegBody,
                                                                          _lowerLegSize.X, _lowerLegSize.Y);
            _spiderGeom.CollisionGroup        = _collisionGroup;
            _leftUpperLegGeom.CollisionGroup  = _collisionGroup;
            _leftLowerLegGeom.CollisionGroup  = _collisionGroup;
            _rightUpperLegGeom.CollisionGroup = _collisionGroup;
            _rightLowerLegGeom.CollisionGroup = _collisionGroup;

            //load joints
            JointFactory.Instance.CreateRevoluteJoint(physicsSimulator, _spiderBody,
                                                      _leftUpperLegBody,
                                                      _spiderBody.Position -
                                                      new Vector2(spiderBodyRadius, 0));
            _leftShoulderAngleJoint = JointFactory.Instance.CreateAngleJoint(physicsSimulator, _spiderBody,
                                                                             _leftUpperLegBody);
            _leftShoulderAngleJoint.TargetAngle = -.4f;
            _leftShoulderAngleJoint.MaxImpulse  = 300;

            JointFactory.Instance.CreateRevoluteJoint(physicsSimulator, _spiderBody,
                                                      _rightUpperLegBody,
                                                      _spiderBody.Position +
                                                      new Vector2(spiderBodyRadius, 0));
            _rightShoulderAngleJoint = JointFactory.Instance.CreateAngleJoint(physicsSimulator, _spiderBody,
                                                                              _rightUpperLegBody);
            _rightShoulderAngleJoint.TargetAngle = .4f;
            _leftShoulderAngleJoint.MaxImpulse   = 300;

            JointFactory.Instance.CreateRevoluteJoint(physicsSimulator, _leftUpperLegBody,
                                                      _leftLowerLegBody,
                                                      _spiderBody.Position -
                                                      new Vector2(spiderBodyRadius, 0) -
                                                      new Vector2(_upperLegSize.X, 0));
            _leftKneeAngleJoint = JointFactory.Instance.CreateAngleJoint(physicsSimulator, _leftUpperLegBody,
                                                                         _leftLowerLegBody);
            _leftKneeAngleJoint.TargetAngle = -_kneeTargetAngle;
            _leftKneeAngleJoint.MaxImpulse  = 300;

            JointFactory.Instance.CreateRevoluteJoint(physicsSimulator, _rightUpperLegBody,
                                                      _rightLowerLegBody,
                                                      _spiderBody.Position +
                                                      new Vector2(spiderBodyRadius, 0) +
                                                      new Vector2(_upperLegSize.X, 0));
            _rightKneeAngleJoint = JointFactory.Instance.CreateAngleJoint(physicsSimulator, _rightUpperLegBody,
                                                                          _rightLowerLegBody);
            _rightKneeAngleJoint.TargetAngle = _kneeTargetAngle;
            _rightKneeAngleJoint.MaxImpulse  = 300;
        }