Beispiel #1
0
/*virtual*/ void GameStateIntro::OnInitialize()
{
	ShLevel::Load(m_levelIdentifier);
	GameStateManager::SetMultiresolution(m_levelIdentifier);
	nextBtn = ShEntity2::Find(m_levelIdentifier, CShIdentifier("next"));

	for(int i = 0; i < 2; ++i)
	{
		CShString id;
		if(i < 10)
		{
			 id = CShString("ecran0") + CShString::FromInt(i+1);
		}
		else
		{
			 id = CShString("ecran")  + CShString::FromInt(i+1);
		}

		ShEntity2* fond = ShEntity2::Find(m_levelIdentifier, CShIdentifier(id));
		SH_ASSERT(NULL != fond);
		ecrans.Add(fond);
	}
	m_cursor = ShEntity2::Create(
		m_levelIdentifier,
		CShIdentifier("cursor"),
		CShIdentifier("layer_default"),
		CShIdentifier("ggj"),
		CShIdentifier("cursor"),
		CShVector3(),
		CShEulerAngles(),
		CShVector3(1.0f, 1.0f, 1.0f));
	ShEntity2::SetPivotTopLeft(m_cursor);
}
void CShTPSEnemy::Update(float dt)
{
	if(m_pGun->GetCoolDown() < m_pGun->GetFireRate())
	{
		m_pGun->AddToCoolDown(dt);
	}

	if(HasReachedTarget()) // If the enemy isn't on its target's location, he will go to it, else he will stay
	{
		m_CurrentState = e_state_idle;
	}
	else
	{
		m_CurrentState = e_state_attack;
		float length = CShVector2(m_Target - m_Position).GetLength();
		m_Direction = CShVector2((m_Target.m_x - m_Position.m_x)/length , (m_Target.m_y - m_Position.m_y)/length);
		ShCharacterController::SetWalkDirection(m_pCharacterController, m_Direction);
		ShCharacterController::SetWalkSpeed(m_pCharacterController, m_Speed);
	}

	switch(m_CurrentState)
	{
		case e_state_idle:
			ShCharacterController::SetWalkSpeed(m_pCharacterController, 0.0f);
			if(m_3d)
			{
				ShEntity3::AnimationPlay(m_pModel, m_pAnimIdle,true);
			}
			break;
		case e_state_attack:

			m_Position = ShCharacterController::GetPosition(m_pCharacterController);
			ShObject::SetPositionX(m_pSprite,m_Position.m_x);
			ShObject::SetPositionY(m_pSprite,m_Position.m_y);
			if(m_3d)
			{
				ShEntity3::AnimationPlay(m_pModel, m_pAnimRun,true); //TODO changer animation en attaque si ça marche un jour
				ShEntity3::SetRotation(m_pModel, CShEulerAngles(0.0f, 0.0f, std::atan2(m_Direction.m_y,m_Direction.m_x ) + 1.5f )); // 1.5f : valeur piffée pour que les enemis regardent bien le joueur
				ShObject::SetPositionX(m_pModel,m_Position.m_x);
				ShObject::SetPositionY(m_pModel,m_Position.m_y);
			}
			ShEntity2::SetRotation(m_pSprite, CShEulerAngles(0.0f, 0.0f, std::atan2(m_Direction.m_y,m_Direction.m_x ) - 1.5f )); // 1.5f : valeur piffée pour que les enemis regardent bien le joueur
			//ShEntity2::SetRotation(m_pSprite, CShEulerAngles(0.0f, 0.0f, shAcosf(m_Direction.m_x/m_Direction.m_y)));
			break;
	}
	ShCharacterController::Update(m_pCharacterController);
}
/**
 * Called on each frame, after the engine update
 */
