Example #1
0
////////////////////////////////////////
//		PUBLIC UTILITY FUNCTIONS
////////////////////////////////////////
// Gets the current frame in the animation
// and moves to the next one in order.
RECT CAnimation::GetFrame()
{
	SetTimeWaited(GetTimeWaited() + GAME->GetTimer().GetDeltaTime());

	RECT tRect;
	
	tRect.left = GetCurrentFrame() * GetFrameWidth();
	tRect.top = 0;
	tRect.right = tRect.left + GetFrameWidth();
	tRect.bottom = tRect.top + GetFrameHeight();	
	
				
	if(GetTimeWaited() > GetTimePerFrame() && !GetStatic())
	{	
		SetTimeWaited(0.0f);
		SetCurrentFrame(GetCurrentFrame() + 1);

		if(GetCurrentFrame() > GetFrameCount())
		{
			if(GetLooping())
				ResetAnimation();	
			else
			{
				SetCurrentFrame(GetFrameCount());
				SetStatic(true);
			}
		}
		
	}

	return tRect;
}
void FaerieAnimationsDelegate::CloneCurrentFrame() {
	assert(_currentAnimation != NULL);
	_currentAnimation->CloneFrame(_currentFrameNumber);
	int currentFrameNumber = _currentFrameNumber + 1;
	emit SetFramesList(GetFramesList());
	emit SetCurrentFrame(currentFrameNumber);
}
void FaerieAnimationsDelegate::InitCurrentAnimationView() {
	assert(_currentAnimation != NULL);
	emit InitAnimationTime(double(_currentAnimation->GetTime()));
	emit SetFramesList(GetFramesList());
	emit SetCurrentFrame(0);
	_currentFrameNumber = 0;
}
void FaerieAnimationsDelegate::DeleteCurrentFrame() {
	assert(_currentAnimation != NULL);
	_currentAnimation->DeleteFrame(_currentFrameNumber);
	int currentFrameNumber = _currentFrameNumber;
	QStringList frames = GetFramesList();
	if (currentFrameNumber >= frames.size()) {
		currentFrameNumber = frames.size() - 1;
	}
	emit SetFramesList(frames);
	emit SetCurrentFrame(currentFrameNumber);
}
Example #5
0
 bool CameraObject::Import( QString & directory, QProgressDialog * progressDlg )
 {
     bool success = true;

     // check that dir exists and is readable
     QFileInfo dirInfo( directory );
     Q_ASSERT( dirInfo.exists() );
     Q_ASSERT( dirInfo.isReadable() );

     QString objectName = dirInfo.baseName();
     this->SetName( objectName );

     // read intrinsic params
     CameraIntrinsicParams params;
     SerializerReader reader;
     QString intrinsicParamsFilename = QString("%1/intrinsic_params.xml").arg( directory );
     QFileInfo intrinsicParamsInfo( intrinsicParamsFilename );
     if( !intrinsicParamsInfo.exists() || !intrinsicParamsInfo.isReadable() )
         Application::GetInstance().Warning( "Camera import", "Intrinsic calibration params (intrinsic_params.xml) is missing or unreadable. Intrinsic camera params will be the default ones." );
     else
     {
        reader.SetFilename( intrinsicParamsFilename.toUtf8().data() );
        reader.Start();
        ::Serialize( &reader, "IntrinsicParams", params );
        reader.Finish();
     }
     SetIntrinsicParams( params );

     // Read calibration matrix
     QString calMatrixFilename = QString("%1/calibMat.xfm").arg( directory );
     QFileInfo calMatrixInfo( calMatrixFilename );
     vtkMatrix4x4 * calMatrix = vtkMatrix4x4::New();
     if( !calMatrixInfo.exists() || !calMatrixInfo.isReadable() )
         Application::GetInstance().Warning( "Camera import", "Calibration matrix file (calibMat.xfm) is missing or unreadable. Calibration matrix will be identity." );
     else
        TrackedVideoBuffer::ReadMatrix( calMatrixFilename, calMatrix );
     SetCalibrationMatrix( calMatrix );
     calMatrix->Delete();

     m_videoBuffer->Import( directory, progressDlg );
     SetCurrentFrame( 0 );
     m_videoInputSwitch->Update();  // Without this update, image is not displayed, but it shouldn't be needed

     // Update representation in view
     UpdateGeometricRepresentation();

     return success;
 }
