本文整理汇总了C#中FarseerPhysics.Dynamics.World类的典型用法代码示例。如果您正苦于以下问题:C# World类的具体用法?C# World怎么用?C# World使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
World类属于FarseerPhysics.Dynamics命名空间,在下文中一共展示了World类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: PlayerSelect
public PlayerSelect(int mode)
{
world = new World(Vector2.Zero);
backPressed = true;
confirmPressed = true;
upPressed = true;
downPressed = true;
showButton = false;
this.Mode = mode;
boxes = new List<PlayerSelectBox>();
boxes.Add(new PlayerSelectBox(new Vector2(270, 145), PlayerIndex.One, 0));
boxes.Add(new PlayerSelectBox(new Vector2(770, 145), PlayerIndex.Two, 1));
boxes.Add(new PlayerSelectBox(new Vector2(270, 550), PlayerIndex.Three, 2));
boxes.Add(new PlayerSelectBox(new Vector2(770, 550), PlayerIndex.Four, 3));
components = new List<Component>();
if (mode == 0)
{
components.Add(new CheckBox(new Vector2(1400, 300), "Free For All", "0"));
components.Add(new CheckBox(new Vector2(1400, 360), "Team Deathmatch", "1"));
components.Add(new CheckBox(new Vector2(1400, 420), "1 Vs All", "2"));
((CheckBox)components[0]).Checked = true;
}
components.Add(new Button(new Vector2(1500, 600), MainGame.tex_ps_next, "next"));
}
开发者ID:Kyle44,项目名称:Project-Jack,代码行数:27,代码来源:PlayerSelect.cs
示例17: Player
public Player(World world, float x, float y, Texture2D texture)
{
torso = BodyFactory.CreateRectangle(world, 60 * MainGame.PIXEL_TO_METER, 80 * MainGame.PIXEL_TO_METER, 1);
torso.Position = new Vector2(x * MainGame.PIXEL_TO_METER, y * MainGame.PIXEL_TO_METER);
torso.BodyType = BodyType.Dynamic;
torso.UserData = this;
legs = BodyFactory.CreateCircle(world, 31 * MainGame.PIXEL_TO_METER, 1);
legs.Position = torso.Position + new Vector2(0, 40 * MainGame.PIXEL_TO_METER);
legs.BodyType = BodyType.Dynamic;
legs.Friction = 5.0f;
legs.UserData = this;
JointFactory.CreateFixedAngleJoint(world, torso);
axis = JointFactory.CreateRevoluteJoint(world, torso, legs, Vector2.Zero);
axis.CollideConnected = false;
axis.MotorEnabled = true;
axis.MotorSpeed = 0.0f;
axis.MotorTorque = 3.0f;
axis.MaxMotorTorque = 10.0f;
onGround = false;
facingLeft = false;
jumpForce = new Vector2(0, -1f);
rightAirForce = new Vector2(5f, 0);
leftAirForce = -1 * rightAirForce;
prevVelocity = Vector2.Zero;
normal = Vector2.Zero;
pressW = false;
holdW = false;
texIdle = new AnimatedTexture(texture, 24, 0, 0, 120, 140);
texRun = new AnimatedTexture(texture, 19, 0, 140, 120, 140);
texJump = new AnimatedTexture(texture, 9, 19 * 120, 140, 120, 140, 1, false, false);
currentTexture = texIdle;
}
开发者ID:TadCordle,项目名称:MrGuyXNA,代码行数:33,代码来源:Player.cs
示例18: PathTile
public PathTile(List<Vector2> localPoints, Vector2 position, World world, bool MakroCollision = false)
{
body = new Body(world);
body.Position = ConvertUnits.ToSimUnits(position);
body.UserData = "Wall";
body.IsStatic = true;
Vertices terrain = new Vertices();
foreach (Vector2 point in localPoints)
{
terrain.Add(ConvertUnits.ToSimUnits(point));
}
for (int i = 0; i < terrain.Count - 1; ++i)
{
FixtureFactory.AttachEdge(terrain[i], terrain[i + 1], body);
body.FixtureList[i].UserData = "Wall";
}
body.Restitution = 0f;
body.Friction = float.MaxValue;
if (!MakroCollision)
body.CollisionCategories = Category.Cat15 & ~Category.Cat3;
else
body.CollidesWith = Category.Cat29;
}
开发者ID:CWentz,项目名称:ParasiteParadiseOriginal,代码行数:26,代码来源:PathTile.cs
示例19: LinearMovingPlatform
// Constructor
public LinearMovingPlatform(World world, Vector2 initialPosition, Vector2 finalPosition, float nearTargetPositionDistance, float width, float speed, bool reverse)
: base(world, initialPosition, finalPosition, width, speed)
{
Vector2 startPosition;
if (!reverse)
{
movingTowardFinal = true;
startPosition = initialPosition;
}
else
{
movingTowardFinal = false;
startPosition = finalPosition;
}
SetUpPlatformTile(startPosition);
this.nearTargetPositionDistance = ConvertUnits.ToSimUnits(nearTargetPositionDistance);
// calculate the maximum velocity
// it depends on the angle between the initial and final position
Vector2 displacementFromFinalToInitial = new Vector2(finalPosition.X - initialPosition.X, finalPosition.Y - initialPosition.Y);
if (displacementFromFinalToInitial.X <= 0)
{
maxVelocity = new Vector2(0, speed);
}
else if (displacementFromFinalToInitial.Y <= 0)
{
maxVelocity = new Vector2(speed, 0);
}
else
{
double angle = Math.Atan2(displacementFromFinalToInitial.X, displacementFromFinalToInitial.Y);
maxVelocity = new Vector2(speed * (float)Math.Sin(angle), speed * (float)Math.Cos(angle));
}
}
开发者ID:psykano,项目名称:STFU-xna,代码行数:36,代码来源:LinearMovingPlatform.cs
示例20: PinballMiniGame
public PinballMiniGame(GraphicsDevice graphicsDevice)
{
this.graphicsDevice = graphicsDevice;
sb = new SpriteBatch(graphicsDevice);
ein = new Kinect(0, 0);
ein.Init();
circleTexture = CreateCircle(ball_radius, graphicsDevice);
gameState = MiniGameState.Initialized;
physicsWorld = new World(new Vector2(0, .982f));
paddleSize = new Vector2(300, 16);
paddleLeft = BodyFactory.CreateRectangle(physicsWorld, paddleSize.X * 2 * pixelToUnit, paddleSize.Y * pixelToUnit, 1000f);
paddleLeft.BodyType = BodyType.Dynamic;
paddleLeft.Position = new Vector2(8 * pixelToUnit, (GameConstants.MiniGameCanvasHeight - 100) * pixelToUnit);
paddleLeft.LocalCenter = new Vector2(0, 0);
paddleLeft.SleepingAllowed = false;
paddleLeft.Restitution = 1.0f;
paddleLeft.IgnoreGravity = true;
ball = BodyFactory.CreateCircle(physicsWorld, (ball_radius) * pixelToUnit, 1000f);
ball.BodyType = BodyType.Dynamic;
ball.Position = new Vector2(100 * pixelToUnit, 100 * pixelToUnit);
ball.Restitution = 1.0f;
ball.SleepingAllowed = false;
}
开发者ID:GriffinLedingham,项目名称:hacklandia,代码行数:29,代码来源:PinballMiniGame.cs
注:本文中的FarseerPhysics.Dynamics.World类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论