int Platform::Update () { if (isAlive ()) { GameObject::Update (); //Performing boundry checking if (x > g_Game.GetScreen_W () - boundX) x = g_Game.GetScreen_W () - boundX; else if (x < boundX) x = boundX; //Updating of animation exists if (animation) animation->Animate (); } if (!GetLives ()) { PlayingState* playing_state = dynamic_cast<PlayingState*> (g_GamePtr->GetState ()); playing_state->SetChangingStateFlag (true); char buffer[BUFSIZ]; ACE_OS::memset (&buffer, 0, sizeof (buffer)); char* username = buffer; #ifdef _MSC_VER DWORD buffer_size = sizeof (buffer); if (!GetUserName (buffer, &buffer_size)) ACE_DEBUG ((LM_ERROR, ACE_TEXT ("failed to GetUserName: %d, continuing\n"), GetLastError ())); #else username = ACE_OS::getenv ("USER"); #endif playing_state->PushScore (username, GetScore ()); } return 0; }
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Summary: The function that HURTS the player! His health goes down and then it checks if he's still alive. If so, starts the death process; if not, does got damaged stuff. Parameters: [in] _damage - the amount of damage to receive. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void CPlayer::TakeDamage( int _damage ) { // if he's currently not invulnerable. if( GetInvulnerableTime() <= 0.0f ) { if( this->GetHealth() > 0 ) { this->SetHealth( this->GetHealth() - _damage ); if( this->GetHealth() < 0 ) this->SetHealth( 0 ); // AudioSystemWwise::GetInstance()->PostEvent(AK::EVENTS::PLAY_DX_2D_UNDERATTACK); //HAX //AUTH: Ryan //Desc: feedback for player hurt, replace with animation / effect later //Date: ???? m_Hurt = true; GetAnimationManager()->SwitchAnimation(CAssetManager::GetInstance()->GetAnimation(ET_PLAYER, PL_HURT), 0.2f); //this->GetRenderNode().hTextureDiffuse = CAssetManager::GetInstance()->GetSmallEnemyData(RED).m_DiffuseHandle; } else if( this->GetHealth() <= 0 ) GetAnimationManager()->SwitchAnimation(CAssetManager::GetInstance()->GetAnimation(ET_PLAYER, PL_DEATH), 0.1f); std::cout << "Player Health: " << this->GetHealth() << "/" << MAX_HP_PLAYER << std::endl; // TODO:: Animations if( this->GetHealth() != 0 ) { // TODO:: Play damage sound // TODO:: Play damage animation // TODO:: Use damage effect } else { // TODO:: Play death sound // TODO:: Play Death animation // TODO:: Use Death effect // TODO:: Activate GAME OVER process. if( GetLives() > 1 ) { m_DeathTimer = (float)(CAssetManager::GetInstance()->GetAnimation(ET_PLAYER, PL_DEATH)->GetDuration() - 0.6f); //CMessageSystem::GetInstance()->SendMessage(new CCreateVFXMessage(GEO_EMITTER_BLOOD_POOL,this,0.0f,0.0f,0.0f)); } else m_DeathTimer = (float)(CAssetManager::GetInstance()->GetAnimation(ET_PLAYER, PL_LOSE)->GetDuration() - 0.6f); std::cout << "PLAYER DYING!" << std::endl; // AudioSystemWwise::GetInstance()->PostEvent(AK::EVENTS::PLAY_DX_3D_DEATH); } this->SetInvulnerableTime(1.0f); } }
int Platform::Update(){ if(isAlive()){ GameObject::Update(); //Performing boundry checking if( x > g_Game.GetScreen_W() - boundX) x = g_Game.GetScreen_W() - boundX; else if ( x < boundX) x = boundX ; //Updating of animation exists if(animation) animation->Animate(); } if(!GetLives()){ PlayingState* playing_state = dynamic_cast<PlayingState*>(g_GamePtr->GetState()); playing_state->SetChangingStateFlag(true); playing_state->PushScore(getenv("USER"), GetScore()); } return 0; }
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Summary: Updates the player! Parameters: [in] _elapsedTime - the time passed since the last frame. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ bool CPlayer::Update( float _elapsedTime ) { static bool once = false; // Timer for death animation. if( m_DeathTimer > 0.0f ) { m_DeathTimer -= _elapsedTime; m_StopAnimSwitching = true; if( GetLives() <= 1 ) { if( !once ) { GetAnimationManager()->SwitchAnimation(CAssetManager::GetInstance()->GetAnimation(ET_PLAYER, PL_LOSE), 0.5f); AudioSystemWwise::GetInstance()->PostEvent(AK::EVENTS::STOP_MX_TRACK_04); AudioSystemWwise::GetInstance()->PostEvent(AK::EVENTS::STOP_MX_TRACK_03); AudioSystemWwise::GetInstance()->PostEvent(AK::EVENTS::STOP_MX_TRACK_02); AudioSystemWwise::GetInstance()->PostEvent(AK::EVENTS::STOP_MX_TRACK_01); AudioSystemWwise::GetInstance()->PostEvent(AK::EVENTS::PLAY_MX_TRACK_02); SetLives(0); once = true; } } else { GetAnimationManager()->SwitchAnimation(CAssetManager::GetInstance()->GetAnimation(ET_PLAYER, PL_DEATH), 0.3f); } if(m_DeathTimer <= 0.0f) { SetIsDying(true); SetKillScreen(true); once = false; if( GetLives() == 0 ) { m_DeathTimer = 0.0f; return true; } m_ResetWave = true; m_DeathTimer = 0.0f; } GetAnimationManager()->Update(_elapsedTime, &GetRenderNode()); return true; } if(this->GetHealth() <= 25) { m_LowHPTimer += _elapsedTime; if(m_LowHPTimer > 1.5f) { m_LowHPTimer = 0.0f; // AudioSystemWwise::GetInstance()->PostEvent(AK::EVENTS::PLAY_FX_2D_BEEP); } } if(this->m_HealthPickup >= 0.0f) { static bool healthpickupcolor = false; if(healthpickupcolor) { //GetRenderNode().hTextureDiffuse = CAssetManager::GetInstance()->GetObjData(ET_PLAYER).m_DiffuseHandle; GetRenderNode().SetDiffuseTextureHandle( CAssetManager::GetInstance()->GetObjData(ET_SMALLENEMY).m_DiffuseHandle ); } else { GetRenderNode().SetDiffuseTextureHandle( CAssetManager::GetInstance()->GetObjData(ET_PLAYER).m_DiffuseHandle ); } m_HealthPickup -= HEALTH_PICKUP_BLINKING_TIME; healthpickupcolor = !healthpickupcolor; } else { GetRenderNode().SetDiffuseTextureHandle( CAssetManager::GetInstance()->GetObjData(ET_PLAYER).m_DiffuseHandle ); } if( GetIsDying() ) { SetIsDying(false); SetKillScreen(false); //m_StopAnimSwitching = false; Vec3f direction; glsLoadVector3(direction, 0.0f, 0.0f, 0.0f); glsCopyVector3(*GetPosition(), direction); GetRenderNode().SetPosition( direction ); ResetMatrix(); } // Vec3f direction; // glsLoadVector3(direction, 0.0f, 0.0f, 0.0f); // // Gets the two distances between the north and south pole (possibly in need of optimizations later). // float SDist = glsGetDistance3(direction, GetRenderNode().m_vPosition); // glsLoadVector3(direction, 0.0f, 150.0f, 0.0f); // float NDist = glsGetDistance3(direction, GetRenderNode().m_vPosition); // // finds the shortest one so it can travel to that one // bool HeadinNorth = NDist < SDist ; // // resets the vector if heading to the south // if(!HeadinNorth) // glsLoadVector3(direction, 0.0f, 0.0f, 0.0f); // // gets the directional vector // glsSubtractVectors3(direction, direction, GetRenderNode().m_vPosition); // glsNormalizeVector3(direction); // glsScaleVector3(direction, 30.0f * _elapsedTime); // // // moves the player by that direction by elapsedTime // glsAddVectors3(GetRenderNode().m_vPosition, GetRenderNode().m_vPosition, direction); // // if the distance is small enough the player stops moving // //glsLoadVector3(direction, 0.0f, 0.0f, 0.0f); // if( (HeadinNorth ? NDist : SDist) <= 0.5f ) // { // SetIsDying(false); // m_StopAnimSwitching = false; // ResetMatrix(); // GetAnimationManager()->SwitchAnimation(CAssetManager::GetInstance()->GetAnimation(ET_PLAYER, PL_IDLE), 0.01f); // } // // copying the player's new position% // glsCopyVector3(*this->GetPosition(), GetRenderNode().m_vPosition); // // // remaking the player's up vector // Vec3f world = { 0.0f, 75.0f, 0.0f }; // glsSubtractVectors3(direction, world, GetRenderNode().m_vPosition); // glsNormalizeVector3(direction); // glsCopyVector3(GetRenderNode().m_vUp, direction); // glsCrossProduct3( this->GetRenderNode().m_vForward, this->GetRenderNode().m_vRight, this->GetRenderNode().m_vUp ); // glsNormalizeVector3( this->GetRenderNode().m_vForward ); // glsCrossProduct3( this->GetRenderNode().m_vRight, this->GetRenderNode().m_vUp, this->GetRenderNode().m_vForward ); // glsNormalizeVector3( this->GetRenderNode().m_vRight ); // // returing out so no other calcualtions are done. // GetAnimationManager()->Update(_elapsedTime, &GetRenderNode()); // return true; //} if( m_PullTimer > 0.0f ) m_PullTimer -= _elapsedTime; else if( m_PullTimer < 0.0f ) m_PullTimer = 0.0f; if( m_PushTimer > 0.0f ) m_PushTimer -= _elapsedTime; else if( m_PushTimer < 0.0f ) m_PushTimer = 0.0f; m_Gun.AddTime(_elapsedTime); // Orient the movement glsCopyVector3(m_MoveUp, this->GetRenderNode().GetUpVector()); glsCrossProduct3( m_MoveForward, m_MoveRight, m_MoveUp ); glsNormalizeVector3( m_MoveForward ); glsCrossProduct3( m_MoveRight, m_MoveUp, m_MoveForward ); glsNormalizeVector3( m_MoveRight ); // Update the velocities. UpdateVelocity(); m_PosXOffset += (*this->GetVelocity())[0] * _elapsedTime; m_PosYOffset += (*this->GetVelocity())[1] * _elapsedTime; // Call parents update CLivingEntity::Update(_elapsedTime); // Update player specific data. // Player position GetRenderNode().SetPosition( ((const float *)(*GetPosition())) ); if( m_JumpTimer > 0.0f ) { m_JumpTimer -= _elapsedTime; } else if( m_JumpTimer < 0.0f ) m_JumpTimer = 0.0f; ////////////////////////////////////////////// // Debug Code ////////////////////////////////////////////// //if( GetAsyncKeyState('P') & 0x01 ) //{ // std::cout << "HUD INFO:\n"; // std::cout << "HP : " << this->GetHealth() << '/' << MAX_HP_PLAYER << std::endl; // std::cout << "Lives : " << this->GetLives() << std::endl; // std::cout << "Ammo : " << this->GetGun().GetShotTotal() << std::endl; // std::cout << "Curr Gun : " << this->GetGun().GetConsumed() << std::endl; //} //HAX //AUTH: Ryan //Desc: feedback for player hurt, replace with animation / effect later //Date: ???? static float hurtTimer = 0.0f; if(m_Hurt) { GetRenderNode().SetColor(1.0f, 0.2f, 0.2f, 1.0f); hurtTimer += _elapsedTime; if(hurtTimer >= 0.5f) { //this->GetRenderNode().hTextureDiffuse = CAssetManager::GetInstance()->GetObjData(ET_PLAYER).m_DiffuseHandle; GetRenderNode().SetColor(1.0f, 1.0f, 1.0f, 1.0f); hurtTimer = 0.0f; m_Hurt = false; } } glsCopyVector3(((Sphere*)this->GetCollisionEntity())->m_Center, this->GetRenderNode().GetPosition()); return true; }