当前位置: 首页>>代码示例>>C#>>正文


C# Dynamics.World类代码示例

本文整理汇总了C#中FarseerPhysics.Dynamics.World的典型用法代码示例。如果您正苦于以下问题:C# World类的具体用法?C# World怎么用?C# World使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


World类属于FarseerPhysics.Dynamics命名空间,在下文中一共展示了World类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Pyramid

        public Pyramid(World world, 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;

            // Physics
            _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;
            }

            //GFX
            _box = new Sprite(ContentWrapper.PolygonTexture(rect, "Square", ContentWrapper.Blue, ContentWrapper.Gold, ContentWrapper.Black, 1f));
        }
开发者ID:tinco,项目名称:Farseer-Physics,代码行数:34,代码来源:Pyramid.cs

示例2: Game

        public Game(UserControl userControl, Canvas drawingCanvas, Canvas debugCanvas, TextBlock txtDebug)
        {
            //Initialize
            IsActive = true;
            IsFixedTimeStep = true;
            TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 16);
            Components = new List<DrawableGameComponent>();
            World = new World(new Vector2(0, 0));
            _gameTime = new GameTime();
            _gameTime.GameStartTime = DateTime.Now;
            _gameTime.FrameStartTime = DateTime.Now;
            _gameTime.ElapsedGameTime = TimeSpan.Zero;
            _gameTime.TotalGameTime = TimeSpan.Zero;

            //Setup Canvas
            DrawingCanvas = drawingCanvas;
            DebugCanvas = debugCanvas;
            TxtDebug = txtDebug;
            UserControl = userControl;

            //Setup GameLoop
            _gameLoop = new Storyboard();
            _gameLoop.Completed += GameLoop;
            _gameLoop.Duration = TargetElapsedTime;
            DrawingCanvas.Resources.Add("gameloop", _gameLoop);
        }
开发者ID:hilts-vaughan,项目名称:Farseer-Physics,代码行数:26,代码来源:Game.cs

示例3: CreateChain

        /// <summary>
        /// Creates a chain.
        /// </summary>
        /// <param name="world">The world.</param>
        /// <param name="start">The start.</param>
        /// <param name="end">The end.</param>
        /// <param name="linkWidth">The width.</param>
        /// <param name="linkHeight">The height.</param>
        /// <param name="fixStart">if set to <c>true</c> [fix start].</param>
        /// <param name="fixEnd">if set to <c>true</c> [fix end].</param>
        /// <param name="numberOfLinks">The number of links.</param>
        /// <param name="linkDensity">The link density.</param>
        /// <returns></returns>
        public static Path CreateChain(World world, Vector2 start, Vector2 end, float linkWidth, float linkHeight, bool fixStart, bool fixEnd, int numberOfLinks, float linkDensity)
        {
            // Chain start / end
            Path path = new Path();
            path.Add(start);
            path.Add(end);

            // A single chainlink
            PolygonShape shape = new PolygonShape(PolygonTools.CreateRectangle(linkWidth, linkHeight));

            // Use PathManager to create all the chainlinks based on the chainlink created before.
            List<Body> chainLinks = PathManager.EvenlyDistibuteShapesAlongPath(world, path, shape, BodyType.Dynamic, numberOfLinks, linkDensity);

            if (fixStart)
            {
                // Fix the first chainlink to the world
                JointFactory.CreateFixedRevoluteJoint(world, chainLinks[0], new Vector2(0, -(linkHeight / 2)), chainLinks[0].Position);
            }

            if (fixEnd)
            {
                // Fix the last chainlink to the world
                JointFactory.CreateFixedRevoluteJoint(world, chainLinks[chainLinks.Count - 1], new Vector2(0, (linkHeight / 2)), chainLinks[chainLinks.Count - 1].Position);
            }

            // Attach all the chainlinks together with a revolute joint
            PathManager.AttachBodiesWithRevoluteJoint(world, chainLinks, new Vector2(0, -linkHeight), new Vector2(0, linkHeight),
                                                      false, false);

            return (path);
        }
开发者ID:scastle,项目名称:Solitude,代码行数:44,代码来源:LinkFactory.cs

