当前位置: 首页>>代码示例>>C#>>正文


C# Hero.Die方法代码示例

本文整理汇总了C#中Hero.Die方法的典型用法代码示例。如果您正苦于以下问题:C# Hero.Die方法的具体用法?C# Hero.Die怎么用?C# Hero.Die使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Hero的用法示例。


在下文中一共展示了Hero.Die方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CollidePlayer

    private void CollidePlayer(Hero attackingHero)
    {
        // This hero is fast enough to kill the hero that ran into it
        if (this.AboveThreshold && !attackingHero.AboveThreshold)
        {
            GameObject projectileExplosion = (GameObject)GameObject.Instantiate(attackingHero.ProjectileExplosion, this.transform.position, this.transform.rotation);
            projectileExplosion.GetComponent<SpriteRenderer>().sprite = attackingHero.ProjectileExplosionSprite;
            this.velocity -= attackingHero.velocity;
            attackingHero.Die(null);
        }

        // Hero that rammed this hero is fast enough to kill
        else if (!this.AboveThreshold && attackingHero.AboveThreshold)
        {
            GameObject projectileExplosion = (GameObject)GameObject.Instantiate(attackingHero.ProjectileExplosion, this.transform.position, this.transform.rotation);
            projectileExplosion.GetComponent<SpriteRenderer>().sprite = attackingHero.ProjectileExplosionSprite;
            attackingHero.velocity -= this.velocity;
            this.Die(null);
        }

        else if (this.AboveThreshold && attackingHero.AboveThreshold)
        {
            if (this.velocity.magnitude > attackingHero.velocity.magnitude)
            {
                this.velocity -= attackingHero.velocity;
                attackingHero.Die(null);
            }
            else
            {
                attackingHero.velocity -= this.velocity;
                this.Die(null);
            }
        }
        // Neither of the colliding heroes are fast enough to kill, so they reverse their direction
        else
        {
            // this.accelerateByScalar(-1.0f);
            // attackingHero.accelerateByScalar(-1.0f);
            Vector2 ourVelo = this.velocity;
            Vector2 theirVelo = attackingHero.velocity;

            Vector2 ourNewVelo = new Vector2(theirVelo.x - ourVelo.x, theirVelo.y - ourVelo.y).normalized * theirVelo.magnitude;
            Vector2 theirNewVelo = (ourNewVelo * -1f).normalized * theirVelo.magnitude;

            this.velocity = ourNewVelo;
            attackingHero.velocity = theirNewVelo;

            Vector2 ourPos = gameObject.transform.position;
            Vector2 theirPos = attackingHero.gameObject.transform.position;
            CollisionController ourCol = gameObject.GetComponent<CollisionController>();
            CollisionController theirCol = attackingHero.gameObject.GetComponent<CollisionController>();
            float ourRad = ourCol.getRadius();
            float theirRad = theirCol.getRadius();

            float distance = (float) Math.Sqrt(Math.Pow(ourPos.x - theirPos.x, 2) + Math.Pow(ourPos.y - theirPos.y, 2));
            float minDistance = 1.5f * (ourRad + theirRad);

            if(distance < minDistance) {
                this.transform.Translate (this.velocity * Time.fixedDeltaTime);
                attackingHero.transform.Translate (attackingHero.velocity * Time.fixedDeltaTime);
            }
        }
    }
开发者ID:BrianShiau,项目名称:TeamGimli,代码行数:63,代码来源:Hero.cs

示例2: MonsterAttack

 private static void MonsterAttack(Hero hero, Monster monster)
 {
     activated = hero.Shield.ActivateSpecial();
     hero.TakeDamage(monster.Damage - (int)hero.Shield.Defense);
     if (activated)
     {
         hero.Shield.DeactivateSpecial();
     }
     if (hero.Health <= 0)
     {
         hero.Die();
         Sounds.StopBattleMusic();
         Sounds.StartMapMusic();
     }
     BlessingOfTheBattle(monster);
 }
开发者ID:K-Pavlov,项目名称:Telerik-Teamwork,代码行数:16,代码来源:BattleLogic.cs


注:本文中的Hero.Die方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。