Example #1
0
        public Spider(World world, PhysicsGameScreen screen, Vector2 position)
        {
            //Load bodies
            _circle          = BodyFactory.CreateCircle(world, SpiderBodyRadius, 0.1f, position);
            _circle.BodyType = BodyType.Dynamic;

            //Left upper leg
            _leftUpper = BodyFactory.CreateRectangle(world, _upperLegSize.X, _upperLegSize.Y, 0.1f,
                                                     _circle.Position - new Vector2(SpiderBodyRadius, 0f) -
                                                     new Vector2(_upperLegSize.X / 2f, 0f));
            _leftUpper.BodyType = BodyType.Dynamic;

            //Left lower leg
            _leftLower = BodyFactory.CreateRectangle(world, _lowerLegSize.X, _lowerLegSize.Y, 0.1f,
                                                     _circle.Position - new Vector2(SpiderBodyRadius, 0f) -
                                                     new Vector2(_upperLegSize.X, 0f) -
                                                     new Vector2(_lowerLegSize.X / 2f, 0f));
            _leftLower.BodyType = BodyType.Dynamic;

            //Right upper leg
            _rightUpper = BodyFactory.CreateRectangle(world, _upperLegSize.X, _upperLegSize.Y, 0.1f,
                                                      _circle.Position + new Vector2(SpiderBodyRadius, 0f) +
                                                      new Vector2(_upperLegSize.X / 2f, 0f));
            _rightUpper.BodyType = BodyType.Dynamic;

            //Right lower leg
            _rightLower = BodyFactory.CreateRectangle(world, _lowerLegSize.X, _lowerLegSize.Y, 0.1f,
                                                      _circle.Position + new Vector2(SpiderBodyRadius, 0f) +
                                                      new Vector2(_upperLegSize.X, 0f) +
                                                      new Vector2(_lowerLegSize.X / 2f, 0f));
            _rightLower.BodyType = BodyType.Dynamic;

            //Create joints
            JointFactory.CreateRevoluteJoint(world, _circle, _leftUpper, new Vector2(_upperLegSize.X / 2f, 0f));
            _leftShoulderAngleJoint            = JointFactory.CreateAngleJoint(world, _circle, _leftUpper);
            _leftShoulderAngleJoint.MaxImpulse = 3f;

            JointFactory.CreateRevoluteJoint(world, _circle, _rightUpper, new Vector2(-_upperLegSize.X / 2f, 0f));
            _rightShoulderAngleJoint            = JointFactory.CreateAngleJoint(world, _circle, _rightUpper);
            _rightShoulderAngleJoint.MaxImpulse = 3f;

            JointFactory.CreateRevoluteJoint(world, _leftUpper, _leftLower, new Vector2(_lowerLegSize.X / 2f, 0f));
            _leftKneeAngleJoint            = JointFactory.CreateAngleJoint(world, _leftUpper, _leftLower);
            _leftKneeAngleJoint.MaxImpulse = 3f;

            JointFactory.CreateRevoluteJoint(world, _rightUpper, _rightLower, new Vector2(-_lowerLegSize.X / 2f, 0f));
            _rightKneeAngleJoint            = JointFactory.CreateAngleJoint(world, _rightUpper, _rightLower);
            _rightKneeAngleJoint.MaxImpulse = 3;

            _screen = screen;

            //GFX
            AssetCreator creator = _screen.ScreenManager.Assets;

            _torso    = new Sprite(creator.CircleTexture(SpiderBodyRadius, MaterialType.Waves, Color.Gray, 1f));
            _upperLeg = new Sprite(creator.TextureFromShape(_leftUpper.FixtureList[0].Shape,
                                                            MaterialType.Blank, Color.DimGray, 1f));
            _lowerLeg = new Sprite(creator.TextureFromShape(_leftLower.FixtureList[0].Shape,
                                                            MaterialType.Blank, Color.DarkSlateGray, 1f));
        }
 public static void SetGeneral(ContentManager content, GraphicsDevice device, World World)
 {
     Globals.content = content;
     Globals.Device = device;
     AssetCreatorr = new AssetCreator(device);
     Globals.World = World;
 }
