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


C++ Entity::GetHealth方法代码示例

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


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

示例1: OnCollision

void LaserBeam::OnCollision(ICollidable *other)
{
    Entity *entity = (Entity*)other;

    Damage_t damage;
    damage.damage = entity->GetHealth();

    if (entity->IsPlayer())
    {
        damage.damage = 1;
    }

    damage.direction = Vector2D(-1, 0);
    damage.inflictor = GetOwner();

    if (GetOwner() != nullptr)
    {
        damage.statsInflictorName = GetOwner()->GetEntityClassName();
        damage.statsInflictorClass = GetOwner()->GetEntityResourceClass();
    }

    damage.statsWeaponName = GetEntityClassName();
    damage.statsWeaponClass = GetEntityResourceClass();

    entity->TakeDamage(damage);

    Vector2D laserCenter = GetOrigin();
    laserCenter.x = entity->GetOrigin().x;

    GetGameContext()->GetParticleRoot()->CreateParticles("laser_cannon_hit", laserCenter, Vector2D(-1, 0));
}
开发者ID:Biohazard90,项目名称:Project-Neo-Gemini,代码行数:31,代码来源:laserbeam.cpp

示例2: DrawESP

void hud::DrawESP()
{
    surface->SetFont(ui::font_hud);
    surface->SetTextColor(0xff, 0xff, 0xff, 0xff);

    Entity *lp  = LocalPlayer();
    int  maxent = globals->maxclients();

    for (int i = 1; i <= ents->GetMaxEntities(); ++i)
    {
        Entity *ent = ents->GetEntity(i);

        if (ent == nullptr || ent == lp)
            continue;

        if (ent->IsDormant())
            continue;

        if (1 && i <= maxent)
        {
            if (!ent->IsAlive())
                continue;

            int x0, y0, x1, y1;

            if (!MakeBox(ent, x0, y0, x1, y1))
             	continue;

            surface->SetColor(0x00, 0x00, 0x00, 0x7f);
            surface->DrawOutlinedRect(x0 - 1, y0 - 1, x1 + 1, y1 + 1);
            surface->DrawOutlinedRect(x0 + 1, y0 + 1, x1 - 1, y1 - 1);

            if (1) // menu.ESP.health
             	surface->DrawFilledRect(x0 - 4, y0 - 1, x0 - 1, y1 + 1);

#if defined(L4D) || defined(L4D2)
            switch (ent->GetTeam())
            {
                case 2:
                case 4:
                    surface->SetColor(0x46, 0x78, 0xff, 0xff);
                break;

                case 3:
                    surface->SetColor(0x96, 0x00, 0xe1, 0xff);
                break;
            }
#else
            switch (ent->GetTeam())
            {
                case TEAM_RED:
                    surface->SetColor(0xff, 0x64, 0x64, 0xff);
                break;

                case TEAM_BLU:
                    surface->SetColor(0x46, 0x78, 0xff, 0xff);
                break;
            }
#endif

            surface->DrawOutlinedRect(x0, y0, x1, y1);

            if (1) // menu.ESP.health
            {
                if (ent->GetHealth() <= ent->GetMaxHealth())
                {
                    if (ent->GetHealth() <= (ent->GetMaxHealth() / 4))
                        surface->SetColor(0xff, 0x00, 0x00, 0xff);
                    else
                        surface->SetColor(0x00, 0xff, 0x00, 0xff);
                }

                surface->DrawFilledRect(x0 - 3, y1 - Min<int>(y1 - y0, (float)(y1 - y0) * ((float)ent->GetHealth() / (float)ent->GetMaxHealth()) + 0.5f), x0 - 1, y1);
            }

            if (1) // menu.ESP.name
            {
                player_info info;
                engine->GetPlayerInfo(i, info);

                int length = 0;
                const wchar_t *text = tounicode(info.name, length);

                int tw, th;
                surface->GetTextSize(ui::font_hud, text, tw, th);

                surface->SetTextPos((x0 + x1 - tw) / 2, y0 - th);
                surface->DrawText(text, length, 0);
            }

            if (1) // menu.ESP.weapon
            {
                Entity *weapon = ent->GetActiveWeapon();

                if (weapon)
                {
                    const char *classname = weapon->GetClass();
#ifndef GMOD
                    if (qstrlen(classname) > 6)
                    {
//.........这里部分代码省略.........
开发者ID:TSM-Dev,项目名称:nh30,代码行数:101,代码来源:hud.cpp


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