private void OnBonusCollision(SKPhysicsContact contact) { if (IsBonusContact(contact)) { SKPhysicsBody BonusBody; if (contact.BodyA.CategoryBitMask == (uint)GameObjects.bonus) { BonusBody = contact.BodyA; } else { BonusBody = contact.BodyB; } var BonusObject = BonusesInScene.Find( (obj) => obj.ID.ToString() == BonusBody.Node.Name); if (BonusObject != null) { BonusObject.Get(); DestroyBonus(BonusObject); } } }
private void OnBulletCollision(SKPhysicsContact contact) { if (IsBulletContact(contact)) { SKPhysicsBody bulletBody; SKPhysicsBody otherBody; if (contact.BodyA.CategoryBitMask == (uint)GameObjects.playerBullet || contact.BodyA.CategoryBitMask == (uint)GameObjects.enemyBullet) { bulletBody = contact.BodyA; otherBody = contact.BodyB; } else { bulletBody = contact.BodyB; otherBody = contact.BodyA; } var bulletObject = BulletsInScene.Find( (obj) => obj.ID.ToString() == bulletBody.Node.Name); var otherObject = SceneGameUnits.Find( (obj) => obj.ID.ToString() == otherBody.Node.Name); if (otherObject != null && bulletObject != null) { otherObject.GetDamage(bulletObject.DMG); DestroyBullet(bulletObject); } } }
public override void DidBeginContact(SKPhysicsContact contact) { if (DidBeginContactAction != null) { DidBeginContactAction(contact); } }
public void DidBeginContact(SKPhysicsContact contact) { // Initialize variables for bodies SKPhysicsBody firstBody, secondBody; // Detect bitmask if (contact.BodyA.CategoryBitMask < contact.BodyB.CategoryBitMask) { firstBody = contact.BodyA; secondBody = contact.BodyB; } else { firstBody = contact.BodyB; secondBody = contact.BodyA; } // Handling collision with a hero and a platform if ((firstBody.CategoryBitMask & CollisionCategory.Hero) != 0 && (secondBody.CategoryBitMask & CollisionCategory.Platform) != 0) { GameMap.Hero.ResetJumps(); } // Handling collision with a hero and an enemy if ((firstBody.CategoryBitMask & CollisionCategory.Hero) != 0 && (secondBody.CategoryBitMask & CollisionCategory.Enemy) != 0) { //secondBody.Node.RemoveFromParent(); //map.Enemies.Remove((EnemySprite)secondBody.Node); } // Handling collision with a enemy and a spell if ((firstBody.CategoryBitMask & CollisionCategory.Enemy) != 0 && (secondBody.CategoryBitMask & CollisionCategory.Spell) != 0) { if (((ShotSprite)secondBody.Node).Type == SpellType.Hero) { secondBody.Node.RemoveFromParent(); firstBody.Node.RemoveFromParent(); GameMap.Enemies.Remove((EnemySprite)firstBody.Node); } } // Handling collision with a spell and a platform if ((firstBody.CategoryBitMask & CollisionCategory.Spell) != 0 && (secondBody.CategoryBitMask & CollisionCategory.Platform) != 0) { firstBody.Node.RemoveFromParent(); } if ((firstBody.CategoryBitMask & CollisionCategory.Hero) != 0 && (secondBody.CategoryBitMask & CollisionCategory.Spell) != 0) { if (((ShotSprite)secondBody.Node).Type == SpellType.Enemy) { SetEndGameCondition(); } } }
public void DidBeginContact(SKPhysicsContact contact) { // Handle contacts between two physics bodies. // Contacts are often a double dispatch problem; the effect you want is based // on the type of both bodies in the contact. This sample solves // this in a brute force way, by checking the types of each. A more complicated // example might use methods on objects to perform the type checking. SKPhysicsBody firstBody; SKPhysicsBody secondBody; // The contacts can appear in either order, and so normally you'd need to check // each against the other. In this example, the category types are well ordered, so // the code swaps the two bodies if they are out of order. This allows the code // to only test collisions once. if (contact.BodyA.CategoryBitMask < contact.BodyB.CategoryBitMask) { firstBody = contact.BodyA; secondBody = contact.BodyB; } else { firstBody = contact.BodyB; secondBody = contact.BodyA; } // Missiles attack whatever they hit, then explode. if ((firstBody.CategoryBitMask & Category.Missile) != 0) { AttackTarget(secondBody, firstBody.Node); } // Ships collide and take damage. The collision damage is based on the strength of the collision. if ((firstBody.CategoryBitMask & Category.Ship) != 0) { // The edge exists just to keep all gameplay on one screen, // so ships should not take damage when they hit the edge. if (contact.CollisionImpulse > collisionDamageThreshold && (secondBody.CategoryBitMask & Category.Edge) == 0) { int damage = (int)(contact.CollisionImpulse / collisionDamageThreshold); ((ShipSprite)firstBody.Node).ApplyDamage(damage); if ((secondBody.CategoryBitMask == Category.Ship)) { ((ShipSprite)secondBody.Node).ApplyDamage(damage); } } } // Asteroids that hit planets are destroyed. if ((firstBody.CategoryBitMask & Category.Asteroid) != 0 && (secondBody.CategoryBitMask & Category.Planet) != 0) { firstBody.Node.RemoveFromParent(); } }
public void DidBeginContact(SKPhysicsContact contact) { // Handle contacts between two physics bodies. // Contacts are often a double dispatch problem; the effect you want is based // on the type of both bodies in the contact. This sample solves // this in a brute force way, by checking the types of each. A more complicated // example might use methods on objects to perform the type checking. SKPhysicsBody firstBody; SKPhysicsBody secondBody; // The contacts can appear in either order, and so normally you'd need to check // each against the other. In this example, the category types are well ordered, so // the code swaps the two bodies if they are out of order. This allows the code // to only test collisions once. if (contact.BodyA.CategoryBitMask < contact.BodyB.CategoryBitMask) { firstBody = contact.BodyA; secondBody = contact.BodyB; } else { firstBody = contact.BodyB; secondBody = contact.BodyA; } // Missiles attack whatever they hit, then explode. if ((firstBody.CategoryBitMask & Category.Missile) != 0) AttackTarget (secondBody, firstBody.Node); // Ships collide and take damage. The collision damage is based on the strength of the collision. if ((firstBody.CategoryBitMask & Category.Ship) != 0) { // The edge exists just to keep all gameplay on one screen, // so ships should not take damage when they hit the edge. if (contact.CollisionImpulse > collisionDamageThreshold && (secondBody.CategoryBitMask & Category.Edge) == 0) { int damage = (int) (contact.CollisionImpulse / collisionDamageThreshold); ((ShipSprite)firstBody.Node).ApplyDamage (damage); if ((secondBody.CategoryBitMask == Category.Ship)) ((ShipSprite)secondBody.Node).ApplyDamage (damage); } } // Asteroids that hit planets are destroyed. if ((firstBody.CategoryBitMask & Category.Asteroid) != 0 && (secondBody.CategoryBitMask & Category.Planet) != 0) firstBody.Node.RemoveFromParent (); }
private bool IsBonusContact(SKPhysicsContact contact) { bool isPlayerAndBonusContact = (contact.BodyA.CategoryBitMask == (uint)GameObjects.player && contact.BodyB.CategoryBitMask == (uint)GameObjects.bonus) || (contact.BodyB.CategoryBitMask == (uint)GameObjects.player && contact.BodyA.CategoryBitMask == (uint)GameObjects.bonus); bool isPlayerBulletAndBonus = (contact.BodyA.CategoryBitMask == (uint)GameObjects.playerBullet && contact.BodyB.CategoryBitMask == (uint)GameObjects.bonus) || (contact.BodyB.CategoryBitMask == (uint)GameObjects.playerBullet && contact.BodyA.CategoryBitMask == (uint)GameObjects.bonus); return(contact.BodyA.CategoryBitMask != contact.BodyB.CategoryBitMask && isPlayerBulletAndBonus || isPlayerAndBonusContact); }
private bool IsBulletContact(SKPhysicsContact contact) { bool isPlayerAndEnemyBullet = (contact.BodyA.CategoryBitMask == (uint)GameObjects.player && contact.BodyB.CategoryBitMask == (uint)GameObjects.enemyBullet) || (contact.BodyB.CategoryBitMask == (uint)GameObjects.player && contact.BodyA.CategoryBitMask == (uint)GameObjects.enemyBullet); bool isEnemyAndPlayerBullet = (contact.BodyA.CategoryBitMask == (uint)GameObjects.enemy && contact.BodyB.CategoryBitMask == (uint)GameObjects.playerBullet) || (contact.BodyB.CategoryBitMask == (uint)GameObjects.enemy && contact.BodyA.CategoryBitMask == (uint)GameObjects.playerBullet); return(contact.BodyA.CategoryBitMask != contact.BodyB.CategoryBitMask && isEnemyAndPlayerBullet || isPlayerAndEnemyBullet); }
void DidBeginContact(SKPhysicsContact contact) { SKPhysicsBody firstBody; SKPhysicsBody secondBody; if (contact.BodyA.CategoryBitMask < contact.BodyB.CategoryBitMask) { firstBody = contact.BodyA; secondBody = contact.BodyB; } else { firstBody = contact.BodyB; secondBody = contact.BodyA; } if ((firstBody.CategoryBitMask & Category.Missile) != 0) { AttackTarget(secondBody, firstBody.Node); } if ((firstBody.CategoryBitMask & Category.Ship) != 0) { if (contact.CollisionImpulse > collisionDamageThreshold && (secondBody.CategoryBitMask & Category.Edge) == 0) { int damage = (int)(contact.CollisionImpulse / collisionDamageThreshold); (firstBody.Node as ShipSprite).ApplyDamage(damage); if ((secondBody.CategoryBitMask == Category.Ship)) { (secondBody.Node as ShipSprite).ApplyDamage(damage); } } } if ((firstBody.CategoryBitMask & Category.Asteroid) != 0 && (secondBody.CategoryBitMask & Category.Planet) != 0) { firstBody.Node.RemoveFromParent(); } }
private void OnEnemyCollision(SKPhysicsContact contact) { bool isPlayerAndEnemyContact = (contact.BodyA.CategoryBitMask == (uint)GameObjects.player && contact.BodyB.CategoryBitMask == (uint)GameObjects.enemy) || (contact.BodyB.CategoryBitMask == (uint)GameObjects.player && contact.BodyA.CategoryBitMask == (uint)GameObjects.enemy); if (isPlayerAndEnemyContact) { SKPhysicsBody EnemyBody; SKPhysicsBody PlayerBody; if (contact.BodyA.CategoryBitMask == (uint)GameObjects.enemy || contact.BodyA.CategoryBitMask == (uint)GameObjects.enemy) { EnemyBody = contact.BodyA; PlayerBody = contact.BodyB; } else { EnemyBody = contact.BodyB; PlayerBody = contact.BodyA; } var enemyObject = SceneGameUnits.Find( (obj) => obj.ID.ToString() == EnemyBody.Node.Name); if (enemyObject != null) { enemyObject.GetDamage(100); Player.GetDamage(10); } else if (EnemyBody.Node == boss.Node) { boss.GetDamage(50); Player.GetDamage(100); } } }
public override void DidBeginContact(SKPhysicsContact contact) { CollisionHappend(contact.BodyA.Node, contact.BodyB.Node); CollisionHappend(contact.BodyB.Node, contact.BodyA.Node); }
public override void DidBeginContact(SKPhysicsContact contact) { if (DidBeginContactAction != null) DidBeginContactAction (contact); }
void DidBeginContact(SKPhysicsContact contact) { SKPhysicsBody firstBody; SKPhysicsBody secondBody; if (contact.BodyA.CategoryBitMask < contact.BodyB.CategoryBitMask) { firstBody = contact.BodyA; secondBody = contact.BodyB; } else { firstBody = contact.BodyB; secondBody = contact.BodyA; } if ((firstBody.CategoryBitMask & Category.Missile) != 0) AttackTarget (secondBody, firstBody.Node); if ((firstBody.CategoryBitMask & Category.Ship) != 0) { if (contact.CollisionImpulse > collisionDamageThreshold && (secondBody.CategoryBitMask & Category.Edge) == 0) { int damage = (int) (contact.CollisionImpulse / collisionDamageThreshold); (firstBody.Node as ShipSprite).ApplyDamage (damage); if ((secondBody.CategoryBitMask == Category.Ship)) (secondBody.Node as ShipSprite).ApplyDamage (damage); } } if ((firstBody.CategoryBitMask & Category.Asteroid) != 0 && (secondBody.CategoryBitMask & Category.Planet) != 0) firstBody.Node.RemoveFromParent (); }
public void DidBeginContact(SKPhysicsContact contact) { inprogress = false; Console.WriteLine("We Collided!"); gameended = true; void gameOver() { var textures = Enumerable.Range(1, 4).Select( (i) => SKTexture.FromImageNamed(String.Format("Death-{0}", i))).ToArray(); deathSpin = SKAction.RepeatAction(SKAction.AnimateWithTextures(textures, .1), 4); var shrink = SKAction.ScaleTo(0f, 2f); var death = SKAction.Sequence(deathSpin, shrink); playerObject.RunAction(death); var playDeath = SKAction.PlaySoundFileNamed("playerDeath", false); playerDied.RunAction(playDeath); gameSong.RunAction(SKAction.CreateStop()); } void animateOver() { var grow = SKAction.ScaleTo(2.0f, 1.5); var shrink = SKAction.ScaleTo(.5f, 1.5); var animate = SKAction.RepeatActionForever(SKAction.Sequence(grow, shrink)); endGame.RunAction(animate); } playerObject.RemoveAllActions(); obstacle.RemoveAllActions(); sidewalk1.RemoveAllActions(); sidewalk2.RemoveAllActions(); sidewalk3.RemoveAllActions(); building1.RemoveAllActions(); building2.RemoveAllActions(); building3.RemoveAllActions(); building4.RemoveAllActions(); building5.RemoveAllActions(); building6.RemoveAllActions(); building7.RemoveAllActions(); building8.RemoveAllActions(); building9.RemoveAllActions(); building10.RemoveAllActions(); building11.RemoveAllActions(); building12.RemoveAllActions(); building13.RemoveAllActions(); building14.RemoveAllActions(); road1.RemoveAllActions(); road2.RemoveAllActions(); road3.RemoveAllActions(); road4.RemoveAllActions(); road5.RemoveAllActions(); road6.RemoveAllActions(); obstacle1.RemoveAllActions(); obstacle2.RemoveAllActions(); enemy.RemoveAllActions(); obstacle4.RemoveAllActions(); scores.Add(score); scores.Sort((a, b) => - 1 * a.CompareTo(b)); var sl = scores.Count; if (sl >= 10) { { sl = 10; } } var plist = NSUserDefaults.StandardUserDefaults; for (int i = 0; i < sl; i++) { { Console.WriteLine(scores[i]); plist.SetInt(scores[i], String.Format("Score-{0}", i)); } } score = 0; //unsubscribe obstacle objects at the end of the round timer.Elapsed -= sendobstacle; timer1.Elapsed -= sendobstacle1; timer2.Elapsed -= sendobstacle2; timer3.Elapsed -= sendobstacle3; timer4.Elapsed -= sendobstacle4; gameOver(); AddChild(endGame); animateOver(); }
private void NodesCollided(SKPhysicsContact contact) { GC.OnNodesCollision(contact); }
public override void DidBeginContact(SKPhysicsContact contact) { base.DidBeginContact(contact); System.Console.WriteLine(contact); }
public override void DidBeginContact(SKPhysicsContact contact) => Callbacks(contact);
public void OnNodesCollision(SKPhysicsContact contact) { OnBulletCollision(contact); OnBonusCollision(contact); OnEnemyCollision(contact); }