Example #3
0
        /// <summary>
        /// Load your graphics content.
        /// </summary>
        protected override void LoadContent()
        {
            _spriteBatch  = new SpriteBatch(GraphicsDevice);
            _lineBatch    = new LineBatch(GraphicsDevice);
            _assetCreator = new AssetCreator(GraphicsDevice);
            _assetCreator.LoadContent(_contentManager);
            _input.LoadContent();

            // Tell each of the screens to load their content.
            foreach (GameScreen screen in _screens)
            {
                screen.LoadContent();
            }
        }
Example #4
0
        private void CreateGFX()
        {
            AssetCreator creator = _screen.ScreenManager.Assets;

            _face  = new Sprite(creator.CircleTexture(0.9f, MaterialType.Squares, Color.Gray, 1f));
            _torso = new Sprite(creator.TextureFromVertices(PolygonTools.CreateRoundedRectangle(2f, 4f, 0.5f, 0.7f, 2),
                                                            MaterialType.Squares, Color.LightSlateGray, 0.8f));

            _upperArm = new Sprite(creator.TextureFromVertices(PolygonTools.CreateCapsule(1.9f, 0.45f, 16),
                                                               MaterialType.Squares, Color.DimGray, 0.8f));
            _lowerArm = new Sprite(creator.TextureFromVertices(PolygonTools.CreateCapsule(1.9f, 0.45f, 16),
                                                               MaterialType.Squares, Color.DarkSlateGray, 0.8f));

            _upperLeg = new Sprite(creator.TextureFromVertices(PolygonTools.CreateCapsule(2f, 0.5f, 16),
                                                               MaterialType.Squares, Color.DimGray, 0.8f));
            _lowerLeg = new Sprite(creator.TextureFromVertices(PolygonTools.CreateCapsule(2f, 0.5f, 16),
                                                               MaterialType.Squares, Color.DarkSlateGray, 0.8f));
        }
Example #5
0
        public Pyramid(World world, PhysicsGameScreen screen, Vector2 position, int count, float density)
        {
            Vertices     rect  = PolygonTools.CreateRectangle(0.5f, 0.5f);
            PolygonShape shape = new PolygonShape(rect, density);

            Vector2 rowStart = position;

            rowStart.Y -= 0.5f + count * 1.1f;

            Vector2     deltaRow = new Vector2(-0.625f, 1.1f);
            const float spacing  = 1.25f;

            _boxes = new List <Body>();

            for (int i = 0; i < count; ++i)
            {
                Vector2 pos = rowStart;

                for (int j = 0; j < i + 1; ++j)
                {
                    Body body = BodyFactory.CreateBody(world);
                    body.BodyType = BodyType.Dynamic;
                    body.Position = pos;
                    body.CreateFixture(shape);
                    _boxes.Add(body);

                    pos.X += spacing;
                }

                rowStart += deltaRow;
            }

            _screen = screen;

            //GFX
            AssetCreator creator = _screen.ScreenManager.Assets;

            _box = new Sprite(creator.TextureFromVertices(rect, MaterialType.Dots, Color.SaddleBrown, 2f));
        }
