/*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); }
/** * 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); }
/** * 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(); }
/*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); }
/*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++; }
/*virtual*/ void ParticleEmitter::ResetParticle(int index) { float angle = (std::rand() % 360) * 3.14f / 180.f; float speed = (std::rand() % (int)(m_maxSpeed/2)) + (m_maxSpeed/2); m_particles[index].velocity = CShVector3(cos(angle) * speed, sin(angle) * speed, 0.0f); m_particles[index].currentLife = CShRandomValue::GetInstance()->GetNextFloat(0.0f, m_maxLifetime); ShEntity2::SetPosition(m_particles[index].entity, m_emitter); ShEntity2::SetShow(m_particles[index].entity, m_enabled); }
/** * Called after the engine updates itself */ void CShPluginTranslate::OnPostUpdate(float dt) { // Loop through every the array of entities to rotate int entityCount = m_aTranslatingEntities.GetCount(); for (int i = 0; i < entityCount; ++i) { STranslatingEntity & elmt = m_aTranslatingEntities[i]; ShEntity2::Translate(elmt.entity, CShVector3(0.0f, elmt.velocity * dt, 0.0f)); } }
/** * Called after engine initialization */ void Game::OnPostInitialize(void) { instance(); instance_->m_registeredAction.action = e_action_none; // Create the Camera ShCamera * pCamera = ShCamera::Create(GID(global), GID(camera), false); SH_ASSERT(shNULL != pCamera); ShCamera::SetPosition(pCamera, CShVector3(0.0f, 0.0f, 100.0f)); ShCamera::SetTarget(pCamera, CShVector3(0.0f, 0.0f, 0.0f)); ShCamera::SetUp(pCamera, CShVector3(0.0f, 1.0f, 0.0f)); ShCamera::SetProjectionOrtho(pCamera); ShCamera::SetNearPlaneDistance(pCamera, 0.0f); ShCamera::SetFarPlaneDistance(pCamera, 200.0f); instance_->m_fRescaleRatio = ShDisplay::GetHeight() / (float)ShDisplay::GetWidth(); ShCamera::SetViewport(pCamera, DISPLAY_WIDTH, DISPLAY_WIDTH * instance_->m_fRescaleRatio); ShCamera::SetCurrent2D(pCamera); // Initialize Sound instance_->m_sound.Initialize(); // Initialize Transition instance_->m_transition.Initialize(); // Initialize states instance_->m_stateMainMenu.Initialize(); instance_->m_stateCredits.Initialize(); instance_->m_stateGame.Initialize(); instance_->Push(MENU); }
/*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); } }
/*virtual*/ void ParticleEmitter::Update(float deltaTimeInSeconds) { int arraySize = m_particles.GetCount(); for(int i = 0; i < arraySize; ++i) { Particle& p = m_particles[i]; p.currentLife -= deltaTimeInSeconds; if (p.currentLife <= 0.0f) { ResetParticle(i); } ShEntity2::Translate( p.entity, CShVector3( p.velocity.m_x * deltaTimeInSeconds, p.velocity.m_y * deltaTimeInSeconds, 0.0f ) ); float ratio = p.currentLife / m_maxLifetime; ShEntity2::SetAlpha(p.entity, ratio); } }
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(); } }
/*virtual*/ void GameStateIntro::OnTouchMove(int iTouch, float positionX, float positionY) { ShEntity2::SetPosition(m_cursor, CShVector3(positionX, positionY, 200.0f)); }
/*virtual*/ void ParticleEmitter::SetEmitter(CShVector3 position) { m_emitter = CShVector3(position.m_x, position.m_y, m_emitter.m_z); }