Ejemplo n.º 1
0
/**
 * Called when the plugin is started
 */
void CShPluginGame::OnPlayStart(void)
{
	m_fScale = 1.0f;

	m_pBackground = ShEntity2::Find(m_levelIdentifier, CShIdentifier("sprite_tps_background"));
	SH_ASSERT(shNULL != m_pBackground);

	m_pPlayer = ShEntity2::Find(m_levelIdentifier, CShIdentifier("sprite_tps_player"));
	SH_ASSERT(shNULL != m_pPlayer);
}
/**
 * Called after engine initialization
 */
void OnPostInitialize(void)
{
	CShIdentifier levelIdentifier("character_controller"); // this is the level name

	//
	// Load level
	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(-300.0f,-1500.0f, 1000.0f));
	ShCamera::SetTarget(g_pCamera, CShVector3(0.0f, 0.0f, 100.0f));
	ShCamera::SetFarPlaneDistance(g_pCamera, 3000.0f);

	ShCamera::SetCurrent2D(g_pCamera);
	ShCamera::SetCurrent3D(g_pCamera);

	//
	// Find the character entity
	g_pCharacter = ShEntity3::Find(levelIdentifier, CShIdentifier("entitypc_warrior"));
	SH_ASSERT(shNULL != g_pCharacter);

	//
	// Initialize the character controller with the level, the identifier, the position, the radius, the direction, the speed.
	g_pCharacterController = ShCharacterController::Create(levelIdentifier, CShIdentifier("character_controller_character_001"), ShObject::GetPosition2(g_pCharacter), 50.0, g_direction, g_speed);
	SH_ASSERT(shNULL != g_pCharacterController);

	//
	// Create the moving input (arrow up).
	// Using JustPressed function in order to change each time the button is pressed and not continuously.
	g_pInputUp = ShInput::CreateInputPressed(ShInput::e_input_device_keyboard, ShInput::e_input_device_control_pc_key_up, 0.1f);
	SH_ASSERT(shNULL != g_pInputUp);

	//
	// Create the rotation inputs (right and left).
	// Using InputPressed function in order to change until the button is released.
	g_pInputLeft = ShInput::CreateInputPressed(ShInput::e_input_device_keyboard, ShInput::e_input_device_control_pc_key_left, 0.1f);
	SH_ASSERT(NULL != g_pInputLeft);
	g_pInputRight = ShInput::CreateInputPressed(ShInput::e_input_device_keyboard, ShInput::e_input_device_control_pc_key_right, 0.1f);
	SH_ASSERT(NULL != g_pInputRight);

	// Find tyhe two animations : warrior idle and warrior run.
	pAnimationWarriorStop = ShAnimation::Find(CShIdentifier("pc_warrior.pc_warrior.idle.01"));
	SH_ASSERT(NULL != pAnimationWarriorStop);

	pAnimationWarriorRun = ShAnimation::Find(CShIdentifier("pc_warrior.pc_warrior.run.01"));
	SH_ASSERT(NULL != pAnimationWarriorRun);

	// By default, we play the idle animation, allowing it to loop.
	ShEntity3::AnimationPlay(g_pCharacter, pAnimationWarriorStop, true);
}
Ejemplo n.º 3
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();
}
Ejemplo n.º 4
0
void CShTPSEnemy::Initialize(const CShIdentifier & levelIdentifier, const CShIdentifier & characterIdentifier, CShTPSGun * defaultGun, ShEntity2 * sprite, CShString enemyCharacterControlleridentifier,  ShEntity3 * model)
{
	if(!m_bInitialized)
	{
		m_bInitialized = false;
		if (model != shNULL)
		{
			m_pModel = model;
			m_3d = true;
		}

		m_pSprite = sprite;
		SH_ASSERT(shNULL != m_pSprite);

		if (m_3d)
		{
			ShObject::SetShow(m_pSprite, false);
			ShObject::SetShow(m_pModel, true);
		}
		else
		{
			ShObject::SetShow(m_pSprite, true);
		}

		float radius = CHARACTER_CONTROLLER_RADIUS_2D;

		if(m_3d)
		{
			m_pAnimIdle = ShAnimation::Find(CShIdentifier(ENEMY_ANIM_IDLE));
			SH_ASSERT(shNULL != m_pAnimIdle);
			m_pAnimRun = ShAnimation::Find(CShIdentifier(ENEMY_ANIM_RUN));
			SH_ASSERT(shNULL != m_pAnimRun);
			/*m_pAnimAttack = ShAnimation::Find(CShIdentifier(ENEMY_ANIM_ATTACK));
			SH_ASSERT(shNULL != m_pAnimAttack);*/
			ShEntity3::AnimationPlay(m_pModel, m_pAnimIdle,true);
			radius= CHARACTER_CONTROLLER_RADIUS_3D;
		}

		CShTPSCharacter::Initialize(levelIdentifier,characterIdentifier, 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(enemyCharacterControlleridentifier), m_Position, radius, m_Direction, m_Speed);
		m_pCharacterController = pCharacterController;
		SH_ASSERT(shNULL != m_pCharacterController);

		m_Target = m_Position;
	}
}
Ejemplo n.º 5
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);
}
Ejemplo n.º 6
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++;
}
Ejemplo n.º 7
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);
	}
}
Ejemplo n.º 8
0
/**
 * Constructor
 */
CShPluginGame::CShPluginGame(void)
: CShPlugin(CShIdentifier("TPS"))
, m_levelIdentifier(GID(NULL))
, m_pBackground(shNULL)
, m_pPlayer(shNULL)
, m_fScale(0.0f)
{

}
Ejemplo n.º 9
0
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();
	}
}
Ejemplo n.º 10
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);
}
Ejemplo n.º 11
0
void CShTPSCharacter::SetUninitialized(void)
{
	m_bInitialized = false;
	m_3d = false;
	m_characterIdentifier = CShIdentifier();
}
/**
 * Constructor
 */
CShPluginTranslate::CShPluginTranslate(void)
: CShPlugin(CShIdentifier("translate"))
, m_levelIdentifier(GID(NULL))
{

}
Ejemplo n.º 13
0
#include <ShSDK/ShSDK.h>

#include "Memory.h"

ShEntity2 * g_pWinEntity = shNULL;

#define WIDTH 4
#define HEIGHT 4
#define PIECES (WIDTH*HEIGHT)

SH_STATIC_ASSERT(PIECES%2 == 0, "Nombre de pièces impair");

static CShIdentifier aIdentifier [] = 
{
	CShIdentifier("recto_carre"),
	CShIdentifier("recto_triangle"),
	CShIdentifier("recto_rond"),
	CShIdentifier("recto_croix"),
	CShIdentifier("recto_carre_vert"),
	CShIdentifier("recto_triangle_vert"),
	CShIdentifier("recto_rond_vert"),
	CShIdentifier("recto_croix_vert"),
};

SH_STATIC_ASSERT((sizeof(aIdentifier)/sizeof(aIdentifier[0])) == (PIECES/2), "Identifier manquant");

struct Card
{
	ShEntity2 * pEntityRecto;
	ShEntity2 * pEntityVerso;