Example #6
0
        public Agent(World world, PhysicsGameScreen screen, Vector2 position)
        {
            _collidesWith        = Category.All;
            _collisionCategories = Category.All;

            _agentBody          = BodyFactory.CreateBody(world, position);
            _agentBody.BodyType = BodyType.Dynamic;

            //Center
            FixtureFactory.AttachCircle(0.5f, 0.5f, _agentBody);

            //Left arm
            FixtureFactory.AttachRectangle(1.5f, 0.4f, 1f, new Vector2(-1f, 0f), _agentBody);
            FixtureFactory.AttachCircle(0.5f, 0.5f, _agentBody, new Vector2(-2f, 0f));

            //Right arm
            FixtureFactory.AttachRectangle(1.5f, 0.4f, 1f, new Vector2(1f, 0f), _agentBody);
            FixtureFactory.AttachCircle(0.5f, 0.5f, _agentBody, new Vector2(2f, 0f));

            //Top arm
            FixtureFactory.AttachRectangle(0.4f, 1.5f, 1f, new Vector2(0f, 1f), _agentBody);
            FixtureFactory.AttachCircle(0.5f, 0.5f, _agentBody, new Vector2(0f, 2f));

            //Bottom arm
            FixtureFactory.AttachRectangle(0.4f, 1.5f, 1f, new Vector2(0f, -1f), _agentBody);
            FixtureFactory.AttachCircle(0.5f, 0.5f, _agentBody, new Vector2(0f, -2f));

            _screen = screen;

            //GFX
            AssetCreator creator = _screen.ScreenManager.Assets;

            _box = new Sprite(creator.TextureFromVertices(PolygonTools.CreateRectangle(1.75f, 0.2f),
                                                          MaterialType.Blank, Color.White, 1f));
            _knob   = new Sprite(creator.CircleTexture(0.5f, MaterialType.Blank, Color.Orange, 1f));
            _offset = ConvertUnits.ToDisplayUnits(2f);
        }
        public override void LoadContent()
        {
            base.LoadContent();

            World.Gravity = new Vector2(0f, 10f);

            HasCursor           = false;
            EnableCameraControl = true;
            HasVirtualStick     = true;

            _hzFront  = 8.5f;
            _hzBack   = 5.0f;
            _zeta     = 0.85f;
            _maxSpeed = 50.0f;

#if WINDOWS_PHONE
            _scale = 2f / 3f;
#else
            _scale = 1f;
#endif

            // terrain
            _ground = new Body(World);
            {
                Vertices terrain = new Vertices();
                terrain.Add(new Vector2(-20f, -5f));
                terrain.Add(new Vector2(-20f, 0f));
                terrain.Add(new Vector2(20f, 0f));
                terrain.Add(new Vector2(25f, -0.25f));
                terrain.Add(new Vector2(30f, -1f));
                terrain.Add(new Vector2(35f, -4f));
                terrain.Add(new Vector2(40f, 0f));
                terrain.Add(new Vector2(45f, 0f));
                terrain.Add(new Vector2(50f, 1f));
                terrain.Add(new Vector2(55f, 2f));
                terrain.Add(new Vector2(60f, 2f));
                terrain.Add(new Vector2(65f, 1.25f));
                terrain.Add(new Vector2(70f, 0f));
                terrain.Add(new Vector2(75f, -0.3f));
                terrain.Add(new Vector2(80f, -1.5f));
                terrain.Add(new Vector2(85f, -3.5f));
                terrain.Add(new Vector2(90f, 0f));
                terrain.Add(new Vector2(95f, 0.5f));
                terrain.Add(new Vector2(100f, 1f));
                terrain.Add(new Vector2(105f, 2f));
                terrain.Add(new Vector2(110f, 2.5f));
                terrain.Add(new Vector2(115f, 1.3f));
                terrain.Add(new Vector2(120f, 0f));
                terrain.Add(new Vector2(160f, 0f));
                terrain.Add(new Vector2(159f, 10f));
                terrain.Add(new Vector2(201f, 10f));
                terrain.Add(new Vector2(200f, 0f));
                terrain.Add(new Vector2(240f, 0f));
                terrain.Add(new Vector2(250f, -5f));
                terrain.Add(new Vector2(250f, 10f));
                terrain.Add(new Vector2(270f, 10f));
                terrain.Add(new Vector2(270f, 0));
                terrain.Add(new Vector2(310f, 0));
                terrain.Add(new Vector2(310f, -5));

                for (int i = 0; i < terrain.Count - 1; ++i)
                {
                    FixtureFactory.AttachEdge(terrain[i], terrain[i + 1], _ground);
                }

                _ground.Friction = 0.6f;
            }

            // teeter board
            {
                _board          = new Body(World);
                _board.BodyType = BodyType.Dynamic;
                _board.Position = new Vector2(140.0f, -1.0f);

                PolygonShape box = new PolygonShape(1f);
                box.SetAsBox(10.0f, 0.25f);
                _teeter =
                    new Sprite(ScreenManager.Assets.TextureFromShape(box, MaterialType.Pavement, Color.LightGray, 1.2f));

                _board.CreateFixture(box);

                RevoluteJoint teeterAxis = JointFactory.CreateRevoluteJoint(_ground, _board, Vector2.Zero);
                teeterAxis.LowerLimit   = -8.0f * Settings.Pi / 180.0f;
                teeterAxis.UpperLimit   = 8.0f * Settings.Pi / 180.0f;
                teeterAxis.LimitEnabled = true;
                World.AddJoint(teeterAxis);

                _board.ApplyAngularImpulse(-100.0f);
            }

            // bridge
            {
                _bridgeSegments = new List <Body>();

                const int    segmentCount = 20;
                PolygonShape shape        = new PolygonShape(1f);
                shape.SetAsBox(1.0f, 0.125f);
                _bridge =
                    new Sprite(ScreenManager.Assets.TextureFromShape(shape, MaterialType.Dots, Color.SandyBrown, 1f));

                Body prevBody = _ground;
                for (int i = 0; i < segmentCount; ++i)
                {
                    Body body = new Body(World);
                    body.BodyType = BodyType.Dynamic;
                    body.Position = new Vector2(161f + 2f * i, 0.125f);
                    Fixture fix = body.CreateFixture(shape);
                    fix.Friction = 0.6f;
                    JointFactory.CreateRevoluteJoint(World, prevBody, body, -Vector2.UnitX);

                    prevBody = body;
                    _bridgeSegments.Add(body);
                }
                JointFactory.CreateRevoluteJoint(World, _ground, prevBody, Vector2.UnitX);
            }

            // boxes
            {
                _boxes = new List <Body>();
                PolygonShape box = new PolygonShape(1f);
                box.SetAsBox(0.5f, 0.5f);
                _box =
                    new Sprite(ScreenManager.Assets.TextureFromShape(box, MaterialType.Squares, Color.SaddleBrown, 2f));

                Body body = new Body(World);
                body.BodyType = BodyType.Dynamic;
                body.Position = new Vector2(220f, -0.5f);
                body.CreateFixture(box);
                _boxes.Add(body);

                body          = new Body(World);
                body.BodyType = BodyType.Dynamic;
                body.Position = new Vector2(220f, -1.5f);
                body.CreateFixture(box);
                _boxes.Add(body);

                body          = new Body(World);
                body.BodyType = BodyType.Dynamic;
                body.Position = new Vector2(220f, -2.5f);
                body.CreateFixture(box);
                _boxes.Add(body);
            }

            // car
            {
                Vertices vertices = new Vertices(8);
                vertices.Add(new Vector2(-2.5f, 0.08f));
                vertices.Add(new Vector2(-2.375f, -0.46f));
                vertices.Add(new Vector2(-0.58f, -0.92f));
                vertices.Add(new Vector2(0.46f, -0.92f));
                vertices.Add(new Vector2(2.5f, -0.17f));
                vertices.Add(new Vector2(2.5f, 0.205f));
                vertices.Add(new Vector2(2.3f, 0.33f));
                vertices.Add(new Vector2(-2.25f, 0.35f));

                PolygonShape chassis = new PolygonShape(vertices, 2f);

                _car          = new Body(World);
                _car.BodyType = BodyType.Dynamic;
                _car.Position = new Vector2(0.0f, -1.0f);
                _car.CreateFixture(chassis);

                _wheelBack          = new Body(World);
                _wheelBack.BodyType = BodyType.Dynamic;
                _wheelBack.Position = new Vector2(-1.709f, -0.78f);
                Fixture fix = _wheelBack.CreateFixture(new CircleShape(0.5f, 0.8f));
                fix.Friction = 0.9f;

                _wheelFront          = new Body(World);
                _wheelFront.BodyType = BodyType.Dynamic;
                _wheelFront.Position = new Vector2(1.54f, -0.8f);
                _wheelFront.CreateFixture(new CircleShape(0.5f, 1f));

                Vector2 axis = new Vector2(0.0f, -1.2f);
                _springBack                = new WheelJoint(_car, _wheelBack, _wheelBack.Position, axis);
                _springBack.MotorSpeed     = 0.0f;
                _springBack.MaxMotorTorque = 20.0f;
                _springBack.MotorEnabled   = true;
                //_springBack.Frequency = _hzBack;
                //_springBack.DampingRatio = _zeta;
                World.AddJoint(_springBack);

                _springFront                = new WheelJoint(_car, _wheelFront, _wheelFront.Position, axis);
                _springFront.MotorSpeed     = 0.0f;
                _springFront.MaxMotorTorque = 10.0f;
                _springFront.MotorEnabled   = false;
                //_springFront.Frequency = _hzFront;
                //_springFront.DampingRatio = _zeta;
                World.AddJoint(_springFront);

                _carBody = new Sprite(ScreenManager.Content.Load <Texture2D>("Samples/car"),
                                      AssetCreator.CalculateOrigin(_car) / _scale);
                _wheel = new Sprite(ScreenManager.Content.Load <Texture2D>("Samples/wheel"));
            }

            Camera.MinRotation = -0.05f;
            Camera.MaxRotation = 0.05f;

            Camera.TrackingBody   = _car;
            Camera.EnableTracking = true;
        }
        /// <summary>
        /// Load your graphics content.
        /// </summary>
        protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);
            _lineBatch = new LineBatch(GraphicsDevice);
            _assetCreator = new AssetCreator(GraphicsDevice);
            _assetCreator.LoadContent(_contentManager);
            _input.LoadContent();

            // Tell each of the screens to load their content.
            foreach (GameScreen screen in _screens)
            {
                screen.LoadContent();
            }
        }