void OnPostUpdate(float deltaTimeInMs)
{
	//
	// Change the walk speed/direction
	if (ShInput::GetValue(g_pInputUp) > 0.2f)
	{
		ShEntity3::AnimationPlay(g_pCharacter, pAnimationWarriorRun, true);
		g_speed = 30.0f;
	}
	else
	{
		ShEntity3::AnimationPlay(g_pCharacter, pAnimationWarriorStop, true);
		g_speed = 0.0f;
	}
	
	if (ShInput::GetValue(g_pInputLeft) > 0.2f)
	{
		g_direction.Rotate(0.05f);
		ShEntity3::Rotate(g_pCharacter, CShEulerAngles(0, 0, 0.05f));
	}
	
	if (ShInput::GetValue(g_pInputRight) > 0.2f)
	{
		g_direction.Rotate(-0.05f);
		ShEntity3::Rotate(g_pCharacter, CShEulerAngles(0, 0, -0.05f));
	}
	
	ShCharacterController::SetWalkSpeed(g_pCharacterController, g_speed);
	ShCharacterController::SetWalkDirection(g_pCharacterController, g_direction);

	//
	// Update the character controller to change the position
	ShCharacterController::Update(g_pCharacterController);

	//
	// Change the position of the character according to the position of the character controller
	CShVector2 character_position = ShCharacterController::GetPosition(g_pCharacterController);
	ShEntity3::SetPositionX(g_pCharacter, character_position.m_x);
	ShEntity3::SetPositionY(g_pCharacter, character_position.m_y);
}
Beispiel #4
0
/*virtual*/ void GameStateCredit::OnInitialize()
{
	ShLevel::Load(m_levelIdentifier);
	GameStateManager::SetMultiresolution(m_levelIdentifier);
	m_cursor = ShEntity2::Create(
		m_levelIdentifier,
		CShIdentifier("cursor"),
		CShIdentifier("layer_default"),
		CShIdentifier("ggj"),
		CShIdentifier("cursor"),
		CShVector3(),
		CShEulerAngles(),
		CShVector3(1.0f, 1.0f, 1.0f));
	ShEntity2::SetPivotTopLeft(m_cursor);
}
Beispiel #5
0
/*explicit*/ Animation::Animation (const CShIdentifier& levelId, const CShString& fileName, const bool& loopable, int nbImages, int fps, const CShVector3& position)
	: m_aImages()
	, m_nbImages(nbImages)
	, m_currentImage(1)
	, m_levelIdentifier(levelId)
	, m_fileName(fileName)
	, m_fAnimSpeed(1.f/fps)
	, m_bLoop(loopable)
	, m_Pos(position)
	, m_Rot()
	, m_Sca(CShVector3(1.0f, 1.0f, 1.0f))
	, m_Piv(CShVector2(0.5f, 0.5f))
	, m_elapsedTime(0.0f)
	, m_currentState(STOP)
{
	//
	// Load the images
	ShEntity2* currentEntity = NULL;
	int nbLoop = 1;
	CShIdentifier entityIdentifier;
	CShIdentifier levelEntityIdentifier;

	while(nbLoop <= nbImages)
	{

		CShString id = fileName + "_" + ((nbLoop<100)?CShString("0") + ((nbLoop<10)?CShString("0"):CShString("")):CShString("")) + CShString::FromInt(nbLoop);
		entityIdentifier = CShIdentifier(id);
		levelEntityIdentifier = CShIdentifier(CShString::FromInt(s_NumberAnim) + id);

		currentEntity = ShEntity2::Create(m_levelIdentifier
			, levelEntityIdentifier
			, CShIdentifier("layer_default")
			, CShIdentifier("ggj")
			, entityIdentifier
			, m_Pos
			, CShEulerAngles()
			, CShVector3(1.0f, 1.0f, 1.0f)
		);
		ShEntity2::SetShow(currentEntity, false);

		nbLoop++;
		m_aImages.Add(currentEntity);
	}
	s_NumberAnim++;
}
Beispiel #6
0
/*explicit*/ ParticleEmitter::ParticleEmitter(
	const CShIdentifier& poolIdentifier,
	const CShString& name, 
	int count, 
	const CShIdentifier& particlePool, 
	const CShIdentifier& particleName, 
	const CShVector3& XYscaleAndZBuffer
)
: m_maxLifetime(3.0f)
, m_emitter(0.0f, 0.0f, XYscaleAndZBuffer.m_z)
, m_maxSpeed(50.0f)
, m_enabled(false)
{
	int zeroCount = (count==0)?0:(int)log10((float)count);
	for(int i = 0; i < count; ++i)
	{
		Particle p;
		CShString frameName = name + CShString("_");
		int currentCount = (i==0)?0:(int)log10((float)i);
		for(int j = currentCount; j < zeroCount; ++j)
		{
			frameName += CShString("0");
		}
		frameName += CShString::FromInt((int)i);
		p.entity = ShEntity2::Create(
			poolIdentifier, 
			CShIdentifier(frameName), 
			CShIdentifier("layer_default"), 
			particlePool,
			particleName,
			m_emitter, 
			CShEulerAngles(0.0f, 0.0f, CShRandomValue::GetInstance()->GetNextFloat(0.0f, M_PI)), 
			CShVector3(1.0f, 1.0f, 1.0f)
		);
		ShEntity2::SetScale(
			p.entity,
			XYscaleAndZBuffer.m_x / ShEntity2::GetWidth(p.entity), 
			XYscaleAndZBuffer.m_y / ShEntity2::GetHeight(p.entity),
			1.0f
		);
		ShEntity2::SetShow(p.entity, false);
		ShEntity2::SetBlendAlphaAdd(p.entity);
		m_particles.Add(p);
	}
}
void CShTPSPlayer::Initialize(const CShIdentifier & levelIdentifier, CShTPSGun * defaultGun)
{
	if (!m_bInitialized)
	{
		m_bInitialized  = true;

		// Load a sprite in 2D in the Sprite attribute
		m_pSprite = shNULL;
		m_pSprite = ShEntity2::Find(levelIdentifier, CShIdentifier(PLAYER_SPRITE_NAME));
		float radius = CHARACTER_CONTROLLER_RADIUS_2D; // radius for the character controller
	
		if (shNULL == m_pSprite) // if no player sprite is on the map, one is created for 3D, to manage collision between invisible 2D stuff
		{
			m_pSprite = ShEntity2::Create(levelIdentifier, CShIdentifier("player_sprite_forced_2D"), GID(layer_default), CShIdentifier("tps"), CShIdentifier("player"), CShVector3(0.0f,0.0f,1.0f), CShEulerAngles(0.0f, 0.0f, 0.0f), CShVector3(1.0f, 1.0f, 1.0f));

		}

		SH_ASSERT(shNULL != m_pSprite);
		m_pModel = shNULL;
		m_pModel = ShEntity3::Find(levelIdentifier, CShIdentifier(PLAYER_SPRITE_NAME));
		if(shNULL != m_pModel)
		{
			m_3d = true;
			m_pAnimIdle = ShAnimation::Find(CShIdentifier(PLAYER_ANIM_IDLE));
			SH_ASSERT(shNULL != m_pAnimIdle);
			m_pAnimRun = ShAnimation::Find(CShIdentifier(PLAYER_ANIM_RUN));
			SH_ASSERT(shNULL != m_pAnimRun);
			/*m_pAnimAttack = ShAnimation::Find(CShIdentifier(PLAYER_ANIM_ATTACK));
			SH_ASSERT(shNULL != m_pAnimAttack);*/
			ShEntity3::AnimationPlay(m_pModel, m_pAnimIdle,true);
			radius= CHARACTER_CONTROLLER_RADIUS_3D;	
		}
		else
		{
			m_3d = false;
		}

		if(m_3d)
		{
			ShObject::SetShow(m_pSprite, false);
			ShObject::SetShow(m_pModel, true);
		}
		else
		{
			ShObject::SetShow(m_pSprite, true);
		}
		CShTPSCharacter::Initialize(levelIdentifier, CShIdentifier(PLAYER_SPRITE_NAME), defaultGun);

		// Initialize the character controller with the level, the identifier, the position, the radius, the direction, the speed.
		ShCharacterController *	pCharacterController = shNULL;
		pCharacterController = ShCharacterController::Create(levelIdentifier, CShIdentifier("character_controller_character_001"), m_Position, radius, m_Direction, m_Speed);
		m_pCharacterController = pCharacterController;
		SH_ASSERT(shNULL != m_pCharacterController);
	}
	else
	{
		Spawn();
	}
}
Beispiel #8
0
/**
 * Called after engine initialization
 */
