コード例 #1
0
ファイル: Ship.cpp プロジェクト: streibeb/cs409
void Ship :: update (WorldInterface& r_world)
{
    if (isUnitAiSet())
    {
        if (!desired_velocity.isZero())
        {
            double theta = max_rotation_rate * TimeSystem::getFrameDuration();
            if(theta > 0.0)
            {
                rotateTowards(desired_velocity.getNormalized(), theta);
            }
            
            double delta = max_acceleration * TimeSystem::getFrameDuration();
            if(delta > 0.0)
            {
                double currentSpeed = getSpeed();
                double desiredSpeed = desired_velocity.getNorm();
                
                if (currentSpeed < desiredSpeed)
                {
                    currentSpeed += delta;
                    if (currentSpeed > desiredSpeed) currentSpeed = desiredSpeed;
                    setSpeed(currentSpeed);
                }
                else if (currentSpeed > desiredSpeed)
                {
                    currentSpeed -= delta;
                    if (currentSpeed < desiredSpeed) currentSpeed = desiredSpeed;
                    setSpeed(currentSpeed);
                }
            }
        }
        
        if (wantsToFire && isReloaded())
        {
            r_world.addBullet(getPosition(), getForward(), getId());
            wantsToFire = false;
            markReloading();
        }
    }
    
	if(isAlive() && isDying())
	{
		r_world.addExplosion(getPositionPrevious(), getRadius() * EXPLOSION_SIZE_FACTOR, 0);
		m_is_dead = true;

		// no further updates
		assert(invariant());
		return;
	}

	if(isAlive())
	{
		updateBasic();  // moves the Ship

		m_reload_timer += TimeSystem::getFrameDuration();
	}

	assert(invariant());
}
コード例 #2
0
ファイル: Ship.cpp プロジェクト: whitelight2134/spacewar
void Ship::update(WorldInterface& world)
{
	if (m_health <= 0 && m_status == dying){
		m_status = dead;
		world.addExplosion(getPositionPrevious(), EXPLOSION_SIZE, 0);
	}

	if (m_status == alive){
		if (isUnitAiSet()){
			double duration = TimeSystem::getFrameDuration();
			m_coordinate.rotateToVector(m_desired_velocity, duration*m_rotation_rate);
			changeSpeed(m_desired_velocity.getNorm(), duration*m_acceleration);
			if (m_fire_bullet_desired && isBulletReady()){
				world.addBullet(getPosition(), m_coordinate.getForward(), m_id);
				m_fire_bullet_desired = false;
				reloadBullet();
			}
		}
		updateBasic();
		m_reloadTimer.update();
	}


	else if (m_health > 0 && m_status == dead){
		m_status = alive;
		Vector3 position = m_coordinate.getPosition();
		position -= 500 * m_coordinate.getForward();
		m_coordinate.setPosition(position);
	}
}