Example #9
0
        public Objects(World world, PhysicsGameScreen screen, Vector2 startPosition, Vector2 endPosition, int count,
                       float radius, ObjectType type)
        {
            _bodies             = new List <Body>(count);
            CollidesWith        = Category.All;
            CollisionCategories = Category.All;

            for (int i = 0; i < count; ++i)
            {
                switch (type)
                {
                case ObjectType.Circle:
                    _bodies.Add(BodyFactory.CreateCircle(world, radius, 1f));
                    break;

                case ObjectType.Rectangle:
                    _bodies.Add(BodyFactory.CreateRectangle(world, radius, radius, 1f));
                    break;

                case ObjectType.Star:
                    _bodies.Add(BodyFactory.CreateGear(world, radius, 10, 0f, 1f, 1f));
                    break;

                case ObjectType.Gear:
                    _bodies.Add(BodyFactory.CreateGear(world, radius, 10, 100f, 1f, 1f));
                    break;
                }
            }

            for (int i = 0; i < _bodies.Count; ++i)
            {
                Body body = _bodies[i];
                body.BodyType            = BodyType.Dynamic;
                body.Position            = Vector2.Lerp(startPosition, endPosition, i / (float)(count - 1));
                body.Restitution         = .7f;
                body.Friction            = .2f;
                body.CollisionCategories = CollisionCategories;
                body.CollidesWith        = CollidesWith;
            }

            _screen = screen;

            //GFX
            AssetCreator creator = _screen.ScreenManager.Assets;

            switch (type)
            {
            case ObjectType.Circle:
                _object = new Sprite(creator.CircleTexture(radius, MaterialType.Dots, Color.DarkRed, 0.8f));
                break;

            case ObjectType.Rectangle:
                _object =
                    new Sprite(creator.TextureFromVertices(PolygonTools.CreateRectangle(radius / 2f, radius / 2f),
                                                           MaterialType.Dots, Color.Blue, 0.8f));
                break;

            case ObjectType.Star:
                _object = new Sprite(creator.TextureFromVertices(PolygonTools.CreateGear(radius, 10, 0f, 1f),
                                                                 MaterialType.Dots, Color.Yellow, 0.8f));
                break;

            case ObjectType.Gear:
                _object = new Sprite(creator.TextureFromVertices(PolygonTools.CreateGear(radius, 10, 100f, 1f),
                                                                 MaterialType.Dots, Color.DarkGreen, 0.8f));
                break;
            }
        }