示例4: CreateCompoundPolygon

 public static Body CreateCompoundPolygon(World world, List<Vertices> list, float density, Vector2 position = new Vector2(), float rotation = 0, BodyType bodyType = BodyType.Static, object userData = null)
 {
     //We create a single body
     Body polygonBody = CreateBody(world, position, rotation, bodyType);
     FixtureFactory.AttachCompoundPolygon(list, density, polygonBody, userData);
     return polygonBody;
 }
开发者ID:runegri,项目名称:NDC2014,代码行数:7,代码来源:BodyFactory.cs

示例5: Platform

 /// <summary>
 /// Initializes a new instance of the <see cref="Platform"/> class.
 /// </summary>
 /// <param name="description">The platform description.</param>
 /// <param name="physicsWorld">The physics world.</param>
 /// <param name="spriteBatch">The sprite batch to use for rendering.</param>
 /// <param name="contentManager">The game's content manager.</param>
 public Platform(PlatformDescription description, ref World physicsWorld, SpriteBatch spriteBatch, ContentManager contentManager)
 {
     this.spriteOffsets = new List<Vector2>();
     this.sprite = new Sprite();
     this.InitializeAndLoadSprites(spriteBatch, contentManager, description);
     this.SetUpPhysics(ref physicsWorld, description);
 }
开发者ID:K-Cully,项目名称:SticKart,代码行数:14,代码来源:Platform.cs

示例6: AIKnight

 public AIKnight(World world)
     : base(world)
 {
     BaseAttribute[UnitAttribute.Speed] = 3f;
     Body.Friction = 0f;
     Color = Color.Gray;
 }
开发者ID:ndssia,项目名称:Corsair3,代码行数:7,代码来源:AIKnight.cs

示例7: CreateInteractiveEntities

 /// <summary>
 /// Creates the bonuses, obstacles and power ups contained in a level.
 /// </summary>
 /// <param name="interactiveEntityDescriptions">A list of interactive entity descriptions.</param>
 /// <param name="physicsWorld">The physics world to create the entities in.</param>
 /// <param name="interactiveEntities">An empty list to store the interactive entities in.</param>
 /// <param name="mineCart">The mine cart entity.</param>
 /// <param name="cartSwitch">The switch entity.</param>
 /// <param name="spriteBatch">The sprite batch to use for rendering.</param>
 /// <param name="contentManager">The game's content manager.</param>
 public static void CreateInteractiveEntities(List<InteractiveEntityDescription> interactiveEntityDescriptions, ref World physicsWorld, ref List<InteractiveEntity> interactiveEntities, ref MineCart mineCart, ref Switch cartSwitch, SpriteBatch spriteBatch, ContentManager contentManager)
 {
     if (interactiveEntities.Count == 0)
     {
         foreach (InteractiveEntityDescription description in interactiveEntityDescriptions)
         {
             if (EntityConstants.PowerUpNames.Contains(description.Name))
             {
                 interactiveEntities.Add(new PowerUp(ref physicsWorld, spriteBatch, contentManager, description, EntitySettingsLoader.GetPowerUpSettings(description.Name)));
             }
             else if (EntityConstants.BonusNames.Contains(description.Name) || EntityConstants.ObstacleNames.Contains(description.Name))
             {
                 interactiveEntities.Add(new BonusOrObstacle(ref physicsWorld, spriteBatch, contentManager, description, EntitySettingsLoader.GetObstacleOrBonusSetting(description.Name)));
             }
             else if (description.Name == EntityConstants.CartBody)
             {
                 mineCart = new MineCart(spriteBatch, contentManager, ref physicsWorld, description.Position, 100.0f, 240.0f, 350.0f, 80.0f, -80.0f);
             }
             else if (description.Name == EntityConstants.Switch)
             {
                 cartSwitch = new Switch(spriteBatch, contentManager, ref physicsWorld, description.Position, mineCart);
             }
         }
     }
 }
开发者ID:K-Cully,项目名称:SticKart,代码行数:35,代码来源:LevelFactory.cs

