【问题标题】:c# visual studio Scrolling game boss level give boss a healthbarc# visual studio Scrolling game boss level 给boss一个healthbar
【发布时间】:2020-10-09 03:38:54
【问题描述】:

制作一个滚动游戏并将其分解成更小的部分,直到我解决了新添加的问题,然后将其添加到游戏中。我想出了如何为玩家创建一个健康条,这样当他被敌人击中时,它会显示健康条的水平正在减少。我似乎无法为敌人的老板做相反的事情。现在我有一个名为 healthbar 的玩家进度条设置为 100%,每次玩家被击中时都会减少 10。我还有一个 Boss 的进度条,叫做 bosshealth,它也设置为 100%,每次被击中时也会减少 10。现在当 Boss 用他的激光击中玩家时,玩家会受到伤害,但当玩家射击 Boss 时,他不会受到任何伤害。

void HitorMiss()
{
    if(Player.Bounds.IntersectsWith(powerarmour.Bounds) || Player.Bounds.IntersectsWith(e1laser.Bounds))
    {
        if (healthbar.Value <= 0)
        {
            healthbar.Value = 100;
        }
        else if (healthbar.Value == 0)
            Dead();
        else
            healthbar.Value -= 10;
    }
    else if(powerarmour.Bounds.IntersectsWith(shoot.Bounds))
    {
        if (bosshealth.Value <= 0)
        {
            bosshealth.Value = 100;
        }
        else if (bosshealth.Value == 0)
        {
            //code to make boss explode and then disappear
        }
        else
            bosshealth.Value -= 10;
    }
}

【问题讨论】:

  • 您是否调试过它是否进入了 else if(powerarmour.Bounds.IntersectsWith(shoot.Bounds)) 块?也许碰撞并不像预期的那样。另外,您是否使用 Unity 或某些库来执行此操作?请标记它。

标签: c#


【解决方案1】:

这是一段相当混乱的代码 - 但我喜欢方法的名称哈哈。

我建议做类似的事情:

  void HitorMiss(){
if(Player.Bounds.IntersectsWith(powerarmour.Bounds) || Player.Bounds.IntersectsWith(e1laser.Bounds))
{
    healthbar.Value = 100;
    if (healthbar.Value == 0) Dead();
    else healthbar.Value -= 10;
}
 if(powerarmour.Bounds.IntersectsWith(shoot.Bounds))
{
    bosshealth.Value = 100; 

    if (bosshealth.Value == 0) BossDead();


    else bosshealth.Value -= 10; 
}}

但我强烈建议您在 hit 方法之外设置 hp 和死亡逻辑。

【讨论】:

  • 为什么是healthbar.Value = 100?每次击中它都会将生命值重置为 100,不是吗?
  • 代码缩进不正确。另外,这个答案如何解决问题? 现在当 Boss 用他的激光击中玩家时,玩家会受到伤害,但当玩家射击 Boss 时,他不会受到任何伤害。 问题是他的代码不适用于后者.
  • 我尝试了你的建议,它只会夺走玩家而不是老板的生命。
  • 基本上我想做的就是为玩家和boss设置一个血条,所以杀死boss需要不止一击
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-15
相关资源
最近更新 更多