Example #10
0
        public override void LoadContent()
        {
            // We add to the GameServices objects that we want to be able to use accross different classes
            // without having to pass them explicitly every time.
            GraphicsDevice = GameServices.GetService<GraphicsDevice>();
            Content = GameServices.GetService<ContentManager>();
            graphics = GameServices.GetService<GraphicsDeviceManager>();
            soundManager = GameServices.GetService<SoundManager>();

            ScreenManager.AddScreen(RankScreen, null, false);
            ScreenManager.AddScreen(PauseScreen, null, false);

            world = new World(new Vector2(0, 0));
            GameServices.AddService<World>(world);

            this.world.ContactManager.PostSolve += new PostSolveDelegate(PostSolve);

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Create a new track
            randomRaceTrack = RandomTrack.createTrack();

            randomRaceTrack.polygonList = polygonsList;

            int[] crucialPoints = { 300, 600, 1000 };
            Logic = new GameLogic(crucialPoints, randomRaceTrack.curvePointsMiddle.Count);

            randomRaceTrack.gameLogic = Logic;
            Logic.DidFinishLap += randomRaceTrack.ResetStickyNotes;

            mySneezesManager.randomTrack = randomRaceTrack;

            LoadPaperEffect();

            screenRenderer = new ScreenRenderer();
            GameServices.AddService<ScreenRenderer>(screenRenderer);
            Logic.DidEliminateCar += screenRenderer.setSadToPlayer;
            Logic.DidFinishLap += screenRenderer.setLap;

            for (int i = 0; i < 4; i++)
            {
                Car aCar = new Car(world, Content.Load<Texture2D>("Images/small_car"), Color.White, randomRaceTrack, i, playerIndexes[i]);
                Cars.Add(aCar);
            }

            assetCreator = new AssetCreator(graphics.GraphicsDevice);
            assetCreator.LoadContent(this.Content);

            defaultViewport = GraphicsDevice.Viewport;

            isFullHd=(ScreenManager.preferredHeight!=720);

            // Single screen mode only
            cameraFollowing = new Camera(defaultViewport, Vector2.Zero, new Vector2(defaultViewport.Width / 2, defaultViewport.Height / 2), 0.0f, Cars.Count, isFullHd);
            //ZOOM:

            //low res:
            //0.95 for 2 players
            //0.93 for 3 players
            //0.91 for 4 players

            //high res:
            //0.95 for 4 players

            GameServices.AddService<Camera>(cameraFollowing);

            mySneezesManager.camera = cameraFollowing;

            //generate starting positions and angles
            int startingPoint = 0;
               // positionCars(startingPoint);

            _debugView = new DebugViewXNA(world);
            _debugView.AppendFlags(FarseerPhysics.DebugViewFlags.Shape);
            _debugView.AppendFlags(FarseerPhysics.DebugViewFlags.DebugPanel);
            _debugView.AppendFlags(FarseerPhysics.DebugViewFlags.PerformanceGraph);
            _debugView.AppendFlags(FarseerPhysics.DebugViewFlags.Joint);
            _debugView.AppendFlags(FarseerPhysics.DebugViewFlags.ContactPoints);
            _debugView.AppendFlags(FarseerPhysics.DebugViewFlags.ContactNormals);
            _debugView.AppendFlags(FarseerPhysics.DebugViewFlags.Controllers);
            _debugView.AppendFlags(FarseerPhysics.DebugViewFlags.CenterOfMass);
            _debugView.AppendFlags(FarseerPhysics.DebugViewFlags.AABB);
            _debugView.DefaultShapeColor = Color.White;
            _debugView.SleepingShapeColor = Color.LightGray;
            _debugView.LoadContent(GraphicsDevice, Content);

            basicVert = new VertexPositionColorTexture[maxNumberOfTriangles];
            for (int i = 0; i < maxNumberOfTriangles; i++) basicVert[i].TextureCoordinate = new Vector2(-1);

            verticesBorders = new VertexPositionColorTexture[randomRaceTrack.curvePointsInternal.Count];

            fluid = new Fluid();
            fluid.Init();

            currentPoses = new Vector2[4];
            prevPoses = new Vector2[4];

            currentMousePos = new Vector2(100);
            prevMousePos = new Vector2(0);

            quad = new QuadRenderComponent(ScreenManager.Game, cameraFollowing, ScreenManager.GraphicsDevice.Viewport.Width, ScreenManager.GraphicsDevice.Viewport.Height);
            ScreenManager.Game.Components.Add(quad);

            fluidUpdateThread = new Thread(this.UpdateFluid);
            fluidUpdateThread.Start();

            mySneezesManager.fluid = fluid;

            fluidEffect = Content.Load<Effect>("Shaders/FluidEffect");
            fluidEffect.Parameters["random"].SetValue(randomTex);

            texInk = new Texture2D(graphics.GraphicsDevice,
                fluid.m_w, fluid.m_h, true,
                SurfaceFormat.Color);
            buffer = new RenderTarget2D(GraphicsDevice, ScreenManager.GraphicsDevice.Viewport.Width, ScreenManager.GraphicsDevice.Viewport.Height, true,
                SurfaceFormat.Color, GraphicsDevice.PresentationParameters.DepthStencilFormat);

            //gaussian = new GaussianBlur(ScreenManager.Game);
        }
