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


C++ Monster::SetDirection方法代码示例

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


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

示例1: tick


//.........这里部分代码省略.........
    }

    if (levelMap_.GetCell(x, y - 0.51f) != '.')
    {
      p.SetPosition(Vector2(p.GetPosition().x, round(y - 0.5f) + 0.5f));
      collided = true;
    }

    if (collided)
    {
      actor->OnCollideWorld();
    }
  };

  for (Actor* actor: actors_)
  {
    if (actor->GetType() == EActorType::MONSTER)
    {
      Monster* monster = dynamic_cast<Monster*>(actor);
      Creature* target = monster->target;
      float distance2;
      Vector2 m_pos = actor->GetPosition();
      if (target && target != nullptr)
      {
        Vector2 t_pos = target->GetPosition();
        distance2 = Sqr(m_pos.x - t_pos.x)
                    + Sqr(m_pos.y - t_pos.y);
        if (distance2 < 25)
        {
          if (abs(m_pos.x - t_pos.x - 1.0f) < playerVelocity_
              && m_pos.x - t_pos.x - 1.0f != 0)
          {
            monster->SetPosition(Vector2(t_pos.x + 1.0f, m_pos.y));
            monster->SetDirection(EActorDirection::NONE);
          }

          if (abs(m_pos.y - t_pos.y + 1.0f) < playerVelocity_
              && m_pos.y - t_pos.y + 1.0f != 0)
          {
            monster->SetPosition(Vector2(m_pos.x, t_pos.y - 1.0f));
            monster->SetDirection(EActorDirection::NONE);
          }

          if (m_pos.x < t_pos.x - 1.0f)
          {
            monster->SetDirection(EActorDirection::EAST);
          }
          else if (m_pos.x > t_pos.x + 1.0f)
          {
            monster->SetDirection(EActorDirection::WEST);
          }
          else if (m_pos.y < t_pos.y - 1.0f)
          {
            monster->SetDirection(EActorDirection::SOUTH);
          }
          else if (m_pos.y > t_pos.y + 1.0f)
          {
            monster->SetDirection(EActorDirection::NORTH);
          }
        }
      }

      if (!target
          || target == nullptr
          || distance2 >= 5)
      {
开发者ID:dahin,项目名称:fefu-mmorpg,代码行数:67,代码来源:GameServer.cpp

示例2: HandlePutMob_

//==============================================================================
void GameServer::HandlePutMob_(const QVariantMap& request, QVariantMap& response)
{
  if (!testingStageActive_)
  {
    WriteResult_(response, EFEMPResult::BAD_ACTION);
    return;
  }

  if (!request["x"].toFloat()
      || !request["y"].toFloat())
  {
    WriteResult_(response, EFEMPResult::BAD_PLACING);
    return;
  }

  float x = request["x"].toFloat();
  float y = request["y"].toFloat();

  Monster* monster = CreateActor_<Monster>();
  SetActorPosition_(monster, Vector2(x, y));

  monster->SetDirection(EActorDirection::SOUTH);

  if (IsPositionWrong(x, y, monster))
  {
    KillActor_(monster);
    WriteResult_(response, EFEMPResult::BAD_PLACING);
    return;
  }

  auto flags = request["flags"].toList();
  for (auto flag: flags)
  {
    if (monster->possibleFlags.lastIndexOf(flag.toString()) == -1)
    {
      WriteResult_(response, EFEMPResult::BAD_FLAG);
      return;
    }
     monster->Flags.push_back(flag.toString());
  }

  monster->SetRace(request["race"].toString());
  if (monster->GetRace() == "NONE")
  {
    WriteResult_(response, EFEMPResult::BAD_RACE);
    return;
  }

  auto stats = request["stats"].toMap();
  for (auto s = stats.begin(); s != stats.end(); s++)
  {
    EStatConst stat = StringToStat[s.key()];
    QVariant val = s.value();
    monster->SetStat(stat, val.toFloat());
  }

  auto inventory = request["inventory"].toList();
  for (auto elem: inventory)
  {
    Item* item = CreateActor_<Item>();
    SetItemDescription(elem.toMap(), item);
    item->SetOnTheGround(false);
    monster->items.push_back(item);
    actors_.erase(std::remove(actors_.begin(), actors_.end(), item)
                , actors_.end()); //???
  }

  QStringList damage;
  damage << request["dealtDamage"].toString().split("d");

  if (damage.size() < 2
      || !damage[0].toInt()
      || !damage[1].toInt())
  {
    WriteResult_(response, EFEMPResult::BAD_DAMAGE);
    return;
  }

  response["id"] = monster->GetId();
}
开发者ID:dahin,项目名称:fefu-mmorpg,代码行数:81,代码来源:GameServer.cpp


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