Exemplo n.º 1
0
void 	CCustomObject::OnMotionCommandsClick(ButtonValue* value, bool& bModif, bool& bSafe)
{
	ButtonValue* B = dynamic_cast<ButtonValue*>(value); R_ASSERT(B);
	switch(B->btn_num){
    case 0:
    	AnimationCreateKey	(m_MotionParams->t_current);
    break;
    case 1:
    	AnimationDeleteKey	(m_MotionParams->t_current);
    break;
    case 2:{
    	TProperties* P 		= TProperties::CreateModalForm("Scale keys");
        PropItemVec items;
        float from_time=m_MotionParams->min_t,to_time=m_MotionParams->max_t,scale_factor=1.f;
		PHelper().CreateFloat	(items,"From Time", 	&from_time, 	from_time, to_time, 	1.f/30.f, 3);
		PHelper().CreateFloat	(items,"To Time",   	&to_time, 		from_time, to_time, 	1.f/30.f, 3);
		PHelper().CreateFloat	(items,"Scale",			&scale_factor, 	-1000.f, 1000.f);
        P->AssignItems		(items);
        if (mrOk==P->ShowPropertiesModal()){
        	m_Motion->ScaleKeys(from_time,to_time,scale_factor);
        }
        TProperties::DestroyForm(P);
        float mx; m_Motion->GetLength(0,&mx);
        if (m_MotionParams->max_t<mx){ 
        	m_MotionParams->max_t=mx;
			m_Motion->SetParam	(m_MotionParams->min_t*30.f,m_MotionParams->max_t*30.f,30.f);
        }
    }break;
    case 3:{
    	TProperties* P 		= TProperties::CreateModalForm("Normalize keys");
        PropItemVec items;
        float from_time=m_MotionParams->min_t,to_time=m_MotionParams->max_t,speed=5.f;
		PHelper().CreateFloat	(items,"From Time", 	&from_time, 	from_time, to_time, 	1.f/30.f, 3);
		PHelper().CreateFloat	(items,"To Time",   	&to_time, 		from_time, to_time, 	1.f/30.f, 3);
		PHelper().CreateFloat	(items,"Speed (m/sec)", &speed, 		0.f, 100.f);
        P->AssignItems		(items);
        if (mrOk==P->ShowPropertiesModal()){
        	m_Motion->NormalizeKeys(from_time,to_time,speed);
        }
        TProperties::DestroyForm(P);
        float mx; m_Motion->GetLength(0,&mx);
        if (m_MotionParams->max_t<mx){ 
        	m_MotionParams->max_t=mx;
 			m_Motion->SetParam	(m_MotionParams->min_t*30.f,m_MotionParams->max_t*30.f,30.f);
        }
    }break;
    case 4:{
    	float mn,mx;
        m_Motion->GetLength		(&mn,&mx);
        m_MotionParams->min_t	= mn;
        m_MotionParams->max_t	= mx;
        m_Motion->SetParam		(mn*30.f,mx*30.f,30.f);
    }break;
	}
    AnimationUpdate			(m_MotionParams->Frame());
	bModif = true;
}
Exemplo n.º 2
0
void CCustomObject::AnimationOnFrame()
{
	VERIFY (m_Motion);

    if (Selected()&&m_MotionParams->bPlay)
    {
    	AnimationUpdate			(m_MotionParams->Frame());
        m_MotionParams->Update	(Device.fTimeDelta,1.f,true);
    }
}
Exemplo n.º 3
0
void 			EnemyRender( Enemy* enemy )
{
	AnimationUpdate( &(enemy->ship_ani) );

	int pos_x = (int)roundf(enemy->pos.x-16);
	int pos_y = (int)roundf(enemy->pos.y-16);

    TextureRender(	enemy->sprite_texture, enemy->runner->render,
					pos_x, pos_y, &(enemy->ship_ani.rect) );
}
Exemplo n.º 4
0
void 	CCustomObject::OnMotionControlClick(ButtonValue* value, bool& bModif, bool& bSafe)
{
	ButtonValue* B = dynamic_cast<ButtonValue*>(value); R_ASSERT(B);
	switch(B->btn_num){
    case 0:{
		m_MotionParams->t_current 	= m_MotionParams->min_t;
        m_MotionParams->tmp = m_MotionParams->t_current;

		m_MotionParams->bPlay= FALSE;
    }break;
    case 1:{
    	float min_k;
    	float max_k;
		m_Motion->FindNearestKey(m_MotionParams->t_current, min_k, max_k);
        m_MotionParams->t_current	= min_k;
        m_MotionParams->tmp = m_MotionParams->t_current;
		m_MotionParams->bPlay= FALSE;
    }break;
    case 2:{
		m_MotionParams->t_current	-= 1.f/30.f;
        m_MotionParams->tmp = m_MotionParams->t_current;
		m_MotionParams->bPlay= FALSE;
    }break;
    case 3:{
		m_MotionParams->bPlay= TRUE;
    }break;
    case 4:{
		m_MotionParams->bPlay= FALSE;
    }break;
    case 5:{
		m_MotionParams->t_current	+= 1.f/30.f;
        m_MotionParams->tmp = m_MotionParams->t_current;
		m_MotionParams->bPlay= FALSE;
    }break;
    case 6:{
    	float min_k;
    	float max_k;
		m_Motion->FindNearestKey(m_MotionParams->t_current, min_k, max_k);
        m_MotionParams->t_current	= max_k;
        m_MotionParams->tmp = m_MotionParams->t_current;
		m_MotionParams->bPlay= FALSE;
    }break;
    case 7:{
		m_MotionParams->t_current 	= m_MotionParams->max_t;
        m_MotionParams->tmp 		= m_MotionParams->t_current;
		m_MotionParams->bPlay		= FALSE;
    }break;
    }
    AnimationUpdate			(m_MotionParams->Frame());
    ExecCommand 			(COMMAND_UPDATE_PROPERTIES);
    bModif = false;
}
Exemplo n.º 5
0
void 	CCustomObject::OnMotionCurrentFrameChange(PropValue* value)
{
	if (m_MotionParams->t_current<m_MotionParams->min_t)
    	m_MotionParams->min_t = m_MotionParams->t_current;

    else if (m_MotionParams->t_current>m_MotionParams->max_t)
    	m_MotionParams->max_t = m_MotionParams->t_current;

	m_Motion->SetParam	(m_MotionParams->min_t*30.f,m_MotionParams->max_t*30.f,30.f);
    m_MotionParams->bPlay= FALSE;
    AnimationUpdate		(m_MotionParams->Frame());
    ExecCommand			(COMMAND_UPDATE_PROPERTIES);
}
Exemplo n.º 6
0
void FSprite::update(float delta)
{
#ifdef ETC1
    if(previous_opacity_ != (float)getOpacity())
    {
        //Update opacity in shader
        getGLProgramState()->setUniformFloat(opacity_location_, (float)getOpacity()/255.0);
        
        previous_opacity_ = (float) getOpacity();
    }
#endif
    
    AnimationUpdate();
}
void MoveAnimComponent::setAnim(AnimationSetup *anim, bool idle /*=false*/)
{
	//Do nothing if animation is already playing
	if( m_activeAnim == anim )
	{
		m_idle = idle;
		return;
	}

	//Stop last animation if still playing
	if( m_activeAnim != 0x0 )
	{
		GameEvent updateAnim(GameEvent::E_UPDATE_ANIM, &AnimationUpdate(m_activeAnim->JobID, GameEngineAnimParams::Duration, 0, 0), 0);
		if (m_owner->checkEvent(&updateAnim))
		{
			m_owner->executeEvent(&updateAnim);
			m_activeAnim = 0x0;
		}
	}

	//If there is no new animation, we have finished
	if( anim == 0x0 ) 
	{
		if (m_runAnim)
		{
			// Reset last speeds as we have resetted our current anim
			for(int j = 0; j < SPEED_HISTORY_SIZE; j++)
				m_lastSpeeds[j] = 0;
		}

		m_idle = idle;
		return;
	}

	//Play given animation
	GameEvent walk(GameEvent::E_PLAY_ANIM, anim, this);
	if (m_owner->checkEvent(&walk))
	{
		m_owner->executeEvent(&walk);
		m_activeAnim = anim;
		m_idle = idle;

		//Calculate time for playing next random idle animation
		if( idle )
		{
			m_idleTime = GameEngine::getAnimLength( m_owner->worldId(), m_activeAnim->Animation );
			m_idleTime *= 1.0f + (rand() % 4);
		}
	}
}
Exemplo n.º 8
0
void TitleScreenDoLogic(bool* Continue, bool* Error, Uint32 Milliseconds)
{
	(void)Continue;
	(void)Error;
	cpSpaceStep(space.Space, Milliseconds * 0.001);
	for (int i = 0; i < MAX_PLAYERS; i++)
	{
		PlayerUpdate(&players[i], Milliseconds);

		// Check which players have fallen below their start pads
		cpVect pos = cpBodyGetPosition(players[i].Body);
		if (pos.y < BLOCK_Y)
		{
			if (!playersEnabled[i])
			{
				// New player entered
				countdownMs = COUNTDOWN_START_MS;
				SoundPlay(SoundStart, 1.0);
			}
			playersEnabled[i] = true;
		}
	}

	if (countdownMs >= 0)
	{
		const int countdownMsNext = countdownMs - Milliseconds;
		// Play a beep every second
		if ((countdownMs / 1000) > (countdownMsNext / 1000))
		{
			SoundPlay(SoundBeep, 1.0);
		}
		// Start game if counted down to zero
		if (countdownMsNext <= 0)
		{
			TitleScreenEnd();
			ToGame();
			return;
		}
		countdownMs = countdownMsNext;
	}

	Animation *a = Start ? &TitleAnim : &GameOverAnim;
	AnimationUpdate(a, Milliseconds);

	HighScoreDisplayUpdate(&HSD, Milliseconds);
}
Exemplo n.º 9
0
void 	CCustomObject::OnMotionFilesClick(ButtonValue* value, bool& bModif, bool& bSafe)
{
	ButtonValue* B = dynamic_cast<ButtonValue*>(value); R_ASSERT(B);
    bModif = false;
    xr_string fn;
	switch(B->btn_num){
    case 0:
        if(EFS.GetOpenName("$game_anims$", fn)){
            m_Motion->LoadMotion(fn.c_str());
            m_MotionParams->Set	(m_Motion);
            AnimationUpdate		(m_MotionParams->Frame());
			bModif 				= true;
		    ExecCommand			(COMMAND_UPDATE_PROPERTIES);
        }
    break;
    case 1:
        if(EFS.GetSaveName("$game_anims$", fn))
            m_Motion->SaveMotion(fn.c_str());
    break;
	}
}
Exemplo n.º 10
0
void 	CCustomObject::OnMotionCameraViewChange(PropValue* value)
{
	if (m_CO_Flags.is(flCameraView))
	    AnimationUpdate	(m_MotionParams->Frame());
}
Exemplo n.º 11
0
// Return whether to keep the particle
static bool ParticleUpdate(Particle *p, const Uint32 ms)
{
	p->x += p->dx * ms / 1000;
	p->y += p->dy * ms / 1000;
	return !AnimationUpdate(&p->anim, ms);
}
void MoveAnimComponent::changeMoveAnim(const std::string& tag, const std::string& name)
{
	AnimationSetup* animToDelete = 0x0;
	if (tag.compare("moveAnimation") == 0)
	{
		animToDelete = m_moveAnim;
		m_moveAnim = static_cast<AnimationSetup*>(AnimationSetup(name.c_str(), 10, 0, -1.0f, 1.0f, 0.0f).clone());		 
		m_moveAnim->Speed = GameEngine::getAnimSpeed(m_owner->worldId(), m_moveAnim->Animation);
	}
	else if (tag.compare("idleAnimation") == 0)
	{
		if (m_idleAnimCount > 0)
			animToDelete = m_idleAnim[0];
		else m_idleAnimCount++;
		m_idleAnim[0] = static_cast<AnimationSetup*>(AnimationSetup(name.c_str(), 10, 0, -1.0f, 0.0f, 0.0f).clone());
	}
	else if (tag.compare("idleAnimation2") == 0 && m_idleAnimCount > 0)
	{
		if (m_idleAnimCount > 1)
			animToDelete = m_idleAnim[1];
		else m_idleAnimCount++;
		m_idleAnim[1] = static_cast<AnimationSetup*>(AnimationSetup(name.c_str(), 10, 0, -1.0f, 0.0f, 0.0f).clone());
	}
	else if (tag.compare("idleAnimation3") == 0 && m_idleAnimCount > 1)
	{
		if (m_idleAnimCount > 2)
			animToDelete = m_idleAnim[2];
		else m_idleAnimCount++;
		m_idleAnim[2] = static_cast<AnimationSetup*>(AnimationSetup(name.c_str(), 10, 0, -1.0f, 0.0f, 0.0f).clone());
	}
	else if (tag.compare("idleAnimation4") == 0 && m_idleAnimCount > 2)
	{
		if (m_idleAnimCount > 3)
			animToDelete = m_idleAnim[3];
		else m_idleAnimCount++;
		m_idleAnim[3] = static_cast<AnimationSetup*>(AnimationSetup(name.c_str(), 10, 0, -1.0f, 0.0f, 0.0f).clone());
	}
	else if (tag.compare("idleAnimation5") == 0 && m_idleAnimCount > 3)
	{
		if (m_idleAnimCount > 4)
			animToDelete = m_idleAnim[4];
		else m_idleAnimCount++;
		m_idleAnim[4] = static_cast<AnimationSetup*>(AnimationSetup(name.c_str(), 10, 0, -1.0f, 0.0f, 0.0f).clone());
	}
	else if (tag.compare("moveBackAnimation") == 0)
	{
		animToDelete = m_moveBackAnim;
		m_moveBackAnim = static_cast<AnimationSetup*>(AnimationSetup(name.c_str(), 10, 0, -1.0f, 1.0f, 0.0f).clone());		 
		m_moveBackAnim->Speed = GameEngine::getAnimSpeed(m_owner->worldId(), m_moveBackAnim->Animation);
	}
	else if (tag.compare("moveLeftAnimation") == 0)
	{
		animToDelete = m_moveLeftAnim;
		m_moveLeftAnim = static_cast<AnimationSetup*>(AnimationSetup(name.c_str(), 10, 0, -1.0f, 1.0f, 0.0f).clone());		 
		m_moveLeftAnim->Speed = GameEngine::getAnimSpeed(m_owner->worldId(), m_moveLeftAnim->Animation);
	}
	else if (tag.compare("moveRightAnimation") == 0)
	{
		animToDelete = m_moveRightAnim;
		m_moveRightAnim = static_cast<AnimationSetup*>(AnimationSetup(name.c_str(), 10, 0, -1.0f, 1.0f, 0.0f).clone());		 
		m_moveRightAnim->Speed = GameEngine::getAnimSpeed(m_owner->worldId(), m_moveRightAnim->Animation);
	}
	else if (tag.compare("runAnimation") == 0)
	{
		animToDelete = m_runAnim;
		m_runAnim = static_cast<AnimationSetup*>(AnimationSetup(name.c_str(), 10, 0, -1.0f, 1.0f, 0.0f).clone());		 
		m_runAnim->Speed = GameEngine::getAnimSpeed(m_owner->worldId(), m_runAnim->Animation);
	}

	if (m_activeAnim != 0x0 && animToDelete == m_activeAnim)
	{
		// Stop active anim because it will be deleted
		GameEvent updateAnim(GameEvent::E_UPDATE_ANIM, &AnimationUpdate(m_activeAnim->JobID, GameEngineAnimParams::Duration, 0, 0), 0);
		if (m_owner->checkEvent(&updateAnim))
		{
			m_owner->executeEvent(&updateAnim);
			m_activeAnim = 0x0;
		}
	}
	// Reset idle state to reload changed idle animation
	m_idle = false;
	// Now the anim can be safely deleted
	delete animToDelete;
}
void MoveAnimComponent::update(float timeStep)
{
	if (timeStep > Math::Epsilon)
	{
		// Only calc next anim if LOD is low enough
		if (m_lod < m_LODToStopAnim)
		{
			//calculate translated distance and speed in x,z plane
			Vec3f dist = m_newPos - m_oldPos;
			dist.y = 0;
			float speed = m_speed * dist.length() / timeStep;
			static const float pi3rd = Math::Pi / 3;
		
			//if (m_runAnim)
			{
				// Currently the average speed is only used for the run animation
				m_lastSpeeds[m_currentSpeedIndex] = speed;
				m_currentSpeedIndex = (m_currentSpeedIndex + 1) % SPEED_HISTORY_SIZE;
				m_avgSpeed = 0;
				for (int i = 0; i < SPEED_HISTORY_SIZE; i++)
				{
					m_avgSpeed += m_lastSpeeds[i];
				}
				m_avgSpeed /= SPEED_HISTORY_SIZE;
			}

			// Object is moving
			if( m_avgSpeed >= m_moveThreshold && speed > 0)
			{
				AnimationSetup* nextAnim = 0x0;
				// Direction in radiants = angle of walking direction - (y-rotation of the object + rotation offset)
				float direction = atan2( -dist.x, -dist.z ) - (m_rotation.y + m_rotationOffset);
			
				// Normalize direction angle to [-PI, +PI]
				// To get less if cases
				if( direction > Math::Pi ) 
					direction = direction - Math::TwoPi;
				if( direction < -Math::Pi )
					direction = Math::TwoPi + direction;

				// Find the right move animation to play by the moving direction
				// If the exact animation is not specified, play the one for forward moving
				if (m_moveBackAnim != 0x0 && (direction >= 2*pi3rd || direction <= -2*pi3rd))
				{
					nextAnim = m_moveBackAnim;
				}
				else if (m_moveLeftAnim != 0x0 && (direction > pi3rd && direction < 2*pi3rd))
				{
					nextAnim = m_moveLeftAnim;
				}
				else if (m_moveRightAnim != 0x0 && (direction > -2*pi3rd && direction < -pi3rd))
				{
					nextAnim = m_moveRightAnim;
				}
				else if (m_runAnim != 0 && m_avgSpeed > m_runThreshold)
				{
					nextAnim = m_runAnim;
					// Reduce playback speed for run anim
					speed -= m_runThreshold - m_speed;
					//printf("Running speed: %.5f\n", speed);
				}
				else if (m_moveAnim != 0x0)
				{
					nextAnim = m_moveAnim;
				}
				// Set anim or reset everything if none found (nextAnim == 0x0)
				setAnim(nextAnim);
			}
			// Play idle animation if too slow and one is specified
			else if (m_idleAnimCount > 0)
			{
				// We weren't in idle state before or the animation time for the idle anim has passed
				if(!m_idle || m_idleTime < 0)
				{
					if(!m_randSeed)
					{
						// rand hasn't been seeded yet
						srand( (unsigned int) (100000 / timeStep) );
						m_randSeed = true;
					}
					// Choose and set new random idle animation
					int i = rand() % m_idleAnimCount; 
					setAnim( m_idleAnim[i], true );
				}
				else
				{
					// The current idle animation is still playing
					// So decrement timer
					m_idleTime -= timeStep;
				}
			}
			// We don't have an anim to play, so stop any currently playing 
			else
			{
				setAnim(0x0);
			}

			//update animation speed (only none idle animations)
			if( m_activeAnim != 0x0 && !m_idle)
			{
				GameEvent updateAnim(GameEvent::E_UPDATE_ANIM, &AnimationUpdate(m_activeAnim->JobID, GameEngineAnimParams::Speed, m_activeAnim->Speed * m_avgSpeed, 0), 0);
				if (m_owner->checkEvent(&updateAnim))
					m_owner->executeEvent(&updateAnim);
			}
		}
		// The LOD is above the critical value, so stop all current anims
		else
			setAnim(0x0);
	
		//update position
		m_oldPos = m_newPos;
	}
}