Example #11
0
        public TheoJansenWalker(World world, PhysicsGameScreen screen, Vector2 position)
        {
            _position   = position;
            _motorSpeed = 2.0f;
            _motorOn    = true;
            _screen     = screen;

            _walkerJoints = new List <DistanceJoint>();

            _leftShoulders  = new Body[3];
            _rightShoulders = new Body[3];
            _leftLegs       = new Body[3];
            _rightLegs      = new Body[3];

            Vector2 pivot = new Vector2(0f, -0.8f);

            // Chassis
            {
                PolygonShape shape = new PolygonShape(1f);
                shape.SetAsBox(2.5f, 1.0f);

                _body =
                    new Sprite(_screen.ScreenManager.Assets.TextureFromShape(shape, MaterialType.Blank,
                                                                             Color.Beige, 1f));

                _chassis          = BodyFactory.CreateBody(world);
                _chassis.BodyType = BodyType.Dynamic;
                _chassis.Position = pivot + _position;

                Fixture fixture = _chassis.CreateFixture(shape);
                fixture.CollisionGroup = -1;
            }

            {
                CircleShape shape = new CircleShape(1.6f, 1f);
                _engine =
                    new Sprite(_screen.ScreenManager.Assets.TextureFromShape(shape, MaterialType.Waves,
                                                                             Color.Beige * 0.8f, 1f));

                _wheel          = BodyFactory.CreateBody(world);
                _wheel.BodyType = BodyType.Dynamic;
                _wheel.Position = pivot + _position;

                Fixture fixture = _wheel.CreateFixture(shape);
                fixture.CollisionGroup = -1;
            }

            {
                _motorJoint = new RevoluteJoint(_wheel, _chassis, _wheel.GetLocalPoint(_chassis.Position), Vector2.Zero);
                _motorJoint.CollideConnected = false;
                _motorJoint.MotorSpeed       = _motorSpeed;
                _motorJoint.MaxMotorTorque   = 400f;
                _motorJoint.MotorEnabled     = _motorOn;
                world.AddJoint(_motorJoint);
            }

            Vector2 wheelAnchor = pivot + new Vector2(0f, 0.8f);

            CreateLegTextures();

            CreateLeg(world, -1f, wheelAnchor, 0);
            CreateLeg(world, 1f, wheelAnchor, 0);

            _leftLeg.Origin       = AssetCreator.CalculateOrigin(_leftLegs[0]);
            _leftShoulder.Origin  = AssetCreator.CalculateOrigin(_leftShoulders[0]);
            _rightLeg.Origin      = AssetCreator.CalculateOrigin(_rightLegs[0]);
            _rightShoulder.Origin = AssetCreator.CalculateOrigin(_rightShoulders[0]);

            _wheel.SetTransform(_wheel.Position, 120f * Settings.Pi / 180f);
            CreateLeg(world, -1f, wheelAnchor, 1);
            CreateLeg(world, 1f, wheelAnchor, 1);

            _wheel.SetTransform(_wheel.Position, -120f * Settings.Pi / 180f);
            CreateLeg(world, -1f, wheelAnchor, 2);
            CreateLeg(world, 1f, wheelAnchor, 2);
        }