示例8: PowerUp

        /// <summary>
        /// Initializes a new instance of the <see cref="PowerUp"/> class.
        /// </summary>
        /// <param name="physicsWorld">The physics world.</param>
        /// <param name="spriteBatch">The sprite batch to use for rendering.</param>
        /// <param name="contentManager">The game's content manager.</param>
        /// <param name="description">The entity description.</param>
        /// <param name="settings">The power up settings.</param>
        public PowerUp(ref World physicsWorld, SpriteBatch spriteBatch, ContentManager contentManager, InteractiveEntityDescription description, PowerUpSetting settings)
            : base(ref physicsWorld, description)
        {
            this.name = settings.Name;
            this.timeOfEffect = settings.TimeOfEffect;

            switch (this.name)
            {
                case EntityConstants.InvincibleName:
                    this.type = PowerUpType.Invincibility;
                    break;
                case EntityConstants.HealthName:
                    this.type = PowerUpType.Health;
                    break;
                case EntityConstants.JumpName:
                    this.type = PowerUpType.Jump;
                    break;
                case EntityConstants.SpeedName:
                    this.type = PowerUpType.Speed;
                    break;
                default:
                    this.type = PowerUpType.None;
                    break;
            }

            this.PhysicsBody.UserData = new InteractiveEntityUserData(InteractiveEntityType.PowerUp, this.timeOfEffect, this.type);
            this.InitializeAndLoad(spriteBatch, contentManager);
        }
开发者ID:K-Cully,项目名称:SticKart,代码行数:36,代码来源:PowerUp.cs

示例9: Border

        public Border(World _world)
        {
            _anchorBottom = BodyFactory.CreateLineArc(_world, 2* MathHelper.Pi, 100, 100, position: new Vector2 (40f, 36f));
            _anchorTop = BodyFactory.CreateLineArc(_world, MathHelper.Pi, 100, 100, position: new Vector2(40f, 36f), rotation: MathHelper.Pi);

            _exitBottom = BodyFactory.CreateLineArc(_world, 2 * MathHelper.Pi, 100, 110, position: new Vector2(40f, 36f));
            _exitTop = BodyFactory.CreateLineArc(_world, MathHelper.Pi, 100, 110, position: new Vector2(40f, 36f), rotation: MathHelper.Pi);

            _exitTop.OnCollision += OnCollision;
            _exitBottom.OnCollision += OnCollision;

            _exitTop.CollisionCategories = Category.All;
            _exitTop.CollidesWith = Category.All;

            _exitBottom.CollisionCategories = Category.All;
            _exitBottom.CollidesWith = Category.All;

            _anchorTop.CollisionCategories = Category.Cat5;  //.All & ~Category.Cat3 & ~Category.Cat2;
            _anchorTop.CollidesWith = Category.Cat1;//Category.All & ~Category.Cat3 & ~Category.Cat2; //collides with enemy and player

            _anchorBottom.CollisionCategories = Category.All & ~Category.Cat3;
            _anchorBottom.CollidesWith = Category.Cat1;//Category.All & ~Category.Cat3 & ~Category.Cat2;  //collides with enemy and player

            //_anchorTop.IsSensor = true;
            //_anchorTop.ContactList
            //_anchorBottom.OnSeparation += OnSeparation;
            //System.Diagnostics.Debug.WriteLine( _anchorTop.ContactList+"contact list");
        }
开发者ID:RiltonF,项目名称:MonogameAsteroids,代码行数:28,代码来源:Border.cs

示例10: Melee

 public Melee(Unit owner, World world)
     : base(owner, world)
 {
     Body.Position = owner.Position + new Vector2(-owner.Facing * 2.7f, -0.8f);
     _startingPosition = Body.Position;
     Body.ApplyLinearImpulse(new Vector2(-owner.Facing * Speed, 0));
 }
开发者ID:ndssia,项目名称:Corsair3,代码行数:7,代码来源:Melee.cs

