Commit 1535d014 authored by 魔大农's avatar 魔大农 🍀

Added alternative song

parent 82794263
This diff is collapsed.
<?xml version="1.0"?>
<material>
<technique name="Techniques/NoTexture.xml" quality="0" loddistance="0" />
<parameter name="UOffset" value="1 0 0 0" />
<parameter name="VOffset" value="0 1 0 0" />
<parameter name="MatDiffColor" value="0.23 0.23 0.23 1" />
<parameter name="MatEmissiveColor" value="0 0 0" />
<parameter name="MatEnvMapColor" value="1 1 1" />
<parameter name="MatSpecColor" value="1 1 0.9 5" />
</material>
<?xml version="1.0"?>
<material>
<technique name="Techniques/PBR/PBRDiffNormalEnvMap.xml" quality="0" loddistance="0" />
<texture unit="diffuse" name="Textures/BoardDiffuse.png" />
<texture unit="normal" name="Textures/BoardNormal.png" />
<texture unit="specular" name="Textures/BoardSpecular.png" />
<texture unit="environment" name="Textures/LeafyKnoll.xml" />
<parameter name="UOffset" value="1 0 0 0" />
<parameter name="VOffset" value="0 1 0 0" />
<parameter name="RoughnessPS" value="0.1" />
<parameter name="MetallicPS" value="0" />
<cull value="ccw" />
<shadowcull value="ccw" />
<fill value="solid" />
<depthbias constant="0" slopescaled="0" />
<renderorder value="128" />
</material>
<?xml version="1.0"?>
<material>
<technique name="Techniques/NoTexture.xml" quality="0" loddistance="0" />
<parameter name="UOffset" value="1 0 0 0" />
<parameter name="VOffset" value="0 1 0 0" />
<parameter name="MatDiffColor" value="0.42 0.32 0.2 1" />
<parameter name="MatEmissiveColor" value="0 0 0" />
<parameter name="MatEnvMapColor" value="0.4 0.5 0.4" />
<parameter name="MatSpecColor" value="1 1 0.9 5" />
</material>
......@@ -20,8 +20,8 @@ Board::Board(): Object(MC->GetContext()),
model_->SetCastShadows(true);
//Fill board with squares
for (int i{0}; i < BOARD_HEIGHT; ++i)
for (int j{0}; j < BOARD_WIDTH; ++j){
for (int i{0}; i < BOARD_WIDTH; ++i)
for (int j{0}; j < BOARD_HEIGHT; ++j){
Square* square{new Square};
square->coords_ = IntVector2(i, j);
square->node_ = rootNode_->CreateChild("Square");
......@@ -38,12 +38,11 @@ Board::Board(): Object(MC->GetContext()),
Node* lightNode{slotNode->CreateChild("Light")};
lightNode->SetPosition(Vector3::UP * 0.23f);
square->light_ = square->node_->CreateComponent<Light>();
square->light_ = lightNode->CreateComponent<Light>();
square->light_->SetColor(Color(0.0f, 0.8f, 0.5f));
square->light_->SetBrightness(0.1f);
square->light_->SetBrightness(0.05f);
square->light_->SetRange(2.0f);
square->light_->SetCastShadows(true);
square->light_->SetCastShadows(false);
squares_[square->coords_] = square;
// square->node_->SetEnabledRecursive(false);
......@@ -261,7 +260,7 @@ void Board::Deselect(Square* square)
square->selected_ = false;
MC->effectMaster_->FadeOut(square->slot_->GetMaterial());
MC->effectMaster_->FadeTo(square->light_, 0.1f);
MC->effectMaster_->FadeTo(square->light_, 0.05f);
}
void Board::DeselectAll()
{
......
......@@ -24,6 +24,26 @@ void EffectMaster::FadeTo(Light* light, float brightness, float duration)
light->SetAttributeAnimation("Brightness Multiplier", fade, WM_ONCE);
}
void EffectMaster::FadeTo(SoundSource* soundSource, float gain, float duration)
{
ValueAnimation* fade{new ValueAnimation(context_)};
fade->SetKeyFrame(0.0f, soundSource->GetGain());
fade->SetKeyFrame(0.42f * duration, Lerp(soundSource->GetGain(), gain, 0.5f));
fade->SetKeyFrame(duration, gain);
soundSource->SetAttributeAnimation("Gain", fade, WM_ONCE);
}
void EffectMaster::FadeOut(SoundSource* soundSource, float duration)
{
float lastGain{soundSource->GetGain()};
ValueAnimation* fade{new ValueAnimation(context_)};
fade->SetKeyFrame(0.0f, lastGain);
fade->SetKeyFrame(0.2f * duration, 0.5f * lastGain);
fade->SetKeyFrame(0.46f * duration, 0.1f * lastGain);
fade->SetKeyFrame(duration, 0.0f);
soundSource->SetAttributeAnimation("Gain", fade, WM_ONCE);
}
void EffectMaster::TransformTo(Node* node, Vector3 pos, Quaternion rot, float duration)
{
ValueAnimation* posAnim{new ValueAnimation(context_)};
......
......@@ -16,6 +16,8 @@ public:
void FadeTo(Material* material, Color color, float duration = 0.23f);
void FadeTo(Light* light, float brightness, float duration = 0.23f);
void FadeTo(SoundSource* soundSource, float gain, float duration = 2.3f);
void FadeOut(SoundSource* soundSource, float duration = 5.0f);
void TransformTo(Node* node, Vector3 pos, Quaternion rot = Quaternion::IDENTITY, float duration = 1.0f);
};
......
......@@ -48,7 +48,7 @@ void InputMaster::HandleKeyDown(StringHash eventType, VariantMap &eventData)
Screenshot();
} break;
case KEY_M: {
MC->ToggleMusic();
MC->NextMusicState();
} break;
case KEY_KP_PLUS: {
MC->MusicGainUp(volumeStep);
......
......@@ -17,7 +17,9 @@ MasterControl* MasterControl::GetInstance()
MasterControl::MasterControl(Context *context):
Application(context),
musicGain_{1.0f},
gameState_{GameState::PLAYER1PICKS}
gameState_{GameState::PLAYER1PICKS},
musicState_{MUSIC_SONG1},
previousMusicState_{MUSIC_OFF}
{
instance_ = this;
}
......@@ -44,13 +46,19 @@ void MasterControl::Start()
CreateScene();
//Play music
Sound* music{cache_->GetResource<Sound>("Resources/Music/Angelight - The Knowledge River.ogg")};
music->SetLooped(true);
Sound* song1{GetMusic("Angelight - The Knowledge River")};
Sound* song2{GetMusic("Cao Sao Vang - Days Of Yore")};
Node* musicNode{world.scene->CreateChild("Music")};
musicSource_ = musicNode->CreateComponent<SoundSource>();
musicSource_->SetSoundType(SOUND_MUSIC);
musicSource_->SetGain(musicGain_);
musicSource_->Play(music);
musicSource1_ = musicNode->CreateComponent<SoundSource>();
musicSource1_->SetSoundType(SOUND_MUSIC);
musicSource1_->SetGain(musicGain_);
musicSource1_->Play(song1);
musicSource2_ = musicNode->CreateComponent<SoundSource>();
musicSource2_->SetSoundType(SOUND_MUSIC);
musicSource2_->SetGain(0.0f);
musicSource2_->Play(song2);
SubscribeToEvent(E_UPDATE, URHO3D_HANDLER(MasterControl, HandleUpdate));
}
......@@ -83,7 +91,6 @@ void MasterControl::CreateScene()
//Create table
Node* tableNode = world.scene->CreateChild("Table");
tableNode->SetRotation(Quaternion(23.5f, Vector3::UP));
// tableNode->SetScale(19.0f);
StaticModel* tableModel = tableNode->CreateComponent<StaticModel>();
tableModel->SetModel(GetModel("Table"));
tableModel->SetMaterial(GetMaterial("Table"));
......@@ -103,8 +110,7 @@ void MasterControl::CreateScene()
void MasterControl::CreateLights()
{
//Add main light source
//Add leafy light source
leafyLightNode_ = world.scene->CreateChild("DirectionalLight");
leafyLightNode_->SetPosition(Vector3(6.0f, 96.0f, 9.0f));
leafyLightNode_->LookAt(Vector3(0.0f, 0.0f, 0.0f));
......@@ -113,12 +119,7 @@ void MasterControl::CreateLights()
leafyLight_->SetRange(180.0f);
leafyLight_->SetFov(34.0f);
leafyLight_->SetCastShadows(false);
leafyLight_->SetShadowIntensity(0.23f);
leafyLight_->SetShapeTexture(static_cast<Texture*>(cache_->GetResource<Texture2D>("Textures/LeafyMask.png")));
leafyLight_->SetShadowBias(BiasParameters(0.000025f, 0.5f));
leafyLight_->SetShadowCascade(CascadeParameters(5.0f, 7.0f, 23.0f, 42.0f, 0.8f));
// leafyLight_->SetShadowCascade(CascadeParameters(64.0f, 86.0f, 128.0f, 192.0f, 0.8f));
// leafyLight_->SetShadowCascade(CascadeParameters(5.0f, 7.0f, 23.0f, 42.0f, 0.8f));
//Add a directional light to the world. Enable cascaded shadows on it
Node* downardsLightNode{world.scene->CreateChild("DirectionalLight")};
......@@ -129,11 +130,10 @@ void MasterControl::CreateLights()
downwardsLight->SetBrightness(0.34f);
downwardsLight->SetColor(Color(0.8f, 0.9f, 0.95f));
downwardsLight->SetCastShadows(true);
// downwardsLight->SetShadowIntensity(0.23f);
downwardsLight->SetShadowBias(BiasParameters(0.000025f, 0.5f));
downwardsLight->SetShadowCascade(CascadeParameters(5.0f, 7.0f, 23.0f, 42.0f, 0.8f));
//Create a point lights.
//Create point lights
for (Vector3 pos : {Vector3(-10.0f, 8.0f, -23.0f), Vector3(-20.0f, -8.0f, 23.0f), Vector3(20.0f, -7.0f, 23.0f)}){
Node* pointLightNode_{world.scene->CreateChild("PointLight")};
pointLightNode_->SetPosition(pos);
......@@ -178,9 +178,21 @@ int MasterControl::CountFreePieces()
return count;
}
Sound* MasterControl::GetMusic(String name) const {
Sound* song{cache_->GetResource<Sound>("Music/"+name+".ogg")};
song->SetLooped(true);
return song;
}
Sound*MasterControl::GetSample(String name) const {
Sound* sample{cache_->GetResource<Sound>("Samples/"+name+".ogg")};
sample->SetLooped(false);
return sample;
}
void MasterControl::HandleUpdate(StringHash eventType, VariantMap& eventData)
{
// float t{eventData[Update::P_TIMESTEP].GetFloat()};
// float t{eventData[Update::P_TIMESTEP].GetFloat()};
UpdateSelectedPiece();
//Wave leafy light
......@@ -250,28 +262,37 @@ void MasterControl::Reset()
gameState_ = GameState::PLAYER1PICKS;
}
void MasterControl::ToggleMusic()
void MasterControl::NextMusicState()
{
ValueAnimation* fade{musicSource_->GetAttributeAnimation("Gain")};
float fadeEndValue{-1.0f};
if (fade)
fadeEndValue = fade->GetAnimationValue(fade->GetEndTime()).GetFloat();
if (musicSource_->GetGain() == 0.0f || fadeEndValue == 0.0f){
ValueAnimation* fadeIn_{new ValueAnimation(context_)};
fadeIn_->SetKeyFrame(0.0f, 0.0f);
fadeIn_->SetKeyFrame(1.0f, 0.5f * musicGain_);
fadeIn_->SetKeyFrame(2.3f, Min(musicGain_, 0.1f));
musicSource_->SetAttributeAnimation("Gain", fadeIn_, WM_ONCE);
if (musicState_ == MUSIC_SONG1){
effectMaster_->FadeOut(musicSource1_);
} else if (musicState_ == MUSIC_SONG2){
effectMaster_->FadeOut(musicSource2_);
}
else{
float lastGain_{musicSource_->GetGain()};
ValueAnimation* fadeOut_ = new ValueAnimation(context_);
fadeOut_->SetKeyFrame(0.0f, lastGain_);
fadeOut_->SetKeyFrame(1.0f, 0.5f * lastGain_);
fadeOut_->SetKeyFrame(2.3f, 0.1f * lastGain_);
fadeOut_->SetKeyFrame(5.0f, 0.0f);
musicSource_->SetAttributeAnimation("Gain", fadeOut_, WM_ONCE);
switch (musicState_) {
case MUSIC_SONG1: case MUSIC_SONG2:{
previousMusicState_ = musicState_;
musicState_ = MUSIC_OFF;
} break;
case MUSIC_OFF: {
if (previousMusicState_ == MUSIC_SONG1)
musicState_ = MUSIC_SONG2;
else if (previousMusicState_ == MUSIC_SONG2)
musicState_ = MUSIC_SONG1;
previousMusicState_ = MUSIC_OFF;
} break;
default: {
previousMusicState_ = MUSIC_OFF;
musicState_ = MUSIC_SONG1;
} break;
}
if (musicState_ == MUSIC_SONG1){
effectMaster_->FadeTo(musicSource1_, musicGain_);
} else if (musicState_ == MUSIC_SONG2){
effectMaster_->FadeTo(musicSource2_, musicGain_);
}
}
......@@ -279,19 +300,19 @@ void MasterControl::MusicGainUp(float step)
{
musicGain_ = Clamp(musicGain_ + step, step, 1.0f);
ValueAnimation* fadeIn_{new ValueAnimation(context_)};
fadeIn_->SetKeyFrame(0.0f, musicSource_->GetGain());
fadeIn_->SetKeyFrame(0.23f, musicGain_);
musicSource_->SetAttributeAnimation("Gain", fadeIn_, WM_ONCE);
if (musicState_ == MUSIC_SONG1)
effectMaster_->FadeTo(musicSource1_, musicGain_, 0.23f);
else if (musicState_ == MUSIC_SONG2)
effectMaster_->FadeTo(musicSource2_, musicGain_, 0.23f);
}
void MasterControl::MusicGainDown(float step)
{
musicGain_ = Clamp(musicGain_ - step, 0.0f, 1.0f);
ValueAnimation* fadeOut_{new ValueAnimation(context_)};
fadeOut_->SetKeyFrame(0.0f, musicSource_->GetGain());
fadeOut_->SetKeyFrame(0.23f, musicGain_);
musicSource_->SetAttributeAnimation("Gain", fadeOut_, WM_ONCE);
if (musicState_ == MUSIC_SONG1)
effectMaster_->FadeTo(musicSource1_, musicGain_, 0.23f);
else if (musicState_ == MUSIC_SONG2)
effectMaster_->FadeTo(musicSource2_, musicGain_, 0.23f);
}
float MasterControl::Sine(const float freq, const float min, const float max, const float shift)
......
......@@ -20,6 +20,7 @@ class Board;
class Piece;
enum class GameState{PLAYER1PICKS, PLAYER2PUTS, PLAYER2PICKS, PLAYER1PUTS, QUATTER};
enum MusicState{MUSIC_SONG1, MUSIC_SONG2, MUSIC_OFF};
typedef struct GameWorld
{
......@@ -73,6 +74,8 @@ public:
Material* GetMaterial(String name) const { return cache_->GetResource<Material>("Materials/"+name+".xml"); }
Model* GetModel(String name) const { return cache_->GetResource<Model>("Models/"+name+".mdl"); }
Texture* GetTexture(String name) const { return cache_->GetResource<Texture>("Textures/"+name+".png"); }
Sound* GetMusic(String name) const;
Sound* GetSample(String name) const;
float Sine(const float freq, const float min, const float max, const float shift = 0.0f);
float Cosine(const float freq, const float min, const float max, const float shift = 0.0f);
......@@ -80,23 +83,26 @@ public:
void Quatter();
void DeselectPiece();
void NextMusicState();
private:
static MasterControl* instance_;
InputMaster* inputMaster_;
SharedPtr<Node> leafyLightNode_;
SharedPtr<Light> leafyLight_;
SharedPtr<SoundSource> musicSource_;
SharedPtr<SoundSource> musicSource1_;
SharedPtr<SoundSource> musicSource2_;
float musicGain_;
GameState gameState_;
MusicState musicState_;
MusicState previousMusicState_;
Piece* selectedPiece_;
Piece* pickedPiece_;
void CreateScene();
void NextPhase();
void ToggleMusic();
void MusicGainUp(float step);
void MusicGainDown(float step);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment