コード例 #1
0
        private void CheckIsUnitOutOfScreen(GameUnit unit)
        {
            bool isNotInScreen = unit.Node.Position.X + unit.Node.Size.Width <0 ||
                                                                              unit.Node.Position.Y + unit.Node.Size.Height> Scene.Size.Width ||
                                 unit.Node.Position.Y + unit.Node.Size.Height < 0;

            if (isNotInScreen)
            {
                DeleteUnit(unit);
                Player.GetDamage(10);
            }
        }
コード例 #2
0
        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);
                }
            }
        }