예제 #1
0
파일: Vessel.cpp 프로젝트: NickPowers43/SW
	void Vessel::AddMyPlayer(Player* player, NetworkWriter* nw)
	{
		if (player)
		{
			myPlayer = player;
			UpdateChunks(true, nw);
		}
		else
		{
			PrintMessage((int)"NULL player added");
		}
	}
예제 #2
0
파일: Space.cpp 프로젝트: treeman/Sat-E
void Space::Update( float dt )
{
    if( satellite.HasFriend() ) {
        victory = true;
    }
    else if( satellite.Fuel() == 0.0 || satellite.Life() == 0.0 ) {
        game_over = true;
    }

    if( dock.IsActive() ) {
        dock.Update( dt );
    }
    else if( !victory ) {
        satellite.Update( dt ); // prevent movement when in docking mode

        // Update movements for the satellite in a fluid manner
        const sf::Input &input = GAME->GetInput();

        Vec2i acc;
        // Set direction
        if( input.IsKeyDown( sf::Key::Left ) ) {
            acc += Vec2f::left;
        }
        if( input.IsKeyDown( sf::Key::Right ) ) {
            acc += Vec2f::right;
        }
        if( input.IsKeyDown( sf::Key::Up ) ) {
            acc += Vec2f::up;
        }
        if( input.IsKeyDown( sf::Key::Down ) ) {
            acc += Vec2f::down;
        }

        // Set size
        acc.SetMagnitude( satellite.AccBoost() );

        satellite.Accelerate( acc );
    }

    // Check victory conditions
    if( victory ) {
        satellite.KillNarrative();

        talk_str.SetText( endgame_chat.Get() );

        //friend_spr.Rotate( 10 * dt );

        // Update fading
        if( endgame_chat.IsDone() ) {
            fade_timer.Start(); // Doesn't affect if already started
            //L_("ticking: %.1f\n", fade_timer.GetTime());

            const float fade_time = 5.0;
            fade = (int)( 0xff * fade_timer.GetTime() / fade_time );
            //L_("fade: %d 255 * tick / %.1f\n", fade, fade_time);
            if( fade > 0xff ) {
                fade = 0xff;
                GAME->Exit();
            }
        }
    }
    else if( game_over ) {
        satellite.KillNarrative();

        fade_timer.Start(); // Doesn't affect if already started

        const float fade_time = 5.0;
        fade = (int)( 0xff * fade_timer.GetTime() / fade_time );
        if( fade > 0xff ) {
            // Restart game
            game_over = victory = false;
            can_activate_docking = false;

            satellite.Reset();
            dock.Reset();

            satellite.SetPos( 480, 480 );
            box.SetPos( 500, 500 );
            fade = 0;

            existing_chunks.clear();
            checked_chunks.clear();
            chunks.clear();

            return;
        }
    }

    box.Update( dt );

    // Retract fuel
    satellite.ChangeFuel( - TWEAKS->GetNum( "fuel_speed" ) * dt );

    // Off centered... Would want a better way but meh
    Vec2f sat_pos = satellite.GetPos();
    sat_pos.x += 5; sat_pos.y += 5;

    const Vec2f docking = sat_pos - box.GetPos();

    // Check for closeness to our docking system
    if( docking.Magnitude() <= 30 ) { // We're close!!
        box.IsClose( true ); // Visible cue

        // Increase our fuel
        satellite.ChangeFuel( TWEAKS->GetNum( "refuel_speed" ) * dt );

        // If we just entered docking
        if( docking.Magnitude() <= 25 ) {
            if( can_activate_docking ) {
                dock.Activate();
                can_activate_docking = false;
            }
        }
    }
    else {
        box.IsClose( false );
        can_activate_docking = true;
    }

    // Home arrow
    if( satellite.SeesWayHome() && docking.Magnitude() > 200 ) {
        Vec2f show_home = docking;
        show_home.SetMagnitude( 50 );
        Vec2f arrow_pos = sat_pos - show_home;
        arrow_home_spr.SetPosition( arrow_pos );

        float angle = - atan2( show_home.y, show_home.x );

        float degree = 180 / math::PI * angle;
        arrow_home_spr.SetRotation( degree );
    }

    // Update chunks, allocate more if needed
    UpdateChunks( dt );

    if( !game_over ) {
        // Center cam on satellite
        CenterCam( satellite.GetPos() );
    }

    // Debug chunk
    //Chunks::iterator it = chunks.find( CurrentChunkIndex() );
    //if( it != chunks.end() ) {
        //Chunk &chunk = it->second;
        //std::stringstream ss;
        //ss << "chunk_rand: " << chunk.Rand() << '\n';
        //Tree::VisualDebug( ss.str() );
    //}
}