本文整理汇总了C#中FarseerPhysics.Dynamics.Contacts.Contact.IsTouching方法的典型用法代码示例。如果您正苦于以下问题:C# Contact.IsTouching方法的具体用法?C# Contact.IsTouching怎么用?C# Contact.IsTouching使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FarseerPhysics.Dynamics.Contacts.Contact
的用法示例。
在下文中一共展示了Contact.IsTouching方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnCollisionEvent
bool OnCollisionEvent(Fixture A, Fixture B, Contact contact)
{
/*if (contact.IsTouching() && A.Body.UserTag == "Player") {
A.Body.ApplyLinearImpulse(new FVector2(0, jumpFactor));
////Debug.Log("A: " + A.Body.LinearVelocity);
/* Play jumping sound. *
Player attachedPlayer = GameObject.FindWithTag("Player").GetComponent<Player>();
attachedPlayer.sfxPlayer.clip = attachedPlayer.jumpSound;
attachedPlayer.sfxPlayer.loop = false;
/* Give some variation to the jump pitch. *
if (!attachedPlayer.NearVortex()) {
attachedPlayer.sfxPlayer.pitch = 1.0f + 0.02f*UnityEngine.Random.Range(-11, 6);
}
attachedPlayer.sfxPlayer.Play();
}
else*/ if (contact.IsTouching() && B.Body.UserTag == "Player") {
B.Body.ApplyLinearImpulse(new FVector2(0, jumpFactor));
////Debug.Log("B: " + B.Body.LinearVelocity);
/* Play jumping sound. */
Player attachedPlayer = GameObject.FindWithTag("Player").GetComponent<Player>();
attachedPlayer.sfxPlayer.clip = attachedPlayer.jumpSound;
attachedPlayer.sfxPlayer.loop = false;
/* Give some variation to the jump pitch. */
if (!attachedPlayer.NearVortex()) {
attachedPlayer.sfxPlayer.pitch = 1.0f + 0.02f*UnityEngine.Random.Range(-11, 6);
}
attachedPlayer.sfxPlayer.Play();
}
return true;
}
示例2: OnCollision
bool OnCollision(Fixture fixtureA, Fixture fixtureB, Contact contact)
{
Vector2 movementBefore = body.LinearVelocity;
body.LinearVelocity = new Vector2(body.LinearVelocity.X, 0);
Block block=null;
foreach (Entity e in game.entities)
{
if (e is Block)
{
Block b = (Block)e;
if(b.fixture.Equals(fixtureB))
{
block = b;
}
}
}
if (contact.IsTouching())
{
if (isMagnet(fixtureB))
return true;
Manifold colis = new Manifold();
contact.GetManifold(out colis);
Vector2 pColis = colis.LocalNormal;
if (pColis.X == 0 && pColis.Y == 1)
{
onGround = true;
modes = Modes.GROUND;
return true;
}
if (pColis.X != 0 && pColis.Y == 0)
{
collisionRec = getBlockFromFixture(fixtureB);
if (fixtureB.Body.Rotation % 45 != 0)
{
onGround = true;
modes = Modes.GROUND;
return false;
}
if (onGround)
{
modes = Modes.WALL;
return false;
}
float direction = inputState.GetJoyDirection();
float x = (float)Math.Sin(direction);
if (pColis.X > 0)
isWallOnRight = true;
else
isWallOnRight = false;
float xMomentum = 0;
if (movementBefore.Y > 0)
{
xMomentum = Math.Abs(body.LinearVelocity.X * 0.3f);
}
else if (movementBefore.Y < 0)
{
xMomentum = -Math.Abs(body.LinearVelocity.X * 0.8f);
}
XboxInput xbi = (XboxInput)inputState;
if (xbi.getYDirection() < 0 || Keyboard.GetState().IsKeyDown(Keys.Up) || Keyboard.GetState().IsKeyDown(Keys.W))
xMomentum += xbi.getYDirection() * 4f;
else
xMomentum = 0;
body.LinearVelocity = new Vector2(0, body.LinearVelocity.Y + xMomentum);
//body.IgnoreGravity = true;
onGround = true;
onGround = true;
modes = Modes.WALL;
ignoreInput = 2;
return false;
}
}
return true;
}
示例3: Destroy
internal void Destroy(Contact contact)
{
Fixture fixtureA = contact.FixtureA;
Fixture fixtureB = contact.FixtureB;
Body bodyA = fixtureA.Body;
Body bodyB = fixtureB.Body;
if (EndContact != null && contact.IsTouching())
{
EndContact(contact);
}
// Remove from the world.
if (contact.Prev != null)
{
contact.Prev.Next = contact.Next;
}
if (contact.Next != null)
{
contact.Next.Prev = contact.Prev;
}
if (contact == ContactList)
{
ContactList = contact.Next;
}
// Remove from body 1
if (contact.NodeA.Prev != null)
{
contact.NodeA.Prev.Next = contact.NodeA.Next;
}
if (contact.NodeA.Next != null)
{
contact.NodeA.Next.Prev = contact.NodeA.Prev;
}
if (contact.NodeA == bodyA.ContactList)
{
bodyA.ContactList = contact.NodeA.Next;
}
// Remove from body 2
if (contact.NodeB.Prev != null)
{
contact.NodeB.Prev.Next = contact.NodeB.Next;
}
if (contact.NodeB.Next != null)
{
contact.NodeB.Next.Prev = contact.NodeB.Prev;
}
if (contact.NodeB == bodyB.ContactList)
{
bodyB.ContactList = contact.NodeB.Next;
}
contact.Destroy();
--ContactCount;
}
示例4: OnCollision
bool OnCollision(Fixture fixtureA, Fixture fixtureB, Contact contact)
{
if (contact.IsTouching())
{
LinkedList<PlayableCharacter> players = game.getEntitiesOfType<PlayableCharacter>();
if (players.Count == 0)
return false;
PlayableCharacter player = players.First();
if (fixtureB == player.fixture)
{
Vector2 magneticForce;
if(!isFan)
magneticForce=magnetPulse * game.magValue;
else
magneticForce=magnetPulse;
if (magneticForce.X != 0)
{
player.body.LinearVelocity = new Vector2(magneticForce.X, player.body.LinearVelocity.Y);
}
else
{
player.body.LinearVelocity = new Vector2(player.body.LinearVelocity.X, magneticForce.Y);
}
if (!isInMagnet)
{
/*
if(magnetPulse.X!=0)
player.body.LinearVelocity = new Vector2(0, body.LinearVelocity.Y);
else
player.body.LinearVelocity = new Vector2(body.LinearVelocity.X, 0);
isInMagnet = true;
* */
}
//player.body.IgnoreGravity = true;
return !isMagnet;
}
}
return true;
}
示例5: HandleCollision
/// <summary>
/// Called when a collision with the platform occurs.
/// </summary>
/// <param name="fixtureA">The first fixture that has collided.</param>
/// <param name="fixtureB">The second fixture that has collided.</param>
/// <param name="contact">The Contact object that contains information about the collision.</param>
/// <returns>Whether the collision should still happen.</returns>
private bool HandleCollision(Fixture fixtureA, Fixture fixtureB, Contact contact)
{
// Check if one of the Fixtures belongs to a ball.
bool causedByBall = (string)fixtureA.Body.UserData == "ball" || (string)fixtureB.Body.UserData == "ball";
if (contact.IsTouching() && causedByBall) {
bool shouldCollisionOccur = false;
// A ball should only bounce off a breakable platform once.
if (_breakable && _visible) {
Break();
// Don't collide with the ball anymore.
_body.CollidesWith = Category.All & ~Category.Cat1;
shouldCollisionOccur = true;
// Don't bounce off broken platforms.
} else if (_breakable && !_visible) {
shouldCollisionOccur = false;
// Always bounce off regular platforms.
} else {
shouldCollisionOccur = true;
}
// Call the methods listening for collision events.
if (OnPlatformCollision != null && shouldCollisionOccur) {
OnPlatformCollision(_breakable);
}
// Tell the physics engine the intended result.
return shouldCollisionOccur;
} else {
// Otherwise, if it's not caused by a ball, then ignore the collision.
return false;
}
}
示例6: OnCollision
bool OnCollision(Fixture fixtureA, Fixture fixtureB, Contact contact)
{
if (contact.IsTouching())
{
LinkedList<PlayableCharacter> players = game.getEntitiesOfType<PlayableCharacter>();
PlayableCharacter player = players.First();
if (fixtureB == player.fixture)
{
if (game.gMode != 2)
{
game.sounds["Rage//Wave//explosion"].Play();
game.PlayerDies();
}
}
else
{
//Destroy block
//SetUpPhysics(Constants.player1SpawnLocation+origPos);
//body.SetTransform(ConvertUnits.ToSimUnits(pos), 0);
//Vector2 possi=ConvertUnits.ToSimUnits(pos);
//body.SetTransformIgnoreContacts(ref possi, 0);
//body.Awake = true;
//body.ApplyForce(new Vector2(1, 0));
//body.LinearVelocity=new Vector2(1, 0);
telePort = true;
}
}
return true;
}
示例7: OnCollision
bool OnCollision(Fixture fixtureA, Fixture fixtureB, Contact contact)
{
if (IsVisible)
{
if (contact.IsTouching())
{
LinkedList<PlayableCharacter> players = game.getEntitiesOfType<PlayableCharacter>();
if (players.Count == 0)
return false;
PlayableCharacter player = players.First();
if (fixtureB == player.fixture)
{
if (game.gMode != 2)
{
game.sounds["Rage//Wave//explosion"].Play();
game.PlayerDies();
}
}
else
{
explosion();
}
}
}
return true;
}
示例8: OnCollision
bool OnCollision(Fixture fixtureA, Fixture fixtureB, Contact contact)
{
if (contact.IsTouching())
{
}
return true;
}
示例9: CollisionEnterEventHandler
/// <summary>
/// コリジョン発生イベント ハンドラー
/// </summary>
/// <param name="fixtureA">フィクスチャーA (自分)</param>
/// <param name="fixtureB">フィクスチャーB (衝突相手)</param>
/// <param name="contact">コンタクト情報</param>
/// <returns></returns>
private bool CollisionEnterEventHandler(Fixture fixtureA, Fixture fixtureB, Contact contact)
{
var phy = Physics2D.GetInstance ();
var a = fixtureA.UserData as PhysicsBody;
var b = fixtureB.UserData as PhysicsBody;
if (a.body == null || b.body == null) {
// メモ:
// Bodyを Dispose してもただちに無効化されるわけではなく、
// 同ステップではイベント ハンドラーも含めてまだ有効。
// ここでチェックしてお帰りいただく必要がある。
return false;
}
if (((a.CollisionMask & b.GroupID) == 0) || ((b.CollisionMask & a.GroupID) == 0)) {
return false;
}
XnaVector2 normal; // A --> B
FixedArray2<XnaVector2> points;
contact.GetWorldManifold (out normal, out points);
var count = contact.Manifold.PointCount;
if (count == 0 && contact.IsTouching ()) {
// センサー(トリガー)モードの時、
// count=0 かつ Manifold は未定義
var cp = new ContactPoint (b, new Vector3 (0, 0, 0), new Vector3 (0, 0, 0));
foreach (var comp in Node.Components) {
comp.OnCollisionEnter (cp);
}
}
else if (count == 1) {
var p = new Vector3 (points[0].X * phy.PPM, points[0].Y * phy.PPM, 0);
var n = new Vector3 (normal.X, normal.Y, 0);
var cp = new ContactPoint (b, p, n);
foreach (var comp in Node.Components) {
comp.OnCollisionEnter (cp);
}
}
else if (count == 2) {
var p = new Vector3 ((points[0].X + points[1].X) / 2.0f * phy.PPM, (points[0].Y + points[1].Y) / 2.0f * phy.PPM, 0);
var n = new Vector3 (normal.X, normal.Y, 0);
var cp = new ContactPoint (b, p, n);
foreach (var comp in Node.Components) {
comp.OnCollisionEnter (cp);
}
}
return true;
}
示例10: OnCollision
bool OnCollision(Fixture fixtureA, Fixture fixtureB, Contact contact)
{
if (contact.IsTouching())
{
LinkedList<PlayableCharacter> players = game.getEntitiesOfType<PlayableCharacter>();
if (players.Count == 0)
return false;
PlayableCharacter player = players.First();
if (fixtureB == player.fixture)
{
if (!game.testLevel)
{
this.IsVisible = false;
game.numDeath = 0;
game.nextLevel(nextLevel++);
}
}
else
{
if(game.deathBlockGoalCollision)
game.PlayerDies();
}
}
return true;
}
示例11: HandleWallCollision
/// <summary>
/// Called when a collision with a wall occurs.
/// </summary>
/// <param name="fixtureA">The first fixture that has collided.</param>
/// <param name="fixtureB">The second fixture that has collided.</param>
/// <param name="contact">The Contact object that contains information about the collision.</param>
/// <returns>Whether the collision should still happen.</returns>
private bool HandleWallCollision(Fixture fixtureA, Fixture fixtureB, Contact contact)
{
// Check if one of the Fixtures belongs to a ball.
bool causedByBall = (string)fixtureA.Body.UserData == "ball" || (string)fixtureB.Body.UserData == "ball";
// A subtle fact about the OnCollision event is that it is only called
// when the associated Contact object is changed from not-touching to touching.
// While two objects are still touching each other, OnCollision won't be called again.
if (contact.IsTouching() && causedByBall) {
// Call any methods that are listening to this event.
if (OnWallCollision != null) {
OnWallCollision();
}
// The ball's trajectory should definitely be affected by the wall, so tell
// the physics engine that by returning true.
return true;
}
// If it's not a ball, then we don't really need to worry about it. Hopefully.
return false;
}
示例12: PreSolve
public void PreSolve(Contact contact, ref Manifold manifold)
{
EventSystem eventSystem = (EventSystem)_systemManager.getSystem(SystemType.Event);
Fixture fixtureA = contact.FixtureA;
Fixture fixtureB = contact.FixtureB;
int playerId = PlayerSystem.PLAYER_ID;
int entityA = (int)fixtureA.Body.UserData;
int entityB = (int)fixtureB.Body.UserData;
string levelUid = LevelSystem.currentLevelUid;
// Check for custom collision filters
bool fixtureAIgnoresEntityB = fixtureA.IsIgnoredEntity(entityB);
bool fixtureBIgnoresEntityA = fixtureB.IsIgnoredEntity(entityA);
if (fixtureAIgnoresEntityB)
contact.Enabled = false;
else if (fixtureBIgnoresEntityA)
contact.Enabled = false;
// Check for item pickup
if (contact.IsTouching() && (entityA == playerId || entityB == playerId))
{
int itemEntityId = entityA == playerId ? entityB : entityA;
Fixture fixture = entityA == playerId ? fixtureB : fixtureA;
ItemComponent itemComponent = _entityManager.getComponent(levelUid, itemEntityId, ComponentType.Item) as ItemComponent;
if (itemComponent != null)
{
contact.Enabled = false;
if (itemComponent.state.inWorld)
{
InventoryComponent playerInventory = _entityManager.getComponent(levelUid, playerId, ComponentType.Inventory) as InventoryComponent;
EquipmentSystem equipmentSystem = _systemManager.getSystem(SystemType.Equipment) as EquipmentSystem;
equipmentSystem.addInventoryItem(playerInventory, itemComponent);
itemComponent.state.inWorld = false;
_bodiesToRemove.Add(fixture.Body);
_entityManager.killEntity(levelUid, itemEntityId);
eventSystem.postEvent(new GameEvent(GameEventType.OnItemPickedUp, itemEntityId));
}
}
}
}
示例13: PostSolve
private void PostSolve(Contact contact, ContactConstraint contactConstraint)
{
if (contact.IsTouching())
{
float maxImpulse = 0.0f;
for (int i = 0; i < contactConstraint.Manifold.PointCount; ++i)
maxImpulse = Math.Max(maxImpulse, contactConstraint.Manifold.Points[i].NormalImpulse);
if (maxImpulse >= 12)
{
IGameObject aGameObj = contactConstraint.BodyA.UserData as IGameObject,
bGameObj = contactConstraint.BodyB.UserData as IGameObject;
if (aGameObj != null)
{
aGameObj.Health -= maxImpulse;
if (aGameObj.Health <= 0)
{
RemoveObject(aGameObj);
}
}
if (bGameObj != null)
{
bGameObj.Health -= maxImpulse;
if (bGameObj.Health <= 0)
{
RemoveObject(bGameObj);
}
}
}
}
}
示例14: DamageCollision
bool DamageCollision(Fixture fixtureA, Fixture fixtureB, Contact contact)
{
Vector2 colNormal = contact.Manifold.LocalNormal;
Vector2 aMomentum = fixtureA.Body.LinearVelocity;
Vector2 bMomentum = fixtureB.Body.LinearVelocity * fixtureB.Body.Mass;
float damage = Math.Abs(Vector2.Dot(aMomentum, colNormal) - Vector2.Dot(bMomentum, colNormal));
damage = (damage < 15f ? 0 : damage); // Min damage = 15
health[fixtureA.Body] -= damage / 200f; // Subject to change
return contact.IsTouching();
}
示例15: ResetCollisionCategory
private bool ResetCollisionCategory(Fixture fixA, Fixture fixB, Contact contact)
{
gun.CollisionCategories = Category.All & ~Category.Cat1;
gun.CollidesWith = Category.All & ~Category.Cat1;
return contact.IsTouching();
}