図0106a
void Scene::CreateResourses() { wstring DataDir; //サンプルのためアセットディレクトリを取得 App::GetApp()->GetAssetsDirectory(DataDir); //中略 //以下オーディオ //サウンド wstring CursorWav = DataDir + L"cursor.wav"; App::GetApp()->RegisterWav(L"cursor", CursorWav); //BGM wstring strMusic = DataDir + L"nanika .wav"; App::GetApp()->RegisterWav(L"Nanika", strMusic); }
void Scene::OnCreate(){
try {
//リソース作成
CreateResourses();
//BGMの再生
auto XAPtr = App::GetApp()->GetXAudio2Manager();
m_BGM = XAPtr->Start(L"Nanika", XAUDIO2_LOOP_INFINITE, 0.1f);
//自分自身にイベントを送る
//これにより各ステージやオブジェクトがCreate時にシーンにアクセスできる
PostEvent(0.0f, GetThis<ObjectInterface>(), GetThis<Scene>(), L"ToGameStage");
}
catch (...) {
throw;
}
}
void Scene::OnDestroy() {
//親クラスのOnDestroyを呼ぶ
SceneBase::OnDestroy();
auto XAPtr = App::GetApp()->GetXAudio2Manager();
XAPtr->Stop(m_BGM);
}
void PlayerJumpState::Enter(const shared_ptr<Player>& Obj) {
auto PtrGrav = Obj->GetBehavior<Gravity>();
PtrGrav->StartJump(Vec3(0, 4.0f, 0));
auto XAPtr = App::GetApp()->GetXAudio2Manager();
XAPtr->Start(L"cursor",0,0.5f);
}
class MultiSpark : public MultiParticle { public: //構築と破棄 MultiSpark(shared_ptr<Stage>& StagePtr); virtual ~MultiSpark(); //初期化 virtual void OnCreate() override; void InsertSpark(const Vec3& Pos); };
void MultiSpark::InsertSpark(const Vec3& Pos) { auto ParticlePtr = InsertParticle(4); ParticlePtr->SetEmitterPos(Pos); ParticlePtr->SetTextureResource(L"SPARK_TX"); ParticlePtr->SetMaxTime(0.5f); vector<ParticleSprite>& pSpriteVec = ParticlePtr->GetParticleSpriteVec(); for (auto& rParticleSprite : ParticlePtr->GetParticleSpriteVec()) { rParticleSprite.m_LocalPos.x = Util::RandZeroToOne() * 0.1f - 0.05f; rParticleSprite.m_LocalPos.y = Util::RandZeroToOne() * 0.1f; rParticleSprite.m_LocalPos.z = Util::RandZeroToOne() * 0.1f - 0.05f; //各パーティクルの移動速度を指定 rParticleSprite.m_Velocity = Vec3( rParticleSprite.m_LocalPos.x * 5.0f, rParticleSprite.m_LocalPos.y * 5.0f, rParticleSprite.m_LocalPos.z * 5.0f ); //色の指定 rParticleSprite.m_Color = Col4(1.0f, 1.0f, 1.0f, 1.0f); } }
void GameStage::CreateSpark() { auto MultiSparkPtr = AddGameObject<MultiSpark>(); //共有オブジェクトにスパークを登録 SetSharedGameObject(L"MultiSpark", MultiSparkPtr); }
void Player::OnCollision(vector<shared_ptr<GameObject>>& OtherVec) { //最初に衝突するオブジェクトがあったとき //スパークの放出 auto PtrSpark = GetStage()->GetSharedGameObject<MultiSpark>(L"MultiSpark", false); if (PtrSpark) { PtrSpark->InsertSpark(GetComponent<Transform>()->GetPosition()); } //中略 }
void SeekObject::OnCreate() { //中略 //Sphereの衝突判定をつける auto PtrColl = AddComponent<CollisionSphere>(); PtrColl->SetIsHitAction(IsHitAction::AutoOnParentSlide); PtrColl->SetCalcScaling(CalcScaling::YScale); PtrColl->SetDrawActive(true); //中略 }