Commit 73cb7773 authored by 魔大农's avatar 魔大农 🍀

Improved piece animation

parent 41b4bfb5
# [:four_leaf_clover:](http://www.luckeyproductions.nl/) Quatter
A digital version of [the Quarto boardgame](https://en.wikipedia.org/wiki/Quarto_%28board_game%29) by Blaise Müller, made using the [Urho3D](http://urho3d.github.io) game engine and other open source software.
A digital version of the [Quarto](https://en.wikipedia.org/wiki/Quarto_%28board_game%29) boardgame by Blaise Müller, made using the [Urho3D](http://urho3d.github.io) game engine and other open source software.
![Screenshot](https://raw.githubusercontent.com/LucKeyProductions/Quatter/master/Screenshots/Screenshot_Thu_May_26_09_02_54_2016.png)
......
......@@ -41,7 +41,7 @@ Board::Board(): Object(MC->GetContext()),
lightNode->SetPosition(Vector3::UP * 0.23f);
square->light_ = lightNode->CreateComponent<Light>();
square->light_->SetColor(COLOR_GLOW);
square->light_->SetBrightness(0.05f);
square->light_->SetBrightness(0.023f);
square->light_->SetRange(2.0f);
square->light_->SetCastShadows(false);
......@@ -311,7 +311,7 @@ void Board::Deselect(Square* square)
//Fade out slot and light
FX->FadeOut(square->slot_->GetMaterial());
FX->FadeTo(square->light_, 0.05f);
FX->FadeTo(square->light_, 0.023f);
}
void Board::DeselectAll()
{
......
......@@ -4,7 +4,6 @@ using namespace Urho3D;
EffectMaster::EffectMaster() : Master()
{
}
void EffectMaster::FadeTo(Material* material, Color color, float duration)
......@@ -57,7 +56,26 @@ void EffectMaster::TransformTo(Node* node, Vector3 pos, Quaternion rot, float du
node->SetAttributeAnimation("Rotation", rotAnim, WM_ONCE);
}
void EffectMaster::ArchTo(Node* node, Vector3 pos, Quaternion rot, float archHeight, float duration, bool stall)
{
ValueAnimation* posAnim{new ValueAnimation(context_)};
posAnim->SetKeyFrame(0.0f, node->GetPosition());
float delay{Random(0.42f) * stall};
if (stall)
posAnim->SetKeyFrame(0.5f * delay, node->GetPosition());
for (int i{1}; i < WAYPOINTS - 1; ++i){
float t{static_cast<float>(i) / WAYPOINTS};
posAnim->SetKeyFrame(delay + duration * t,
node->GetPosition().Lerp(pos, t) + archHeight * Vector3::UP * Arch(t));
}
posAnim->SetKeyFrame(delay + duration, pos);
node->SetAttributeAnimation("Position", posAnim, WM_ONCE);
ValueAnimation* rotAnim{new ValueAnimation(context_)};
rotAnim->SetKeyFrame(0.0f, node->GetRotation());
if (stall)
rotAnim->SetKeyFrame(delay, node->GetRotation());
rotAnim->SetKeyFrame(duration, rot);
node->SetAttributeAnimation("Rotation", rotAnim, WM_ONCE);
}
......@@ -4,21 +4,25 @@
#include <Urho3D/Urho3D.h>
#include "master.h"
#define WAYPOINTS 42
class EffectMaster : public Master
{
URHO3D_OBJECT(EffectMaster, Master);
public:
EffectMaster();
void FadeOut(Material* material) {
FadeTo(material, material->GetShaderParameter("MatDiffColor").GetColor() * 0.0f);
}
void FadeOut(Light* light) { FadeTo(light, 0.0f); }
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(Material* material) {FadeTo(material, material->GetShaderParameter("MatDiffColor").GetColor() * 0.0f); }
void FadeOut(Light* light) { FadeTo(light, 0.0f); }
void FadeOut(SoundSource* soundSource, float duration = 5.0f);
void TransformTo(Node* node, Vector3 pos, Quaternion rot = Quaternion::IDENTITY, float duration = 1.0f);
void ArchTo(Node* node, Vector3 pos, Quaternion rot, float archHeight = 2.3f, float duration = 1.0f, bool stall = false);
float Arch(float t) const noexcept { return 1.0f - pow(2.0f * (t-0.5f), 4.0f); }
};
#endif // EFFECTMASTER_H
......@@ -62,7 +62,7 @@ void InputMaster::HandleKeyDown(StringHash eventType, VariantMap &eventData)
switch (key){
case KEY_ESC:{
if (!BOARD->IsEmpty()){
if (!BOARD->IsEmpty() || MC->GetSelectedPiece() || MC->GetPickedPiece()){
MC->Reset();
} else MC->Exit();
} break;
......
......@@ -42,9 +42,11 @@ void Piece::Reset()
if (state_ != PieceState::FREE){
state_ = PieceState::FREE;
FX->TransformTo(rootNode_,
MC->AttributesToPosition(static_cast<int>(attributes_.to_ulong())),
Quaternion(Random(360.0f), Vector3::UP));
FX->ArchTo(rootNode_,
MC->AttributesToPosition(ToInt()),
Quaternion(Random(360.0f), Vector3::UP),
attributes_[0] ? 2.0f : 1.3f + attributes_[1] ? 0.5f : 1.0f + Random(0.23f),
RESET_DURATION, true);
}
}
......@@ -97,7 +99,7 @@ void Piece::Pick()
if (MC->GetGameState() == GameState::PLAYER2PICKS)
rootNode_->SetParent(CAMERA->GetPocket(true));
FX->TransformTo(rootNode_, Vector3::DOWN, Quaternion(10.0f, Vector3(1.0f, 0.0f, 0.5f)));
FX->ArchTo(rootNode_, Vector3::DOWN, Quaternion(10.0f, Vector3(1.0f, 0.0f, 0.5f)), 1.0f, 0.8f);
FX->FadeOut(outlineModel_->GetMaterial());
FX->FadeOut(light_);
......@@ -110,6 +112,6 @@ void Piece::Put(Vector3 position)
rootNode_->SetParent(MC->world_.scene_);
FX->TransformTo(rootNode_, position, Quaternion(Random(-13.0f, 13.0f), Vector3::UP));
FX->ArchTo(rootNode_, position, Quaternion(Random(-13.0f, 13.0f), Vector3::UP), 2.3f, 0.42f);
}
}
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