Commit c87d5cb4 authored by 魔大农's avatar 魔大农 🍀

Added wood texture to pieces

parent 3931a75c
No preview for this file type
<?xml version="1.0"?>
<material>
<technique name="Techniques/DiffNormalSpec.xml" quality="0" loddistance="0" />
<texture unit="diffuse" name="Textures/WoodDark.png" />
<texture unit="normal" name="Textures/WoodNormals.png" />
<texture unit="specular" name="Textures/WoodSpecular.png" />
<parameter name="MatDiffColor" value="1 1 1 1" />
<parameter name="MatSpecColor" value="0.32 0.35 0.3 5" />
<cull value="ccw" />
<shadowcull value="ccw" />
<fill value="solid" />
</material>
<?xml version="1.0"?>
<material>
<technique name="Techniques/DiffNormalSpec.xml" quality="0" loddistance="0" />
<texture unit="diffuse" name="Textures/WoodLight.png" />
<texture unit="normal" name="Textures/WoodNormals.png" />
<texture unit="specular" name="Textures/WoodSpecular.png" />
<parameter name="MatDiffColor" value="1 1 1 1" />
<parameter name="MatSpecColor" value="0.13 0.15 0.1 7" />
<cull value="ccw" />
<shadowcull value="ccw" />
<fill value="solid" />
</material>
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -36,7 +36,8 @@ void Board::RegisterObject(Context *context)
Board::Board(Context* context): LogicComponent(context),
squares_{},
selectedSquare_{},
lastSelectedSquare_{}
lastSelectedSquare_{},
indicators_{}
{
}
......@@ -305,7 +306,8 @@ bool Board::CheckQuatter()
//Quatter!
if (matching.any()) {
Indicate(IntVector2(0, j), IntVector2(BOARD_WIDTH - 1, j));
Indicate(IntVector2(0, j),
IntVector2(BOARD_WIDTH - 1, j));
return true;
}
}
......@@ -346,7 +348,8 @@ bool Board::CheckQuatter()
//Quatter!
if (matching.any()) {
Indicate(IntVector2{i, 0}, IntVector2{i, BOARD_HEIGHT - 1});
Indicate(IntVector2(i, 0),
IntVector2(i, BOARD_HEIGHT - 1));
return true;
}
}
......@@ -387,8 +390,8 @@ bool Board::CheckQuatter()
//Quatter!
if (matching.any()) {
Indicate(IntVector2{ 0, direction * (BOARD_HEIGHT - 1) },
IntVector2{ BOARD_WIDTH - 1, !direction * (BOARD_HEIGHT - 1) });
Indicate(IntVector2( 0, direction * (BOARD_HEIGHT - 1) ),
IntVector2( BOARD_WIDTH - 1, !direction * (BOARD_HEIGHT - 1) ));
return true;
}
}
......@@ -405,12 +408,12 @@ bool Board::CheckQuatter()
for (int m : {0, 1}) for (int n : {0, 1}) {
IntVector2 coords(k + m, l + n);
Piece* piece{squares_[coords].Get()->piece_};
IntVector2 coords{ k + m, l + n };
Piece* piece{ squares_[coords].Get()->piece_ };
if (piece) {
Piece::PieceAttributes attributes(piece->GetPieceAttributes());
Piece::PieceAttributes attributes{ piece->GetPieceAttributes() };
if (m == 0 && n == 0) {
......@@ -445,8 +448,26 @@ bool Board::CheckQuatter()
}
void Board::Indicate(IntVector2 first, IntVector2 last)
{
//Indicate row
if (first.y_ == last.y_) {
//Indicate single square (for keyboard selection)
if (last == IntVector2(-1, -1)) {
FadeInIndicator(indicators_[0], true);
FX->TransformTo(indicators_[0]->GetNode(),
CoordsToPosition(first) * Vector3(0.0f, 1.0f, 1.0f),
indicators_[0]->GetNode()->GetRotation(),
0.05f);
indicators_[0]->model1_->SetMorphWeight(1, static_cast<float>(first.y_ > 0 && first.y_ < 3));
indicators_[0]->model2_->SetMorphWeight(1, static_cast<float>(first.y_ > 0 && first.y_ < 3));
FadeInIndicator(indicators_[1], true);
FX->TransformTo(indicators_[1]->GetNode(),
CoordsToPosition(first) * Vector3(1.0f, 1.0f, 0.0f),
indicators_[1]->GetNode()->GetRotation(),
0.05f);
indicators_[1]->model1_->SetMorphWeight(1, static_cast<float>(first.x_ > 0 && first.x_ < 3));
indicators_[1]->model2_->SetMorphWeight(1, static_cast<float>(first.x_ > 0 && first.x_ < 3));
//Indicate row
} else if (first.y_ == last.y_) {
FadeInIndicator(indicators_[0]);
indicators_[0]->GetNode()->SetPosition(CoordsToPosition(first) * Vector3(0.0f, 1.0f, 1.0f));
......@@ -479,9 +500,9 @@ void Board::Indicate(IntVector2 first, IntVector2 last)
FadeInIndicator(indicators_[2]);
}
void Board::FadeInIndicator(Indicator* indicator)
void Board::FadeInIndicator(Indicator* indicator, bool fast)
{
FX->FadeTo(indicator->glow_, COLOR_GLOW, 2.3f, 1.0f);
FX->FadeTo(indicator->glow_, COLOR_GLOW, fast? 0.23f : 2.3f, fast ? 0.0f : 1.0f);
}
void Board::HideIndicators()
{
......
......@@ -84,7 +84,7 @@ private:
void Indicate(IntVector2 first, IntVector2 last = IntVector2(-1, -1));
void CreateSquares();
void CreateIndicators();
void FadeInIndicator(Indicator* indicator);
void FadeInIndicator(Indicator* indicator, bool fast = false);
};
#endif // BOARD_H
......@@ -26,7 +26,7 @@ EffectMaster::EffectMaster(Context* context) : Master(context)
void EffectMaster::FadeTo(Material* material, Color color, float duration, float delay)
{
Color startColor{material->GetShaderParameter("MatDiffColor").GetColor()};
Color startColor{ material->GetShaderParameter("MatDiffColor").GetColor() };
ValueAnimation* fade{ new ValueAnimation(context_) };
fade->SetKeyFrame(0.0f, startColor);
......@@ -47,7 +47,7 @@ void EffectMaster::FadeTo(Light* light, float brightness, float duration)
void EffectMaster::FadeTo(SoundSource* soundSource, float gain, float duration)
{
ValueAnimation* fade{new ValueAnimation(context_)};
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);
......@@ -57,7 +57,7 @@ void EffectMaster::FadeOut(SoundSource* soundSource, float duration)
{
float lastGain{ soundSource->GetGain() };
ValueAnimation* fade{new ValueAnimation(context_)};
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);
......@@ -68,11 +68,13 @@ void EffectMaster::FadeOut(SoundSource* soundSource, float duration)
void EffectMaster::TransformTo(Node* node, Vector3 pos, Quaternion rot, float duration)
{
ValueAnimation* posAnim{ new ValueAnimation(context_) };
posAnim->SetKeyFrame(0.0f, node->GetPosition());
posAnim->SetKeyFrame(duration, pos);
node->SetAttributeAnimation("Position", posAnim, WM_ONCE);
ValueAnimation* rotAnim{ new ValueAnimation(context_) };
rotAnim->SetKeyFrame(0.0f, node->GetRotation());
rotAnim->SetKeyFrame(duration, rot);
node->SetAttributeAnimation("Rotation", rotAnim, WM_ONCE);
......@@ -80,13 +82,13 @@ void EffectMaster::TransformTo(Node* node, Vector3 pos, Quaternion rot, float du
void EffectMaster::ArchTo(Node* node, Vector3 pos, Quaternion rot, float archHeight, float duration, float delay)
{
ValueAnimation* posAnim{new ValueAnimation(context_)};
ValueAnimation* posAnim{ new ValueAnimation(context_) };
posAnim->SetKeyFrame(0.0f, node->GetPosition());
for (int i{0}; i < WAYPOINTS - 1; ++i) {
float t{static_cast<float>(i) / WAYPOINTS};
float t2 = 0.5f * (t + (0.5f + 0.5f * pow(2.0f * (t - 0.5f), 3.0f)));
float t{ static_cast<float>(i) / WAYPOINTS };
float t2{ 0.5f * (t + (0.5f + 0.5f * pow(2.0f * (t - 0.5f), 3.0f))) };
posAnim->SetKeyFrame(delay + (duration * t2),
node->GetPosition().Lerp(pos, t) + archHeight * Vector3::UP * Arch(t));
}
......@@ -94,6 +96,7 @@ void EffectMaster::ArchTo(Node* node, Vector3 pos, Quaternion rot, float archHei
node->SetAttributeAnimation("Position", posAnim, WM_ONCE);
ValueAnimation* rotAnim{ new ValueAnimation(context_) };
rotAnim->SetKeyFrame(0.0f, node->GetRotation());
if (delay != 0.0f)
rotAnim->SetKeyFrame(delay, node->GetRotation());
......
......@@ -25,8 +25,8 @@
class Indicator : public LogicComponent
{
friend class Board;
URHO3D_OBJECT(Indicator, LogicComponent);
friend class Board;
public:
Indicator(Context* context);
......
......@@ -91,7 +91,7 @@ void InputMaster::HandleKeys()
for (int key : pressedKeys_) {
switch (key) {
case KEY_SPACE:
case KEY_SPACE: case KEY_RETURN: case KEY_RETURN2:
ActionButtonPressed();
break;
case KEY_TAB:
......@@ -151,8 +151,12 @@ void InputMaster::HandleKeyUp(StringHash eventType, VariantMap &eventData)
int key{ eventData[KeyUp::P_KEY].GetInt() };
if (key == KEY_SPACE)
if (key == KEY_SPACE
|| key == KEY_RETURN
|| key == KEY_RETURN2)
{
actionDone_ = false;
}
if (key == KEY_UP
|| key == KEY_DOWN
......@@ -491,9 +495,8 @@ void InputMaster::HandleJoystickButtonDown(StringHash eventType, VariantMap &eve
void InputMaster::HandleJoystickButtonUp(StringHash eventType, VariantMap &eventData)
{ (void)eventType;
using namespace JoystickButtonUp;
int joystickId{eventData[P_JOYSTICKID].GetInt()};
int button{eventData[P_BUTTON].GetInt()};
int joystickId{ eventData[JoystickButtonUp::P_JOYSTICKID].GetInt() };
int button{ eventData[JoystickButtonUp::P_BUTTON].GetInt() };
if (CorrectJoystickId(joystickId) && button == LucKey::SB_CROSS)
actionDone_ = false;
......@@ -510,7 +513,7 @@ void InputMaster::ActionButtonPressed()
if (MC->InPickState()){
Piece* selectedPiece{MC->GetSelectedPiece()};
Piece* selectedPiece{ MC->GetSelectedPiece() };
if (selectedPiece){
selectedPiece->Pick();
BOARD->SelectNearestFreeSquare();
......@@ -746,7 +749,7 @@ bool InputMaster::RaycastToTable()
}
Ray InputMaster::MouseRay()
{
Ray mouseRay{CAMERA->camera_->GetScreenRay(mousePos_.x_, mousePos_.y_)};
Ray mouseRay{CAMERA->GetScreenRay(mousePos_.x_, mousePos_.y_)};
return mouseRay;
}
......
......@@ -80,14 +80,7 @@ Color LucKey::RandomColor()
float LucKey::Sine(float x)
{
if (x < -M_PI){
while (x < -M_PI) {
x += 2.0f * M_PI;
}
} else while (x > M_PI) {
x -= 2.0f * M_PI;
}
x = Cycle(x, -M_PI, M_PI);
float sin{};
......
......@@ -82,6 +82,7 @@
#define CACHE GetSubsystem<ResourceCache>()
#define INPUT GetSubsystem<Input>()
#define GRAPHICS GetSubsystem<Graphics>()
#define RENDERER GetSubsystem<Renderer>()
#define TIME GetSubsystem<Time>()
#define FILES GetSubsystem<FileSystem>()
......
......@@ -70,9 +70,9 @@ void MasterControl::Setup()
//Add resource paths
String resourcePaths{};
if (FILES->DirExists(FILES->GetAppPreferencesDir("luckey", "quatter")))
/*if (FILES->DirExists(FILES->GetAppPreferencesDir("luckey", "quatter")))
resourcePaths = FILES->GetAppPreferencesDir("luckey", "quatter");
else if (FILES->DirExists("Resources"))
else */if (FILES->DirExists("Resources"))
resourcePaths = "Resources";
else if (FILES->DirExists("../Quatter/Resources"))
resourcePaths = "../Quatter/Resources";
......@@ -367,12 +367,14 @@ void MasterControl::NextPhase()
} break;
}
}
void MasterControl::Quatter()
{
previousGameState_ = gameState_;
gameState_ = GameState::QUATTER;
}
void MasterControl::Reset()
{
lastReset_ = TIME->GetElapsedTime();
......@@ -418,6 +420,7 @@ void MasterControl::NextSelectionMode()
default: break;
}
}
void MasterControl::SetSelectionMode(SelectionMode mode)
{
if (selectionMode_ == mode) return;
......@@ -462,6 +465,7 @@ void MasterControl::NextMusicState()
FX->FadeTo(musicSource2_, Max(musicGain_, 0.1f));
}
}
void MasterControl::MusicGainUp(float step)
{
musicGain_ = Clamp(musicGain_ + step, step, 1.0f);
......
......@@ -31,6 +31,7 @@ Piece::Piece(Context* context): LogicComponent(context),
state_{PieceState::FREE}
{
}
void Piece::OnNodeSet(Node* node)
{ if (!node) return;
......@@ -51,7 +52,6 @@ void Piece::OnNodeSet(Node* node)
light_->SetRange(3.0f);
}
void Piece::Init(PieceAttributes attributes)
{
attributes_ = attributes;
......@@ -59,11 +59,11 @@ void Piece::Init(PieceAttributes attributes)
if (attributes[3]) {
pieceModel_->SetMaterial(MC->GetMaterial("Wood_light"));
pieceModel_->SetMaterial(MC->GetMaterial("WoodLight"));
} else {
pieceModel_->SetMaterial(MC->GetMaterial("Wood_dark"));
pieceModel_->SetMaterial(MC->GetMaterial("WoodDark"));
}
outlineModel_->SetModel(MC->GetModel("Piece_"+GetCodon(2)+"_outline"));
......@@ -134,6 +134,7 @@ void Piece::Deselect()
FX->FadeOut(light_);
}
}
void Piece::Pick()
{
if (state_ != PieceState::PUT) {
......
......@@ -17,7 +17,7 @@
*/
#include "quattercam.h"
#include <initializer_list>
//#include <initializer_list>
void QuatterCam::RegisterObject(Context *context)
{
......@@ -30,6 +30,7 @@ QuatterCam::QuatterCam(Context* context) : LogicComponent(context),
targetPosition_{Vector3::UP * 0.42f}
{
}
void QuatterCam::OnNodeSet(Node *node)
{ if (!node) return;
......@@ -51,21 +52,22 @@ void QuatterCam::OnNodeSet(Node *node)
void QuatterCam::CreatePockets()
{
for (bool p : {true, false}){
for (bool left : { true, false }){
Node* pocketNode{node_->CreateChild("Pocket")};
pocketNode->SetPosition(Vector3(p?2.0f:-2.0f, 1.5f, 3.2f));
Node* pocketNode{ node_->CreateChild("Pocket") };
pocketNode->SetPosition(Vector3(left ? -2.0f : 2.0f, 1.5f, 3.2f));
pocketNode->SetRotation(Quaternion(-70.0f, Vector3::RIGHT));
if (p)
if (left)
pockets_.first_ = pocketNode;
else
pockets_.second_ = pocketNode;
}
}
void QuatterCam::SetupViewport()
{
SharedPtr<Viewport> viewport(new Viewport(context_, MC->world_.scene_, camera_));
viewport_ = viewport;
viewport_ = new Viewport(context_, GetScene(), camera_);
//Add anti-asliasing and bloom
effectRenderPath_ = viewport_->GetRenderPath();
......@@ -73,32 +75,37 @@ void QuatterCam::SetupViewport()
effectRenderPath_->SetEnabled("FXAA3", true);
effectRenderPath_->Append(CACHE->GetResource<XMLFile>("PostProcess/BloomHDR.xml"));
effectRenderPath_->SetShaderParameter("BloomHDRThreshold", 0.4f);
effectRenderPath_->SetShaderParameter("BloomHDRMix", Vector2(1.0f, 1.25f));
effectRenderPath_->SetShaderParameter("BloomHDRMix", Vector2(1.0f, 0.7f));
effectRenderPath_->SetEnabled("BloomHDR", true);
Renderer* renderer{GetSubsystem<Renderer>()};
renderer->SetViewport(0, viewport_);
RENDERER->SetViewport(0, viewport_);
}
void QuatterCam::Update(float timeStep)
{
//Update distance
if (aimDistance_ != distance_)
distance_ = 0.1f * (9.0f * distance_ + aimDistance_);
Vector3 relativeToTarget{(node_->GetPosition() - targetPosition_).Normalized()};
Vector3 relativeToTarget{ (node_->GetPosition() - targetPosition_).Normalized() };
if (relativeToTarget.Length() != distance_){
node_->SetPosition(distance_ * relativeToTarget + targetPosition_);
camera_->SetFov(Clamp(60.0f + distance_, 23.0f, 110.0f));
}
//Spin pockets
UpdatePockets(timeStep);
}
void QuatterCam::UpdatePockets(float timeStep)
{
float spinSpeed{23.0f};
pockets_.first_->Rotate(Quaternion(timeStep * spinSpeed, Vector3::UP));
pockets_.second_->Rotate(Quaternion(-timeStep * spinSpeed, Vector3::UP));
//Reposition pockets
pockets_.first_->SetPosition(Vector3(-2.2f - 0.06f * (ZOOM_MAX - distance_), 1.4f, 3.2f));
pockets_.second_->SetPosition(Vector3(2.2f + 0.06f * (ZOOM_MAX - distance_), 1.4f, 3.2f));
pockets_.first_->SetPosition(Vector3(-2.2f - 0.06f * (ZOOM_MAX - distance_), 1.4f - GetPitch() * 0.01f, 3.2f));
pockets_.second_->SetPosition(Vector3(2.2f + 0.06f * (ZOOM_MAX - distance_), 1.4f - GetPitch() * 0.01f, 3.2f));
}
void QuatterCam::Rotate(Vector2 rotation)
......@@ -107,18 +114,20 @@ void QuatterCam::Rotate(Vector2 rotation)
node_->RotateAround(targetPosition_,
Quaternion(rotation.x_, Vector3::UP) * Quaternion(rotation.y_, node_->GetRight()),
TS_WORLD);
Vector3 camRight{ node_->GetRight() };
//Clamp pitch
if (GetPitch() > PITCH_MAX)
node_->RotateAround(targetPosition_,
Quaternion(PITCH_MAX - GetPitch(), node_->GetRight()),
Quaternion(PITCH_MAX - GetPitch(), camRight),
TS_WORLD);
else if (GetPitch() < PITCH_MIN)
node_->RotateAround(targetPosition_,
Quaternion(PITCH_MIN - GetPitch(), node_->GetRight()),
Quaternion(PITCH_MIN - GetPitch(), camRight),
TS_WORLD);
}
void QuatterCam::Zoom(float delta)
{
aimDistance_ = Clamp(aimDistance_ - delta, ZOOM_MIN, ZOOM_MAX);
}
/* Quatter
// Copyright (C) 2017 LucKey Productions (luckeyproductions.nl)
// Copyright (C) 2016 LucKey Productions (luckeyproductions.nl)
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
......@@ -20,7 +20,7 @@
#define QUATTERCAM_H
#include <Urho3D/Urho3D.h>
#include "luckey.h"
#include "mastercontrol.h"
namespace Urho3D {
class Drawable;
......@@ -45,7 +45,6 @@ class QuatterCam : public LogicComponent
{
URHO3D_OBJECT(QuatterCam, LogicComponent);
friend class MasterControl;
friend class InputMaster;
public:
QuatterCam(Context* context);
......@@ -53,23 +52,25 @@ public:
void OnNodeSet(Node* node) override;
void Update(float timeStep) override;
SharedPtr<Camera> camera_;
SharedPtr<Viewport> viewport_;
SharedPtr<RenderPath> effectRenderPath_;
Vector3 GetPosition() const { return node_->GetPosition(); }
Node* GetPocket(bool right) const { return right ? pockets_.second_ : pockets_.first_; }
Node* GetPocket(bool left) const { return left ? pockets_.first_ : pockets_.second_; }
void Rotate(Vector2 rotation);
float GetPitch() const { return node_->GetRotation().EulerAngles().x_; }
float GetYaw() const { return node_->GetRotation().EulerAngles().y_; }
void SetDistance(float distance) { aimDistance_ = Clamp(distance, ZOOM_MIN, ZOOM_MAX); }
float GetDistance() const { return distance_; }
void Zoom(float delta);
void ZoomToBoard() { SetDistance(6.0f); }
void ZoomToTable() { SetDistance(13.0f); }
float GetDistance() const { return distance_; }
Ray GetScreenRay(float x, float y) const { return camera_->GetScreenRay(x, y); }
private:
SharedPtr<Camera> camera_;
SharedPtr<Viewport> viewport_;
SharedPtr<RenderPath> effectRenderPath_;
Pair<SharedPtr<Node>,
SharedPtr<Node>> pockets_;
......@@ -78,8 +79,8 @@ private:
Vector3 targetPosition_;
void SetupViewport();
void Rotate(Vector2 rotation);
void CreatePockets();
void UpdatePockets(float timeStep);
};
#endif // QUATTERCAM_H
......@@ -53,6 +53,7 @@ void Yad::OnNodeSet(Node *node)
light_->SetBrightness(YAD_FULLBRIGHT);
}
void Yad::Dim()
{
FX->FadeTo(light_, YAD_DIMMED);
......@@ -73,6 +74,3 @@ void Yad::Restore()
FX->FadeTo(light_, YAD_FULLBRIGHT);
FX->FadeTo(material_, COLOR_GLOW, 0.1f);
}
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