Commit 5bad9cf8 authored by 魔大农's avatar 魔大农

Added outline and limited camera rotation

parent b7f08820
No preview for this file type
No preview for this file type
<material>
<technique name="Techniques/NoTextureAddAlpha.xml" />
<parameter name="MatDiffColor" value="0.125 1 0.666 0.7" />
<parameter name="MatSpecColor" value="1 1 1 16" />
</material>
\ No newline at end of file
......@@ -15,10 +15,11 @@ InputMaster::InputMaster() : Master(),
void InputMaster::HandleKeyDown(StringHash eventType, VariantMap &eventData)
{
using namespace KeyDown;
int key = eventData[P_KEY].GetInt();
int key{eventData[KeyDown::P_KEY].GetInt()};
pressedKeys_.Insert(key);
float volumeStep{0.1f};
switch (key){
//Exit when ESC is pressed
case KEY_ESC:{
......@@ -35,6 +36,15 @@ void InputMaster::HandleKeyDown(StringHash eventType, VariantMap &eventData)
Log::Write(1, fileName);
screenshot.SavePNG(fileName);
} break;
case KEY_M: {
MC->ToggleMusic();
} break;
case KEY_KP_PLUS: {
MC->MusicGainUp(volumeStep);
} break;
case KEY_KP_MINUS: {
MC->MusicGainDown(volumeStep);
} break;
default: break;
}
}
......@@ -78,9 +88,26 @@ void InputMaster::HandleJoystickButtonUp(StringHash eventType, VariantMap &event
void InputMaster::HandleUpdate(StringHash eventType, VariantMap &eventData)
{
if (input_->GetMouseButtonDown(2)){
float t{eventData[Update::P_TIMESTEP].GetFloat()};
idleTime_ += t;
if (input_->GetMouseButtonDown(1)){
idleTime_ = 0.0f;
IntVector2 mouseMove = input_->GetMouseMove();
Vector2 rotation = Vector2(mouseMove.x_, mouseMove.y_) * 0.23f;
Vector2 rotation = Vector2(mouseMove.x_, mouseMove.y_) * 0.1f;
MC->world.camera->Rotate(rotation);
}
//Should check whose turn it is
JoystickState* joy0 = input_->GetJoystickByIndex(0);
if (joy0){
Vector2 rotation{-Vector2(joy0->GetAxisPosition(2), joy0->GetAxisPosition(3))};
if (rotation.Length()){
idleTime_ = 0.0f;
MC->world.camera->Rotate(rotation);
}
}
float idleThreshold{5.0f};
if (idleTime_ > idleThreshold)
MC->world.camera->Rotate(Vector2::LEFT * Min((idleTime_ - idleThreshold) * 0.0023f, 0.005f));
}
......@@ -14,6 +14,8 @@ public:
private:
Input* input_;
float idleTime_;
HashSet<int> pressedKeys_;
HashSet<int> pressedMouseButtons_;
HashSet<int> pressedJoystickButtons_;
......
......@@ -55,6 +55,8 @@
#include <Urho3D/UI/Font.h>
#include <Urho3D/UI/Text.h>
#include <Urho3D/UI/UI.h>
#include <Urho3D/Scene/ValueAnimation.h>
#include <Urho3D/DebugNew.h>
......
......@@ -14,6 +14,7 @@ MasterControl* MasterControl::GetInstance()
MasterControl::MasterControl(Context *context):
Application(context),
musicGain_{1.0f},
gamePhase_{GamePhase::PLAYER1PICKS}
{
instance_ = this;
......@@ -25,6 +26,7 @@ void MasterControl::Setup()
engineParameters_["LogName"] = GetSubsystem<FileSystem>()->GetAppPreferencesDir("urho3d", "logs")+"Quatter.log";
engineParameters_["ResourcePaths"] = "Data;CoreData;Resources";
engineParameters_["WindowIcon"] = "icon.png";
// engineParameters_["FullScreen"] = false;
// engineParameters_["WindowWidth"] = 960;
// engineParameters_["WindowHeight"] = 540;
......@@ -37,12 +39,13 @@ void MasterControl::Start()
CreateScene();
//Play music
Sound* music = cache_->GetResource<Sound>("Resources/Music/Angelight - The Knowledge River.ogg");
Sound* music{cache_->GetResource<Sound>("Resources/Music/Angelight - The Knowledge River.ogg")};
music->SetLooped(true);
Node* musicNode = world.scene->CreateChild("Music");
SoundSource* musicSource = musicNode->CreateComponent<SoundSource>();
musicSource->SetSoundType(SOUND_MUSIC);
musicSource->Play(music);
Node* musicNode{world.scene->CreateChild("Music")};
musicSource_ = musicNode->CreateComponent<SoundSource>();
musicSource_->SetSoundType(SOUND_MUSIC);
musicSource_->SetGain(musicGain_);
musicSource_->Play(music);
}
void MasterControl::Stop()
{
......@@ -120,3 +123,44 @@ void MasterControl::NextPhase()
break;
}
}
void MasterControl::ToggleMusic()
{
if (musicSource_->GetGain() == 0.0f){
ValueAnimation* fadeIn_{new ValueAnimation(context_)};
fadeIn_->SetKeyFrame(0.0f, 0.0f);
fadeIn_->SetKeyFrame(1.0f, 0.5f * musicGain_);
fadeIn_->SetKeyFrame(2.3f, musicGain_);
musicSource_->SetAttributeAnimation("Gain", fadeIn_, WM_ONCE);
}
else{
musicGain_ = musicSource_->GetGain();
ValueAnimation* fadeOut_ = new ValueAnimation(context_);
fadeOut_->SetKeyFrame(0.0f, musicGain_);
fadeOut_->SetKeyFrame(1.0f, 0.5f * musicGain_);
fadeOut_->SetKeyFrame(2.3f, 0.1f * musicGain_);
fadeOut_->SetKeyFrame(5.0f, 0.0f);
musicSource_->SetAttributeAnimation("Gain", fadeOut_, WM_ONCE);
}
}
void MasterControl::MusicGainUp(float step)
{
musicGain_ = Clamp(musicGain_ + step, 0.0f, 1.0f);
ValueAnimation* fadeIn_{new ValueAnimation(context_)};
fadeIn_->SetKeyFrame(0.0f, musicSource_->GetGain());
fadeIn_->SetKeyFrame(0.23f, musicGain_);
musicSource_->SetAttributeAnimation("Gain", fadeIn_, WM_ONCE);
}
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);
}
......@@ -57,14 +57,23 @@ public:
void Exit();
void CreateLights();
inline GamePhase GetGamePhase() const noexcept { return gamePhase_; }
Material* GetMaterial(String name) const { return cache_->GetResource<Material>("Materials/"+name+".xml"); }
Model* GetModel(String name) const { return cache_->GetResource<Model>("Models/"+name+".mdl"); }
private:
static MasterControl* instance_;
SharedPtr<SoundSource> musicSource_;
float musicGain_;
GamePhase gamePhase_;
Node* movingLightNode_;
void CreateScene();
void NextPhase();
void ToggleMusic();
void MusicGainUp(float step);
void MusicGainDown(float step);
void HandleUpdate(StringHash eventType, VariantMap& eventData);
};
......
......@@ -7,32 +7,51 @@ Piece::Piece(std::bitset<4> attributes): Object(MC->GetContext()),
rootNode_->SetRotation(Quaternion(Random(360.0f), Vector3::UP));
attributes_ = attributes;
int attr{static_cast<int>(attributes.to_ulong())};
StaticModel* model = rootNode_->CreateComponent<StaticModel>();
model->SetCastShadows(true);
switch (attributes.to_ulong()){
case 0: case 8: model->SetModel(MC->cache_->GetResource<Model>("Resources/Models/Piece_SSS.mdl"));
StaticModel* pieceModel = rootNode_->CreateComponent<StaticModel>();
pieceModel->SetCastShadows(true);
switch (attr){
case 0: case 8: pieceModel->SetModel(MC->GetModel("Piece_SSS"));
break;
case 1: case 9: model->SetModel(MC->cache_->GetResource<Model>("Resources/Models/Piece_SSH.mdl"));
case 1: case 9: pieceModel->SetModel(MC->GetModel("Piece_SSH"));
break;
case 2: case 10: model->SetModel(MC->cache_->GetResource<Model>("Resources/Models/Piece_SRS.mdl"));
case 2: case 10: pieceModel->SetModel(MC->GetModel("Piece_SRS"));
break;
case 3: case 11: model->SetModel(MC->cache_->GetResource<Model>("Resources/Models/Piece_SRH.mdl"));
case 3: case 11: pieceModel->SetModel(MC->GetModel("Piece_SRH"));
break;
case 4: case 12: model->SetModel(MC->cache_->GetResource<Model>("Resources/Models/Piece_TSS.mdl"));
case 4: case 12: pieceModel->SetModel(MC->GetModel("Piece_TSS"));
break;
case 5: case 13: model->SetModel(MC->cache_->GetResource<Model>("Resources/Models/Piece_TSH.mdl"));
case 5: case 13: pieceModel->SetModel(MC->GetModel("Piece_TSH"));
break;
case 6: case 14: model->SetModel(MC->cache_->GetResource<Model>("Resources/Models/Piece_TRS.mdl"));
case 6: case 14: pieceModel->SetModel(MC->GetModel("Piece_TRS"));
break;
case 7: case 15: model->SetModel(MC->cache_->GetResource<Model>("Resources/Models/Piece_TRH.mdl"));
case 7: case 15: pieceModel->SetModel(MC->GetModel("Piece_TRH"));
break;
}
if (attributes[3]){
model->SetMaterial(MC->cache_->GetResource<Material>("Resources/Materials/Wood_dark.xml"));
pieceModel->SetMaterial(MC->cache_->GetResource<Material>("Resources/Materials/Wood_dark.xml"));
}
else pieceModel->SetMaterial(MC->cache_->GetResource<Material>("Resources/Materials/Wood_light.xml"));
StaticModel* outlineModel = rootNode_->CreateComponent<StaticModel>();
outlineModel->SetCastShadows(true);
outlineModel->SetEnabled(!attr);
switch(attr){
case 0: case 8: case 1: case 9:
outlineModel->SetModel(MC->GetModel("Piece_SS_outline"));
break;
case 2: case 10: case 3: case 11:
outlineModel->SetModel(MC->GetModel("Piece_SR_outline"));
break;
case 4: case 12: case 5: case 13:
outlineModel->SetModel(MC->GetModel("Piece_TS_outline"));
break;
case 6: case 14: case 7: case 15:
outlineModel->SetModel(MC->GetModel("Piece_TR_outline"));
break;
}
else model->SetMaterial(MC->cache_->GetResource<Material>("Resources/Materials/Wood_light.xml"));
outlineModel->SetMaterial(MC->cache_->GetResource<Material>("Resources/Materials/Glow.xml"));
}
......@@ -23,6 +23,8 @@ public:
inline bool GetAttribute(int index) const noexcept { return attributes_[index]; }
private:
Node* rootNode_;
String modelName_;
std::bitset<4> attributes_;
PieceState state_;
};
......
......@@ -12,9 +12,9 @@ QuatterCam::QuatterCam():
camera_ = rootNode_->CreateComponent<Camera>();
camera_->SetFarClip(1024.0f);
rootNode_->SetPosition(Vector3(3.0f, 5.0f, -11.0f));
rootNode_->LookAt(Vector3::UP);
rootNode_->LookAt(Vector3::ZERO);
Zone* zone = rootNode_->CreateComponent<Zone>();
Zone* zone{rootNode_->CreateComponent<Zone>()};
zone->SetFogStart(23.0f);
zone->SetFogEnd(42.0f);
......@@ -43,8 +43,18 @@ void QuatterCam::SetupViewport()
void QuatterCam::Rotate(Vector2 rotation)
{
rootNode_->LookAt(targetPosition_);
rootNode_->RotateAround(targetPosition_,
Quaternion(rotation.x_, Vector3::UP) * Quaternion(rotation.y_, rootNode_->GetRight()), TS_WORLD);
//Clamp pitch
float pitch{rootNode_->GetRotation().EulerAngles().x_};
if (pitch > 80.0f)
rootNode_->RotateAround(targetPosition_,
Quaternion(-(pitch - 80.0f), rootNode_->GetRight()), TS_WORLD);
else if (pitch < -0.0f)
rootNode_->RotateAround(targetPosition_,
Quaternion(-pitch, rootNode_->GetRight()), TS_WORLD);
}
//void QuatterCam::Focus(Vector3 targetPosition, float distance, float duration)
......
......@@ -32,7 +32,6 @@ public:
Quaternion GetRotation();
Vector2 GetDollyRotation();
private:
MasterControl* masterControl_;
SharedPtr<Node> rootNode_;
float distance_;
......
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