void OnPostInitialize(void)
{
	CShIdentifier levelIdentifier("memory");

	bool loaded = ShLevel::Load(levelIdentifier);
	SH_ASSERT(loaded);

	//
	// Create Camera
	g_pCamera = ShCamera::Create(GID(global), GID(camera_free), false);
	SH_ASSERT(NULL != g_pCamera);
	ShCamera::SetPosition(g_pCamera, CShVector3(0, 0.0f, 1000.0f));
	ShCamera::SetTarget(g_pCamera, CShVector3(0.0f, 0.0f, 0.0f));
	ShCamera::SetFarPlaneDistance(g_pCamera, 3000.0f);
	ShCamera::SetViewport(g_pCamera, 256*WIDTH, 256*HEIGHT);
	ShCamera::SetProjectionOrtho(g_pCamera);

	ShCamera::SetCurrent2D(g_pCamera);

	ratio = CShVector2((256*WIDTH)/(float)ShDisplay::GetWidth(), (256*HEIGHT)/(float)ShDisplay::GetHeight());

	g_pWinEntity = ShEntity2::Find(levelIdentifier, CShIdentifier("sprite_memory_win_001"));
	SH_ASSERT(shNULL != g_pWinEntity);
	ShEntity2::SetShow(g_pWinEntity, false);

	//
	// Create all sprites
	for (int i = 0; i < HEIGHT; ++i)
	{
		for (int j = 0; j < WIDTH; ++j)
		{
			CShVector3 pos;
			pos.m_x = (256.0f * j) - (128.0f + (((WIDTH/2)-1) * 256.0f));
			pos.m_y = (256.0f * i) - (128.0f + (((HEIGHT/2)-1) * 256.0f));

			int c = i*WIDTH+j;

			aCards[c].pEntityRecto = ShEntity2::Create(levelIdentifier, CShIdentifier(), GID(layer_default), CShIdentifier("memory"), aIdentifier[c/2], pos, CShEulerAngles(0.0f, 0.0f, 0.0f), CShVector3(1.0f, 1.0f, 1.0f));
			SH_ASSERT(shNULL != aCards[c].pEntityRecto);

			aCards[c].pEntityVerso = ShEntity2::Create(levelIdentifier, CShIdentifier(), GID(layer_default), CShIdentifier("memory"), CShIdentifier("verso"), pos, CShEulerAngles(0.0f, 0.0f, 0.0f), CShVector3(1.0f, 1.0f, 1.0f));
			SH_ASSERT(shNULL != aCards[c].pEntityVerso);

			aCards[c].type = c/2;
		}
	}

	for (int i = 0; i < PIECES; ++i)
	{
		ShEntity2::SetShow(aCards[i].pEntityRecto, false);
	}

	shuffle();
}