Example #6
0
///////////////////////////////////////////////
//  CONSTRUCTOR / DECONSTRUCT / OP OVERLOADS
///////////////////////////////////////////////
CAnimation::CAnimation(int nImageID,int nImageWidth,int nImageHeight, int nFrameWidth,
				int nFrameHeight,int nFrames,int nCurrent,float fTimePerFrame,bool bLooping,bool bStatic)
{
	SetImageID(nImageID);
	SetImageWidth(nImageWidth);
	SetImageHeight(nImageHeight);
	SetFrameWidth(nFrameWidth);
	SetFrameHeight(nFrameHeight);
	// Because framecount starts at 0
	SetFrameCount(nFrames - 1);
	SetCurrentFrame(nCurrent);
	SetLooping(bLooping);
	SetStatic(bStatic);
	SetTimePerFrame(fTimePerFrame);
	SetTimeWaited(0.0f);
}
Example #7
0
void UpdateAnimation (Animation * animation)
{
	animation->t += animation->stepSize;
	// Increment animation's t field by animation's stepSize field's value

	if (animation->t > (float) 1.0)
	{
		animation->t = 0.0;	// Reset parameter
	}
	// Check whether parameter has reached end of its path

	SetCurrentFrame (animation, (animation->states + animation->curState)->curFrame + animation->frameRate);
	// Update the current frame and active image

	switch (animation->type)	// Get the animation's path type
	{
	case kStationary:			// Stationary case
		break;	// Break out of switch statement

	case kLinear:				// Linear case
		animation->globalLoc = PointPlusVector2 (animation->path.vector.tail, ScaleVector2 (animation->path.vector, animation->t));
		// Calculate animation's position along a line

		break;	// Break out of switch statement

	case kBezier:				// Bézier case
		animation->globalLoc = Bezier2 (animation->path, animation->t);
		// Calculate animation's position along a Bézier curve

		break;	// Break out of switch statement

	default:
		NORET_MESSAGE("Unsupported type: UpdateAnimation failed","1");
		// Return failure
	}
}
Example #8
0
////////////////////////////////////////
//		PRIVATE UTILITY FUNCTIONS
////////////////////////////////////////
void CAnimation::ResetAnimation()
{
	SetCurrentFrame(0);
	SetTimeWaited(0.0f);
	SetStatic(false);
}
Example #9
0
// 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;
		}
	}
}
Example #10
0
// Animation that plays on death - twelve circles with oscillating radiuses that move away from the player 
void Player::HandleDeath(const jutil::GameTime& timespan)
{
	// If we've just entered, put all the sprites in place
	if (m_TimerDeath.ElapsedMilliseconds() == 0)
	{
		for (int i = 0; i < m_DeathSprites.size(); ++i)
			m_DeathSprites[i].SetPosition(GetPosition());
	}
	else // Otherwise, we're under way - animate
	{
		// Oscillate the radius
		if (m_DeathSpriteFlickerCounter > 4)
			m_DeathSpriteFlicker = false;
		else if (m_DeathSpriteFlickerCounter < 1)
			m_DeathSpriteFlicker = true;

		if (m_DeathSpriteFlicker)
			m_DeathSpriteFlickerCounter++;
		else
			m_DeathSpriteFlickerCounter--;

		for (int i = 0; i < m_DeathSprites.size(); ++i)
			m_DeathSprites[i].SetCurrentFrame(m_DeathSpriteFlickerCounter);

		// Move all the circles outwards in the right directions
		float d = timespan.GetDeltaTime();
		for (int i = 0; i < 2; i++, d = -d)
			m_DeathSprites[i].Move(jmath::vec2(d, d));

		for (int i = 2; i < 4; i++, d = -d)
			m_DeathSprites[i].Move(jmath::vec2(-d, d));

		for (int i = 4; i < 6; ++i, d = -d)
			m_DeathSprites[i].MoveX(d*1.6f);

		for (int i = 6; i < 8; ++i, d = -d)
			m_DeathSprites[i].MoveY(d*1.6f);

		for (int i = 8; i < 10; ++i, d = -d)
			m_DeathSprites[i].MoveX(d*0.4f);

		for (int i = 10; i < 12; ++i, d = -d)
			m_DeathSprites[i].MoveY(d*0.4f);
	}


	m_TimerDeath += timespan;
	m_TimerInvincibility.SetTime(JTime::Milliseconds(INVINCIBILITY_TIME)); 

	// If we're done dying, reset everything
	if (m_TimerDeath.ElapsedMilliseconds() > 5850) // 5300
	{
		m_TimerDeath.SetTime(0);
		m_Health = 28;
	}
	// If we're done dying, get ready to spawn back in
	else if (m_TimerDeath.ElapsedMilliseconds() > 5400)
	{
		float n = jmath::Normalise(5400.f, 5800.f, (float)m_TimerDeath.ElapsedMilliseconds());

		if (n > 0.9f)
		{
			if (GetCurrentFrame() == 1)
				SetCurrentFrame(2);
			else
				SetCurrentFrame(3);
		}
		else
			SetRectangle(jmath::vec4(120, 8, 24, 32));
		SetAnimationFrame();
		if (n > 1.f)
			n = 1.f;
		jmath::vec2 r = m_RespawnPos;
		r.y = jmath::Lerp(m_RespawnPos.y - 240, m_RespawnPos.y - 5, n);
		SetPosition(r);
	}
	// If we've played the animation, set player to spawn pos
	else if (m_Health != INT_MIN && m_TimerDeath.ElapsedMilliseconds() > 2300)
	{

		jmath::vec2 r = m_RespawnPos;
		m_Health = INT_MIN;
		r.y -= 240;
		SetPosition(r);
		SetAnimationFrame();
	}
}