本文整理汇总了C#中FarseerPhysics.Collision.Shapes.CircleShape类的典型用法代码示例。如果您正苦于以下问题:C# CircleShape类的具体用法?C# CircleShape怎么用?C# CircleShape使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CircleShape类属于FarseerPhysics.Collision.Shapes命名空间,在下文中一共展示了CircleShape类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Bullet
protected Bullet(Ship parent, Vector2 offset, Vector2 speed, string texture)
: base(parent, texture, parent.Size)
{
Sprite.Origin = new Vector2f(Sprite.Texture.Size.X / 2f, 0);
#region Body Initialize
Body = new Body(State.World);
Body.BodyType = BodyType.Dynamic;
Body.IsBullet = true;
var shape = new CircleShape((0.15f / 4) * parent.Size, 0);
Body.CreateFixture(shape);
Body.Position = parent.Body.Position + parent.Body.GetWorldVector(offset);
Body.Rotation = parent.Body.Rotation;
Body.OnCollision += (a, b, contact) =>
{
if (!Collision(a, b, contact))
return false;
Dead = true;
return false;
};
Body.LinearVelocity = Parent.Body.LinearVelocity + Parent.Body.GetWorldVector(speed);
Body.UserData = this;
#endregion
}
开发者ID:Rohansi,项目名称:FPCompo11,代码行数:28,代码来源:Bullet.cs
示例2: onGridSizeChanged
private void onGridSizeChanged(object sender, SizeChangedEventArgs e) {
Debug.WriteLine("width: " + LayoutRoot.ActualWidth + " height: " + LayoutRoot.ActualHeight);
if (ball == null) {
float width = (float)LayoutRoot.ActualWidth;
float height = (float)LayoutRoot.ActualHeight;
ballBody = BodyFactory.CreateBody(world, new Vector2(ConvertUnits.ToSimUnits(width / 2f), ConvertUnits.ToSimUnits(height / 2f)));
ballBody.BodyType = BodyType.Dynamic;
ballBody.LinearDamping = 1f;
CircleShape circleShape = new CircleShape(ConvertUnits.ToSimUnits(8f), 1f);
Fixture fixture = ballBody.CreateFixture(circleShape);
fixture.OnCollision += OnBalCollision;
ball = new Ball(canvas, 8, new System.Windows.Point(width / 2f, height / 2f));
}
if (level == null) {
level = new Level(currentLevel, canvas);
Body wallBody;
System.Windows.Point position;
foreach (Wall wall in level.getWalls()) {
position = wall.getPosition();
wallBody = BodyFactory.CreateRectangle(
world,
ConvertUnits.ToSimUnits(wall.getWidth()),
ConvertUnits.ToSimUnits(wall.getHeight()),
0.001f,
new Vector2(ConvertUnits.ToSimUnits(position.X + wall.getWidth() / 2f), ConvertUnits.ToSimUnits(position.Y + wall.getHeight() / 2f))
);
wallBody.Restitution = 0.25f;
}
ballBody.Position = new Vector2(ConvertUnits.ToSimUnits(level.getStart().X), ConvertUnits.ToSimUnits(level.getStart().Y));
ball.setPosition(new System.Windows.Point(ConvertUnits.ToDisplayUnits(ballBody.Position.X), ConvertUnits.ToDisplayUnits(ballBody.Position.Y)));
}
}
开发者ID:serioja90,项目名称:labirynth,代码行数:32,代码来源:Game.xaml.cs
示例3: LoadContent
public override void LoadContent(World world, ContentManager content, Vector2 position, PhysicsScene physicsScene)
{
base.LoadContent(world, content, position, physicsScene);
Vector2 size = this.size * sizeRatio;
CircleShape circle1 = new CircleShape(0.1f, 1f);
CircleShape circle2 = new CircleShape(0.1f, 1f);
CircleShape circle3 = new CircleShape(0.1f, 1f);
CircleShape circle4 = new CircleShape(0.1f, 1f);
circle1.Position = new Vector2(-((size.X / 2) + 0.2f), (size.Y + 0.1f) / 2);
circle2.Position = new Vector2((size.X / 2) + 0.2f, (size.Y + 0.1f) / 2);
circle3.Position = new Vector2(-((size.X / 2) + 0.2f), (size.Y - 0.3f) / 2);
circle4.Position = new Vector2((size.X / 2) + 0.2f, (size.Y - 0.3f) / 2);
sensors[0] = body.CreateFixture(circle1, (int)-(100 + id));
sensors[1] = body.CreateFixture(circle2, (int)-(200 + id));
sensors[2] = body.CreateFixture(circle3, (int)-(300 + id));
sensors[3] = body.CreateFixture(circle4, (int)-(400 + id));
sensors[0].IsSensor = true;
sensors[1].IsSensor = true;
sensors[2].IsSensor = true;
sensors[3].IsSensor = true;
}
开发者ID:Woktopus,项目名称:Acllacuna,代码行数:26,代码来源:Enemy.cs
示例4: CreateBullets
private static void CreateBullets(Body ship)
{
Func<Vector2, Body> createBullet = pos =>
{
var body = new Body(world);
body.BodyType = BodyType.Dynamic;
body.IsBullet = true;
var shape = new FarseerCircleShape(0.15f / 4, 1);
body.CreateFixture(shape);
body.Position = ship.Position + ship.GetWorldVector(pos);
body.Rotation = ship.Rotation;
body.ApplyForce(body.GetWorldVector(new Vector2(0.0f, -15f)));
body.OnCollision += (a, b, contact) =>
{
world.RemoveBody(body);
return false;
};
return body;
};
createBullet(new Vector2(-0.575f, -0.20f));
createBullet(new Vector2(0.575f, -0.20f));
}
开发者ID:Rohansi,项目名称:Programe,代码行数:27,代码来源:Program.cs
示例5: OneSidedPlatformTest
private OneSidedPlatformTest()
{
//Ground
BodyFactory.CreateEdge(World, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
// Platform
{
Body body = BodyFactory.CreateBody(World);
body.Position = new Vector2(0.0f, 10.0f);
PolygonShape shape = new PolygonShape(1);
shape.SetAsBox(3.0f, 0.5f);
_platform = body.CreateFixture(shape);
_top = 10.0f + 0.5f;
}
// Actor
{
Body body = BodyFactory.CreateBody(World);
body.BodyType = BodyType.Dynamic;
body.Position = new Vector2(0.0f, 12.0f);
_radius = 0.5f;
CircleShape shape = new CircleShape(_radius, 20);
_character = body.CreateFixture(shape);
body.LinearVelocity = new Vector2(0.0f, -50.0f);
}
}
开发者ID:danzel,项目名称:FarseerPhysics,代码行数:30,代码来源:OneSidedPlatformTest.cs
示例6: SensorTest
private SensorTest()
{
{
Body ground = BodyFactory.CreateBody(World);
{
EdgeShape shape = new EdgeShape(new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
ground.CreateFixture(shape);
}
{
CircleShape shape = new CircleShape(5.0f, 1);
shape.Position = new Vector2(0.0f, 10.0f);
_sensor = ground.CreateFixture(shape);
_sensor.IsSensor = true;
}
}
{
CircleShape shape = new CircleShape(1.0f, 1);
for (int i = 0; i < Count; ++i)
{
_touching[i] = false;
_bodies[i] = BodyFactory.CreateBody(World);
_bodies[i].BodyType = BodyType.Dynamic;
_bodies[i].Position = new Vector2(-10.0f + 3.0f * i, 20.0f);
_bodies[i].UserData = i;
_bodies[i].CreateFixture(shape);
}
}
}
开发者ID:hilts-vaughan,项目名称:Farseer-Physics,代码行数:34,代码来源:SensorTest.cs
示例7: CircleBenchmarkTest
private CircleBenchmarkTest()
{
Body ground = BodyFactory.CreateBody(World);
// Floor
EdgeShape ashape = new EdgeShape(new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
ground.CreateFixture(ashape);
// Left wall
ashape = new EdgeShape(new Vector2(-40.0f, 0.0f), new Vector2(-40.0f, 45.0f));
ground.CreateFixture(ashape);
// Right wall
ashape = new EdgeShape(new Vector2(40.0f, 0.0f), new Vector2(40.0f, 45.0f));
ground.CreateFixture(ashape);
// Roof
ashape = new EdgeShape(new Vector2(-40.0f, 45.0f), new Vector2(40.0f, 45.0f));
ground.CreateFixture(ashape);
CircleShape shape = new CircleShape(1.0f, 1);
for (int i = 0; i < XCount; i++)
{
for (int j = 0; j < YCount; ++j)
{
Body body = BodyFactory.CreateBody(World);
body.BodyType = BodyType.Dynamic;
body.Position = new Vector2(-38f + 2.1f * i, 2.0f + 2.0f * j);
body.CreateFixture(shape);
}
}
}
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:34,代码来源:CircleBenchmarkTest.cs
示例8: ComputerControlledTank
public ComputerControlledTank(
ISoundManager soundManager,
World world,
Collection<IDoodad> doodads,
Team team,
Vector2 position,
float rotation,
Random random,
DoodadFactory doodadFactory,
IEnumerable<Waypoint> waypoints)
: base(soundManager, world, doodads, team, position, rotation, doodadFactory)
{
this.world = world;
this.random = random;
this.states = new Dictionary<Type, ITankState>();
this.states.Add(typeof(MovingState), new MovingState(world, this.Body, this, waypoints, random));
this.states.Add(typeof(AttackingState), new AttackingState(world, this.Body, this));
this.states.Add(typeof(TurningState), new TurningState(this.Body, this));
this.currentState = this.states[typeof(MovingState)];
this.currentState.StateChanged += this.OnStateChanged;
this.currentState.NavigateTo();
this.sensor = BodyFactory.CreateBody(world, this.Position);
var shape = new CircleShape(6, 0);
Fixture sensorFixture = this.sensor.CreateFixture(shape);
sensorFixture.Friction = 1f;
sensorFixture.IsSensor = true;
sensorFixture.CollisionCategories = PhysicsConstants.SensorCategory;
sensorFixture.CollidesWith = PhysicsConstants.PlayerCategory | PhysicsConstants.ObstacleCategory |
PhysicsConstants.MissileCategory;
}
开发者ID:aschearer,项目名称:BaconGameJam2012,代码行数:32,代码来源:ComputerControlledTank.cs
示例9: LoadCollider
private bool LoadCollider()
{
/* find a mesh component to create box from */
var meshComponent = this.GameObject.Components.FirstOrDefault(c => c is MeshComponent) as MeshComponent;
if (meshComponent == null)
{
return false;
}
if (!meshComponent.IsLoaded) meshComponent.Load();
Vector2 vMin = new Vector2(float.MaxValue, float.MaxValue);
Vector2 vMax = new Vector2(float.MinValue, float.MinValue);
foreach (var vertex in meshComponent.Vertices)
{
if (vertex.X * GameObject.Scale.X < vMin.X) vMin.X = vertex.X * GameObject.Scale.X;
if (vertex.X * GameObject.Scale.X > vMax.X) vMax.X = vertex.X * GameObject.Scale.X;
if (vertex.Y * GameObject.Scale.Y < vMin.Y) vMin.Y = vertex.Y * GameObject.Scale.Y;
if (vertex.Y * GameObject.Scale.Y > vMax.Y) vMax.Y = vertex.Y * GameObject.Scale.Y;
}
Radius = (vMax.X - vMin.X) / 2.0f;
CollisionShape = new CircleShape(Radius, 15.0f);
return true;
}
开发者ID:BaldMan82,项目名称:iGL,代码行数:29,代码来源:CircleColliderFarseerComponent.cs
示例10: LoadCollider
private bool LoadCollider()
{
/* find a mesh component to create box from */
var meshComponent = this.GameObject.Components.FirstOrDefault(c => c is MeshComponent) as MeshComponent;
if (meshComponent == null)
{
return false;
}
if (!meshComponent.IsLoaded) meshComponent.Load();
float maxExtend = float.MinValue;
foreach (var vertex in meshComponent.Vertices)
{
if (vertex.X * GameObject.Scale.X > maxExtend) maxExtend = vertex.X * GameObject.Scale.X;
if (vertex.Y * GameObject.Scale.Y > maxExtend) maxExtend = vertex.Y * GameObject.Scale.Y;
if (vertex.Z * GameObject.Scale.Z > maxExtend) maxExtend = vertex.Z * GameObject.Scale.Z;
}
float max = maxExtend;
CollisionShape = new CircleShape(maxExtend, 1.0f);
return true;
}
开发者ID:BaldMan82,项目名称:iGL,代码行数:26,代码来源:SphereColliderFarseerComponent.cs
示例11: Ship
public Ship(World world, SpawnData spawn, int id)
{
Ball = null;
Id = id;
IsThrusting = false;
IsReversing = false;
IsBoosting = false;
IsLeftTurning = false;
IsRightTurning = false;
IsShooting = false;
IsBlocked = false;
IsBlockedFrame = false;
Color = spawn.Color;
var body = new Body(world);
body.Rotation = FMath.Atan2(-spawn.Position.Y, -spawn.Position.X);
body.Position = spawn.Position;
var shape = new CircleShape(radius, 1f);
body.BodyType = BodyType.Dynamic;
body.FixedRotation = true;
Fixture = body.CreateFixture(shape);
Fixture.Restitution = restitution;
var bodyGravity = new Body(world);
bodyGravity.Position = spawn.Position;
var shapeGravity = new CircleShape(radiusGravity, 1f);
bodyGravity.FixedRotation = true;
FixtureGravity = bodyGravity.CreateFixture(shapeGravity);
FixtureGravity.IsSensor = true;
}
开发者ID:det,项目名称:Rimbalzo,代码行数:31,代码来源:Ship.cs
示例12: Missile
public Missile(
ISoundManager soundManager,
World world,
Collection<IDoodad> doodads,
int numberOfBounces,
Team team,
Vector2 position,
float rotation,
DoodadFactory doodadFactory)
{
this.soundManager = soundManager;
this.doodadFactory = doodadFactory;
this.world = world;
this.doodads = doodads;
this.numberOfBounces = numberOfBounces;
this.body = BodyFactory.CreateBody(world, position, this);
this.body.BodyType = BodyType.Dynamic;
this.body.FixedRotation = true;
CircleShape shape = new CircleShape(5 / Constants.PixelsPerMeter, 0.1f);
Fixture fixture = body.CreateFixture(shape);
fixture.Restitution = 1;
fixture.Friction = 0;
fixture.CollisionCategories = PhysicsConstants.MissileCategory;
fixture.CollidesWith = PhysicsConstants.EnemyCategory | PhysicsConstants.PlayerCategory |
PhysicsConstants.ObstacleCategory | PhysicsConstants.MissileCategory |
PhysicsConstants.SensorCategory;
obstacleCollisionCtr = 0;
Vector2 force = new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation)) * 3;
this.body.ApplyForce(force);
}
开发者ID:aschearer,项目名称:BaconGameJam2012,代码行数:32,代码来源:Missile.cs
示例13: LoadContent
public void LoadContent(ContentManager content, World world, Vector2 position, Vector2 size)
{
body = BodyFactory.CreateRectangle(world, size.X, size.Y, 1f);
body.FixedRotation = true;
body.FixtureList[0].UserData = 9000;
body.Position = ConvertUnits.ToSimUnits(position);
body.BodyType = BodyType.Dynamic;
CircleShape circle1 = new CircleShape(size.X / 4, 1f);
CircleShape circle2 = new CircleShape(size.Y / 6, 1f);
CircleShape circle3 = new CircleShape(size.Y / 6, 1f);
circle1.Position = new Vector2(0, -size.Y / 3);
circle2.Position = new Vector2(-1.5f * size.X / 5, -size.Y / 10);
circle3.Position = new Vector2(-0.4f * size.X / 5, -size.Y / 10);
head = body.CreateFixture(circle1);
hands[0] = body.CreateFixture(circle2);
hands[1] = body.CreateFixture(circle3);
head.UserData = (int)10000;
hands[0].UserData = (int)11000;
hands[1].UserData = (int)11000;
image.LoadContent(content, "Graphics/tezka", Color.White, position);
image.ScaleToMeters(size);
image.position = ConvertUnits.ToDisplayUnits(body.Position);
}
开发者ID:Woktopus,项目名称:Acllacuna,代码行数:34,代码来源:Boss.cs
示例14: AttachCircle
public static Fixture AttachCircle(float radius, float density, Body body, object userData)
{
if (radius <= 0)
throw new ArgumentOutOfRangeException("radius", "Radius must be more than 0 meters");
CircleShape circleShape = new CircleShape(radius, density);
return body.CreateFixture(circleShape, userData);
}
开发者ID:HaKDMoDz,项目名称:Zazumo,代码行数:8,代码来源:FixtureFactory.cs
示例15: AttachCircle
public static Fixture AttachCircle( float radius, float density, Body body, Vector2 offset, object userData = null )
{
if( radius <= 0 )
throw new ArgumentOutOfRangeException( nameof( radius ), "Radius must be more than 0 meters" );
var circleShape = new CircleShape( radius, density );
circleShape.position = offset;
return body.createFixture( circleShape, userData );
}
开发者ID:prime31,项目名称:Nez,代码行数:9,代码来源:FixtureFactory.cs
示例16: Clone
public override Shape Clone()
{
CircleShape shape = new CircleShape();
shape.ShapeType = ShapeType;
shape.Radius = Radius;
shape.Position = Position;
return shape;
}
开发者ID:HaKDMoDz,项目名称:Lunar-Development-Kit,代码行数:9,代码来源:CircleShape.cs
示例17: ControllerTest
private ControllerTest()
{
//Ground
BodyFactory.CreateEdge(World, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
//Create the gravity controller
GravityController gravity = new GravityController(20);
gravity.DisabledOnGroup = 3;
gravity.EnabledOnGroup = 2;
gravity.DisabledOnCategories = Category.Cat2;
gravity.EnabledOnCategories = Category.Cat3;
World.AddController(gravity);
Vector2 startPosition = new Vector2(-10, 2);
Vector2 offset = new Vector2(2);
//Create the planet
Body planet = BodyFactory.CreateBody(World);
planet.Position = new Vector2(0, 20);
CircleShape planetShape = new CircleShape(2, 1);
planet.CreateFixture(planetShape);
//Add the planet as the one that has gravity
gravity.AddBody(planet);
//Create 10 smaller circles
for (int i = 0; i < 10; i++)
{
Body circle = BodyFactory.CreateBody(World);
circle.BodyType = BodyType.Dynamic;
circle.Position = startPosition + offset * i;
circle.SleepingAllowed = false;
CircleShape circleShape = new CircleShape(1, 0.1f);
Fixture fix = circle.CreateFixture(circleShape);
fix.CollisionCategories = Category.Cat3;
fix.CollisionGroup = 2;
if (i == 4)
{
circle.ControllerFilter.IgnoreController(ControllerType.GravityController);
}
if (i == 5)
{
fix.CollisionCategories = Category.Cat2;
}
if (i == 6)
{
fix.CollisionGroup = 3;
}
}
}
开发者ID:boris2,项目名称:mmogameproject2,代码行数:56,代码来源:ControllerTest.cs
示例18: Clone
public override Shape Clone()
{
CircleShape shape = new CircleShape();
shape._radius = Radius;
shape._density = _density;
shape._position = _position;
shape.ShapeType = ShapeType;
shape.MassData = MassData;
return shape;
}
开发者ID:Werkheisera2,项目名称:RaginRovers,代码行数:10,代码来源:CircleShape.cs
示例19: CreateFixtureFromRadius
public virtual void CreateFixtureFromRadius(float radius)
{
float hx = (Sprite.Size.X / 2f);
float hy = (Sprite.Size.Y / 2f);
Sprite.Origin = new Vector2(hx, hy);
CircleShape c = new CircleShape(radius, 1);
c.Position += new Vector2(radius, radius);
CreateFixture(c);
}
开发者ID:lytedev,项目名称:wrack,代码行数:11,代码来源:Entity.cs
示例20: RevoluteTest
private RevoluteTest()
{
//Ground
var ground = BodyFactory.CreateEdge(World, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
{
//The big fixed wheel
CircleShape shape = new CircleShape(5.0f, 5);
Body body = BodyFactory.CreateBody(World);
body.Position = new Vector2(-10.0f, 15.0f);
body.BodyType = BodyType.Dynamic;
body.CreateFixture(shape);
_fixedJoint = new FixedRevoluteJoint(body, Vector2.Zero, body.Position);
_fixedJoint.MotorSpeed = 0.25f * Settings.Pi;
_fixedJoint.MaxMotorTorque = 5000.0f;
_fixedJoint.MotorEnabled = true;
World.AddJoint(_fixedJoint);
// The small gear attached to the big one
Body body1 = BodyFactory.CreateGear(World, 1.5f, 10, 0.1f, 1, 1);
body1.Position = new Vector2(-10.0f, 12.0f);
body1.BodyType = BodyType.Dynamic;
_joint = new RevoluteJoint(body, body1, body.GetLocalPoint(body1.Position),
Vector2.Zero);
_joint.MotorSpeed = 1.0f * Settings.Pi;
_joint.MaxMotorTorque = 5000.0f;
_joint.MotorEnabled = true;
_joint.CollideConnected = false;
World.AddJoint(_joint);
CircleShape circle_shape = new CircleShape(3.0f, 5);
var circleBody = BodyFactory.CreateBody(World);
circleBody.Position = new Vector2(5.0f, 30.0f);
circleBody.BodyType = BodyType.Dynamic;
circleBody.CreateFixture(circle_shape);
PolygonShape polygonShape = new PolygonShape(2.0f);
polygonShape.SetAsBox(10.0f, 0.2f, new Vector2(-10.0f, 0.0f), 0.0f);
var polygon_body = BodyFactory.CreateBody(World);
polygon_body.Position = new Vector2(20.0f, 10.0f);
polygon_body.BodyType = BodyType.Dynamic;
polygon_body.IsBullet = true;
polygon_body.CreateFixture(polygonShape);
RevoluteJoint rjd = new RevoluteJoint(ground, polygon_body, new Vector2(20.0f, 10.0f));
rjd.LowerLimit = -0.25f * Settings.Pi;
rjd.UpperLimit = 0.0f;
rjd.LimitEnabled = true;
World.AddJoint(rjd);
}
}
开发者ID:danzel,项目名称:FarseerPhysics,代码行数:54,代码来源:RevoluteTest.cs
注:本文中的FarseerPhysics.Collision.Shapes.CircleShape类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论