Пример #1
0
void LaserBeam::OnRender(const render_context_t &context)
{
    context.painter->save();

    float lifeFraction = 0.0f;
    if (lifetime > 0.0f)
    {
        lifeFraction = MAX(0, timer - GetGameContext()->GetGameTime()) / lifetime;
    }

    float flashFraction = 1.0f;
    if (flashTimer > 0.0f)
    {
        flashFraction = MAX(0, flashTimer - GetGameContext()->GetGameTime()) / LASER_FLASH_DURATION;
    }

    float baseAlpha = qPow(lifeFraction, 0.5f);
    float flashAlpha = qPow(flashFraction, 2.0f);

    QColor color(160, 255, 175);

    context.painter->setPen(Qt::transparent);
    context.painter->setCompositionMode(QPainter::CompositionMode_Plus);



    Vector2D size = GetSize();
    size.y = flashSize * baseAlpha * 3.0f;
    Vector2D origin = GetOrigin() - size * 0.5f;

    Camera::GetInstance()->ToScreen(origin);
    Camera::GetInstance()->Scale(size);

    color.setAlpha(flashAlpha * baseAlpha * 255);

    context.painter->setBrush(color);
    context.painter->drawRect(origin.x, origin.y, size.x, size.y);

    size = GetSize();
    size.y = fixedSize * baseAlpha;
    origin = GetOrigin() - size * 0.5f;

    Camera::GetInstance()->ToScreen(origin);
    Camera::GetInstance()->Scale(size);

    color.setAlpha(baseAlpha * 255);

    context.painter->setBrush(color);
    context.painter->drawRect(origin.x, origin.y, size.x, size.y);
    context.painter->restore();
}
bool AbstractDelayedScriptEvent::ShouldFire() const
{
    if (GetGameContext()->GetGameTime() < startTime)
        return false;

    return BaseClass::ShouldFire();
}
Пример #3
0
    GfxFunctions* GetGfxFunctions()
    {
        auto contextPtr = reinterpret_cast<u32*>(GetGameContext());

        // GfxContext* is at GameContext+0x934
        return reinterpret_cast<GfxFunctions*>(contextPtr[0x934 / 4]);
    }
Пример #4
0
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));
}
Пример #5
0
void LaserBeam::Spawn()
{
    BaseClass::Spawn();

    timer = GetGameContext()->GetGameTime() + lifetime;

    spawned = false;
}
Пример #6
0
    virtual void Spawn()
    {
        yspeed = qlerp(qfrand(), FIGHTER_1_Y_SPEED_MIN, FIGHTER_1_Y_SPEED_MAX);
        startTime = GetGameContext()->GetGameTime() + qfrand() * 1.0f;
        salvoCount = 0;
        movingDown = qbrand();

        float yspeed = movingDown ? -FIGHTER_1_X_SPEED : FIGHTER_1_X_SPEED;
        GetShip()->SetVelocity(Vector2D(FIGHTER_1_X_SPEED, yspeed));
    }
Пример #7
0
void Projectile::Init(const Resource_Projectile_t &data, bool playerOwner)
{
    this->playerOwner = playerOwner;
    this->data = data;

    SetSize(Vector2D(data.size, data.size));

    ParticleSystem *particlesSpawn = nullptr;

    if (!data.particle_trail.empty())
        particlesIdle = GetGameContext()->GetParticleRoot()->CreateParticles(data.particle_trail.c_str());
    if (!data.particle_spawn.empty())
        particlesSpawn = GetGameContext()->GetParticleRoot()->CreateParticles(data.particle_spawn.c_str());

    if (!particlesIdle.isNull())
        particlesIdle->SetParticleParent(this);
    if (particlesSpawn != nullptr)
        particlesSpawn->SetParticleParent(this);
}
void CGameServerChannel::SetupNetChannel(INetChannel *pNetChannel)
{
	pNetChannel->SetServer(GetGameContext()->GetNetContext(), true);
  INetChannel::SPerformanceMetrics pm;
	if (!gEnv->bMultiplayer)
		pm.pPacketRateDesired = gEnv->pConsole->GetCVar("g_localPacketRate");
	else
		pm.pPacketRateDesired = gEnv->pConsole->GetCVar("sv_packetRate");
	pm.pBitRateDesired = gEnv->pConsole->GetCVar("sv_bandwidth");
	pNetChannel->SetPerformanceMetrics(&pm);
}
Пример #9
0
    virtual void OnSimulate(float frametime)
    {
        float originy = GetShip()->GetOrigin().y;
        float sizeyhalf = GetShip()->GetSize().y * 0.5f;

        if (!movingDown
                && originy - sizeyhalf < Camera::GetInstance()->GetWorldMins().y)
        {
            movingDown = true;
            GetShip()->SetVelocity(Vector2D(FIGHTER_1_X_SPEED, yspeed));
        }
        else if (movingDown
                 && originy + sizeyhalf > Camera::GetInstance()->GetWorldMaxs().y)
        {
            movingDown = false;
            GetShip()->SetVelocity(Vector2D(FIGHTER_1_X_SPEED, -yspeed));
        }

        if (!IsShipFullyVisible())
        {
            return;
        }

        if (startTime > GetGameContext()->GetGameTime())
        {
            return;
        }

        if (GetShip()->CanShoot())
        {
            GetShip()->Shoot(Vector2D(-1, 0), 20.0f);

            salvoCount++;

            if (salvoCount >= 3)
            {
                salvoCount = 0;
                startTime = GetGameContext()->GetGameTime() + 1.5f;
            }
        }
    }
