예제 #1
0
void PPhysics2D::v_updateEntity(entityID id, const GameTime& gameTime) {
    CRigidBody *body = getEntityAs<CRigidBody>(id);
    CTransform *transform = getEntityAs<CTransform>(id);

    //transform->m_position.addScaledVector(body->m_velocity, gameTime.getElapsedSecond());
    transform->setX(transform->getX()  + body->m_velocity.x * gameTime.getElapsedSecond());
    transform->setY(transform->getY()  + body->m_velocity.y * gameTime.getElapsedSecond());
    if (body->m_bApplyGravity) {
        body->addForce(glm::vec2(.0f, 200.0f));
    }
    //body->m_velocity.addScaledVector(body->m_forceAccum, gameTime.getElapsedSecond());
    body->m_velocity.x += body->m_forceAccum.x * gameTime.getElapsedSecond();
    body->m_velocity.y += body->m_forceAccum.y * gameTime.getElapsedSecond();

    body->m_velocity *= powf(body->m_damping, gameTime.getElapsedSecond());

    body->clearForce();
}
예제 #2
0
void PPlayer::v_updateEntity(entityID id, const GameTime& gameTime) {
    CPlayer *player = getEntityAs<CPlayer>(id);
    CTransform *transform = getEntityAs<CTransform>(id);
    CRigidBody *body = getEntityAs<CRigidBody>(id);

    if (player->m_bAlive) {
        player->m_elapsedTime += gameTime.getElapsedMillisecond();
        double temp = 0.25f * sin((double)(MathUtils::TWO_PI * 0.001 * player->m_elapsedTime + 0));

        // set screen position with floating in account
        player->m_floatingAmount = temp;
        transform->setOffsetY(transform->getOffsetY() + player->m_floatingAmount);

        if (player->m_bSpeedUp) {
            if (player->m_actualThrustAmount < player->m_speedupThrustAmount) {
                player->m_actualThrustAmount += 350 * gameTime.getElapsedSecond();
            }
            player->m_bSpeedUp = false;
        }
        else {
            if (player->m_actualThrustAmount < player->m_maxThrustAmount) {
                player->m_actualThrustAmount += 150 * gameTime.getElapsedSecond();
            }
            else if (player->m_actualThrustAmount > player->m_maxThrustAmount) {
                player->m_actualThrustAmount -= 250 * gameTime.getElapsedSecond();
            }
        }
        
        body->m_velocity.y = sin(transform->getRotation()) * player->m_actualThrustAmount;
        body->m_velocity.x = player->m_forward.x * cos(transform->getRotation()) * player->m_actualThrustAmount;

        if (player->m_cooldown > 0) {
            player->m_cooldown -= gameTime.getElapsedMillisecond();
            // Design issue : Draw with UpdateProcess
            Locator::getRenderer()->renderRectangle(true, transform->getX() - 25, transform->getY() + 55, 75, 5, 0xFF, 0xFF, 0xFF);
            Locator::getRenderer()->renderRectangle(true, transform->getX() - 25, transform->getY() + 55, (1 - (player->m_cooldown / player->m_defaultCooldown)) * 75, 5, 0x66, 0x99, 0x99);
        }
    }
}
void PParticuleManager::v_updateEntity(entityID id, const GameTime& gameTime) {
    CParticuleEmitter *e = getEntityAs<CParticuleEmitter>(id);
    CTransform *transform = getEntityAs<CTransform>(id);

    if (e->m_bActive) {
        e->m_elapsedRate += gameTime.getElapsedMillisecond();
        if (e->m_elapsedRate > e->m_rate)  {

            // due to custom memory allocation used by clone method, the pointer could
            // be null sometimes
            IParticule* p = e->m_particulePrototype->cloneIntoPool();
            if (p != nullptr) {

                // TODO : cause a division per zero
                /*float lv = (e->m_lifetimeVariation > 0) ? MathUtils::randint(e->m_lifetimeVariation * 2) - e->m_lifetimeVariation : 0;
                float av = (e->m_angleVariation > 0) ? MathUtils::randint(e->m_angleVariation * 2) - e->m_angleVariation : 0;
                float sv = (e->m_speedVariation > 0) ? MathUtils::randint(e->m_speedVariation * 2) - e->m_speedVariation : 0;
                float pv = (e->m_spawnPositionVariation > 0) ? MathUtils::randint(e->m_spawnPositionVariation * 2) - e->m_spawnPositionVariation : 0;*/
                float lv , av, sv, pv = 0;

                p->m_x = transform->getX() + pv;
                p->m_y = transform->getY() + pv;
                p->m_elapsed = 0;
                p->m_lifetime = e->m_lifetime + lv;
                glm::vec2 velocity = MathUtils::fromPolar(e->m_angle + av, e->m_speed + sv);
                p->m_vx = velocity.x;
                p->m_vy = velocity.y;

                p->m_gravityApplied = e->m_bIsGravityApplied;

                m_particulesEmitted.push_back(p);
            }
            e->m_elapsedRate = 0;
        }
    }
}