示例11: TetrisPlayer

        public TetrisPlayer(Game game, World world)
            : base(game)
        {
            _world = world;

            tetrisShapes.Add(new bool[,] { { true, false }, { true, false }, { true, true } });
            tetrisShapes.Add(new bool[,] { { true, true, true }, { false, false, true } });
            tetrisShapes.Add(new bool[,] { { true, true }, { true, true } });
            tetrisShapes.Add(new bool[,] { { true, true, true }, { false, true, false } });
            tetrisShapes.Add(new bool[,] { { true }, { true }, { true }, { true } });
            tetrisShapes.Add(new bool[,] { { false, true, true }, { true, true, false } });
            tetrisShapes.Add(new bool[,] { { true, true, false }, { false, true, true } });
            tetrisShapes.Add(new bool[,] { { true } });
            tetrisShapes.Add(new bool[,] { { true }, { true } });
            tetrisShapes.Add(new bool[,] { { true }, { true }, { true } });

            tetrisProb.Add(1); // LL
            tetrisProb.Add(1); // LR
            tetrisProb.Add(4); // O
            tetrisProb.Add(2); // T
            tetrisProb.Add(4); // I
            tetrisProb.Add(1); // Z
            tetrisProb.Add(1); // MZ
            tetrisProb.Add(1); // I1
            tetrisProb.Add(1); // I2
            tetrisProb.Add(3); // I3

            Game1.Timers.Create(SPAWN_TIME, false, Spawn);
        }
开发者ID:northdocks,项目名称:ggj-2012-splash-damage,代码行数:29,代码来源:TetrisPlayer.cs

示例12: PhysicsGameEntity

 /// <summary>
 /// Constructs a FPE Body from the given list of vertices and density
 /// </summary>
 /// <param name="game"></param>
 /// <param name="world"></param>
 /// <param name="vertices">The collection of vertices in display units (pixels)</param>
 /// <param name="bodyType"></param>
 /// <param name="density"></param>
 public PhysicsGameEntity(Game game, World world, Category collisionCategory, Vertices vertices, BodyType bodyType, float density)
     : this(game,world,collisionCategory)
 {
     ConstructFromVertices(world,vertices,density);
     Body.BodyType = bodyType;
     Body.CollisionCategories = collisionCategory;
 }
开发者ID:dreasgrech,项目名称:FarseerPhysicsBaseFramework,代码行数:15,代码来源:PhysicsGameEntity.cs

示例13: LocalPlayer

        public LocalPlayer(World world, Vector2 position, Category collisionCat, float scale, float limbStrength, float limbDefense, bool evilSkin, Color color, PlayerIndex player)
            : base(world, position, collisionCat, scale, limbStrength, limbDefense, evilSkin, color)
        {
            this.player = player;
            punchBtnPressed = punchKeyPressed = false;
            kickBtnPressed = kickKeyPressed = false;
            shootBtnPressed = shootKeyPressed = false;
            trapBtnPressed = trapKeyPressed = false;
            usesKeyboard = !GamePad.GetState(player).IsConnected;
            lastShootAngle = 0f;

            jumpBtn = Buttons.A;
            rightBtn = Buttons.LeftThumbstickRight;
            leftBtn = Buttons.LeftThumbstickLeft;
            crouchBtn = Buttons.LeftTrigger;
            punchBtn = Buttons.X;
            kickBtn = Buttons.B;
            shootBtn = Buttons.RightTrigger;
            trapBtn = Buttons.Y;

            upKey = Keys.W;
            rightKey = Keys.D;
            leftKey = Keys.A;
            downKey = Keys.S;
            trapKey = Keys.T;
        }
开发者ID:TadCordle,项目名称:Project-Jack,代码行数:26,代码来源:LocalPlayer.cs

示例14: Serialize

 public static void Serialize(World world, string filename)
 {
     using (FileStream fs = new FileStream(filename, FileMode.Create))
     {
         new WorldXmlSerializer().Serialize(world, fs);
     }
 }
开发者ID:guozanhua,项目名称:KinectRagdoll,代码行数:7,代码来源:Serialization.cs

示例15: Wall

 public Wall(World world, WallCompiled wall)
 {
     if (wall.Shape == ShapeData.Closed) Fixtures = new Fixture[wall.Verts1.Length];
     else Fixtures = new Fixture[wall.Verts1.Length-1];
     for (int i = 0; i < wall.Verts1.Length-1; i++) addQuad(world, wall, i, i+1);
     if (wall.Shape == ShapeData.Closed) addQuad(world, wall, wall.Verts1.Length-1, 0);
 }
开发者ID:det,项目名称:Rimbalzo,代码行数:7,代码来源:Wall.cs


注:本文中的FarseerPhysics.Dynamics.World类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。