Пример #10
0
void Ship::Shoot(const Vector2D &direction,
                 const Resource_Projectile_t &projectile, Vector2D offset)
{
    Projectile *p = (Projectile*)GetGameContext()->CreateEntityNoSpawn("projectile");

    Q_ASSERT(p != nullptr);

    float volume = IsPlayer() ? 0.5f : 0.3f;

    offset.Rotate(GetAngle());

    p->SetOwner(this);
    p->Teleport(GetOrigin() + offset);
    p->SetAngle(direction.Angle());
    p->Init(projectile, IsPlayer());
    p->Launch(direction, volume);

    if (projectile.fire_rate > 0.0f)
        shootDelay = GetGameContext()->GetGameTime() + 1.0f / projectile.fire_rate;

    GetGameContext()->SpawnEntity(p);
}
void Destructible::EmitDamageParticles(const char *particleName, const Damage_t *damage, Vector2D position)
{
    if (particleName != nullptr && *particleName != 0)
    {
        Vector2D direction(GetForward());

        if (damage != nullptr)
        {
            direction = damage->direction;
        }

        GetGameContext()->GetParticleRoot()->CreateParticles(particleName,
                                          position, direction);
    }
}
CGameServerChannel::CGameServerChannel(INetChannel *pNetChannel, CGameContext *pGameContext, CGameServerNub *pServerNub)
: m_pServerNub(pServerNub), m_channelId(0), m_hasLoadedLevel(false), m_onHold(false)
{
	Init( pNetChannel, pGameContext );
	CRY_ASSERT(pNetChannel);

#if NEW_BANDWIDTH_MANAGEMENT
	pNetChannel->SetServer(GetGameContext()->GetNetContext(), true);
#else
	SetupNetChannel(pNetChannel);
#endif // NEW_BANDWIDTH_MANAGEMENT

	if (!sv_timeout_disconnect)
		sv_timeout_disconnect=gEnv->pConsole->GetCVar("sv_timeout_disconnect");

	gEnv->pConsole->AddConsoleVarSink( this );
  CCryAction::GetCryAction()->OnActionEvent(SActionEvent(eAE_channelCreated,1));
}
Пример #13
0
void Projectile::OnCollision(ICollidable *other)
{
    Remove();

    if (!data.particle_hit.empty())
        GetGameContext()->GetParticleRoot()->CreateParticles(data.particle_hit.c_str(), GetOrigin(), GetForward());

    Entity *entity = (Entity*)other;

    Damage_t damage;
    damage.damage = 1;
    damage.inflictor = this;
    damage.direction = GetForward();
    damage.statsInflictorName = inflictorName;
    damage.statsInflictorClass = inflictorClass;
    damage.statsWeaponName = GetEntityClassName();
    damage.statsWeaponClass = GetEntityResourceClass();
    entity->TakeDamage(damage);
}
Пример #14
0
void LaserBeam::OnSimulate(float frametime)
{
    BaseClass::OnSimulate(frametime);

    float laserLength = Camera::GetInstance()->GetWorldMaxs().x - Camera::GetInstance()->GetWorldMins().x;
    float gameTime = GetGameContext()->GetGameTime();

    SetSize(Vector2D(laserLength, LASER_MAX_SIZE_Y));

    Entity *owner = GetOwner();

    if (owner == nullptr
            || timer < gameTime)
    {
        Remove();
    }
    else
    {
        Vector2D center = owner->GetOrigin();
        center.x -= laserLength * 0.5f;
        center += offset;

        if (!spawned)
        {
            Teleport(center);
            spawned = true;
        }
        else
        {
            SetOrigin(center);
        }
    }

    if (flashTimer < gameTime)
    {
        flashSize = fixedSize;
        fixedSize = qlerp(qfrand(), LASER_MIN_SIZE_Y, LASER_MAX_SIZE_Y);
        flashTimer = gameTime + LASER_FLASH_DURATION;
    }
}
 virtual void FireEvent()
 {
     GetGameContext()->ShowWarningText();
 }
Пример #16
0
void Ship::SetShootDelay(float delay)
{
    shootDelay = GetGameContext()->GetGameTime() + delay;
}
Пример #17
0
bool Ship::CanShoot() const
{
    return shootDelay < GetGameContext()->GetGameTime();
}