Beispiel #1
0
void VideoEngine::DrawFPS()
{
    if(!_fps_display)
        return;

    uint32 frame_time = vt_system::SystemManager->GetUpdateTime();
    SetDrawFlags(VIDEO_X_LEFT, VIDEO_Y_BOTTOM, VIDEO_X_NOFLIP, VIDEO_Y_NOFLIP, VIDEO_BLEND, 0);

    // Calculate the FPS for the current frame
    uint32 current_fps = 1000;
    if(frame_time) {
        current_fps /= frame_time;
    }

    // The number of times to insert the current FPS sample into the fps_samples array
    uint32 number_insertions;

    if(_number_samples == 0) {
        // If the FPS display is uninitialized, set the entire FPS array to the current FPS
        _number_samples = FPS_SAMPLES;
        number_insertions = FPS_SAMPLES;
    } else if(current_fps >= 500) {
        // If the game is going at 500 fps or faster, 1 insertion is enough
        number_insertions = 1;
    } else {
        // Find if there's a discrepancy between the current frame time and the averaged one.
        // If there's a large difference, add extra samples so the FPS display "catches up" more quickly.
        float avg_frame_time = 1000.0f * FPS_SAMPLES / _fps_sum;
        int32 time_difference = static_cast<int32>(avg_frame_time) - static_cast<int32>(frame_time);

        if(time_difference < 0)
            time_difference = -time_difference;

        if(time_difference <= static_cast<int32>(MAX_FTIME_DIFF))
            number_insertions = 1;
        else
            number_insertions = FPS_CATCHUP; // Take more samples to catch up to the current FPS
    }

    // Insert the current_fps samples into the fps_samples array for the number of times specified
    for(uint32 j = 0; j < number_insertions; j++) {
        _fps_sum -= _fps_samples[_current_sample];
        _fps_sum += current_fps;
        _fps_samples[_current_sample] = current_fps;
        _current_sample = (_current_sample + 1) % FPS_SAMPLES;
    }

    uint32 avg_fps = _fps_sum / FPS_SAMPLES;

    // The text to display to the screen
    char fps_text[16];
    sprintf(fps_text, "FPS: %d", avg_fps);

    Move(930.0f, 720.0f); // Upper right hand corner of the screen
    Text()->Draw(fps_text, TextStyle("text20", Color::white));

} // void GUISystem::_DrawFPS(uint32 frame_time)
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
Box3D::Box3D(void)
{
	SetEmpty();
	SetDrawFlags(0);
	m_TranslateMode = modeScale;
	m_vTranslationFixPoint.Init();
	m_TranslateHandle.Init();
	m_bEnableHandles = true;
	SetDrawColors(Options.colors.clrToolHandle, Options.colors.clrToolBlock);
}
Beispiel #3
0
void VideoEngine::_DrawFPS()
{
    if(!_fps_display || !_FPS_textimage)
        return;

    PushState();
    SetStandardCoordSys();
    SetDrawFlags(VIDEO_X_LEFT, VIDEO_Y_BOTTOM, VIDEO_X_NOFLIP, VIDEO_Y_NOFLIP, VIDEO_BLEND, 0);
    Move(930.0f, 40.0f); // Upper right hand corner of the screen
    _FPS_textimage->Draw();
    PopState();
} // void GUISystem::_DrawFPS()
// Set the relevant animation depending on the state of the player following the update loop
void Player::SetAnimationFrame()
{
	PlayerState state;
	AnimationState newState;

	if (p_Window->GetKey(Mega::Keys::MOVE_LEFT) == JKEY_HOLD)
		SetDrawFlags(jvis::Sprite::DrawFlags::FlipHorizontal);
	else if (p_Window->GetKey(Mega::Keys::MOVE_RIGHT) == JKEY_HOLD)
		RemoveDrawFlags(jvis::Sprite::DrawFlags::FlipHorizontal);


	if (m_TimerDeath.ElapsedMilliseconds() > 0)
		newState = AnimationState::SPAWNING;
	// Been hit
	else if (m_TimerInvincibility.ElapsedMilliseconds() < INVINCIBILITY_TIME / 2.5f)
		newState = AnimationState::INVINCIBLE;
	else if (m_HasCollidedBelow)
	{
		if (m_TimerBulletAnimationDelay.ElapsedMilliseconds() < FIRING_ANIMATION_DELAY)
		{
			// Running and gunning
			if (p_Window->GetKey(Mega::Keys::MOVE_LEFT) == JKEY_HOLD || p_Window->GetKey(Mega::Keys::MOVE_RIGHT) == JKEY_HOLD)
				newState = AnimationState::SHOOTRUN;
			else // Still firing
				newState = AnimationState::SHOOTSTILL;
		}
		else
		{
			// Running
			if (p_Window->GetKey(Mega::Keys::MOVE_LEFT) == JKEY_HOLD || p_Window->GetKey(Mega::Keys::MOVE_RIGHT) == JKEY_HOLD)
				newState = AnimationState::RUN;
			else // standing still
				newState = AnimationState::STILL;
		}
	}
	else
	{
		// Firing and jumping
		if (m_TimerBulletAnimationDelay.ElapsedMilliseconds() < FIRING_ANIMATION_DELAY)
			newState = AnimationState::SHOOTJUMP;
		else // Just jumping
			newState = AnimationState::JUMP;
	}

	if (newState != m_AnimationState)
	{
		m_AnimationState = newState;
		SetDelay(120);
		SetNumColumns(3);
		SetCurrentFrame(1);

		switch (m_AnimationState)
		{
		case INVINCIBLE:
			SetRectangle(jmath::vec4(0, 146, 32, 30));
			SetNumFrames(2);
			SetDelay(20);
			break;

		case STILL:
			SetRectangle(jmath::vec4(0, 38, 32, 30));
			SetNumFrames(1);
			break;

		case RUN:
			SetRectangle(jmath::vec4(0, 6, 32, 30));
			SetNumFrames(3);
			break;

		case JUMP:
			SetRectangle(jmath::vec4(0, 106, 32, 30));
			SetNumFrames(1);
			break;

		case SHOOTSTILL:
			SetRectangle(jmath::vec4(64, 38, 32, 30));
			SetNumFrames(1);
			break;

		case SHOOTRUN:
			SetRectangle(jmath::vec4(0, 70, 32, 30));
			SetNumFrames(3);
			break;

		case SHOOTJUMP:
			SetRectangle(jmath::vec4(32, 102, 32, 30));
			SetNumFrames(1);
			break;
		case SPAWNING:
			SetNumFrames(3);
			SetNumColumns(1);
			SetCurrentFrame(1);
			SetDelay(10000);
			break;
		}
	}
}