微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

处理 - 如何让我的布尔值保持固定更长时间?

如何解决处理 - 如何让我的布尔值保持固定更长时间?

一位学生处理/javascript 业余爱好者,正在寻找有关我制作的游戏的一些建议。它是在 Processing 2.2.1 中制作的,我认为它相对过时,因此变量等的某些名称可能会有所不同。

我认为问题在于,在碰撞事件期间(角色和一个赋予它额外生命的对象),“life”布尔值设置为 true,但仅在碰撞持续时间内。我希望将布尔值设置为 true,直到角色与通常会结束游戏的对象发生碰撞。我目前的设置意味着角色暂时有额外的生命,所以当它接触到坏物体时总是会死亡。

我附上了我的一些代码。有什么建议吗?`

  //Part of the 'good object' code:
  
  void Draw()
  {
    image(Warning_fall,Position.x,130);
    Hat.resize(86,66);

    if (life == true)
    {
      image(Hat,170,50);
    } else
    {
      image(Hat,Position.y);
    }
  }

  void Move()
  {
    Position.add(VeLocity);
  }

  boolean hatHit(float x,float y,float w,float h)   
  {
    if ((x < Position.x) && (x + w > Position.x + 86) && (y + h > Position.y) && (y + h > Position.y + 66))
    {
      return true;
    }
  }
} 

//From the main game code

for (int index = 0; index < num_of_hats; index ++)
    {  
      arrayHats[index].Draw();
      arrayHats[index].Move();
      if (arrayHats[index].hatHit(Students.sx,Students.sy,sw,sh) == true)
      {
        arrayHats[index].life = true;
        bonus = bonus + 1;
      }
    }

 for (int index = 0; index < num_of_cones; index ++)            
    {       
      arrayCones[index].Draw();
      arrayCones[index].Move();  
      if (arrayCones[index].coneHit(Students.sx,sh) == true)
      {
        if (arrayBoots[index].life == true)
         {
           arrayBoots[index].life = false;  // Removes extra life.
          } 
          else
          {
          gameScreen = 4;   //signifies game over.
        }
      }
    }

`

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。