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

Added board and pieces

parent c6b06789
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -20,10 +20,14 @@ SOURCES += \
luckey.cpp \
mastercontrol.cpp \
inputmaster.cpp \
quartocam.cpp
quartocam.cpp \
board.cpp \
piece.cpp
HEADERS += \
luckey.h \
mastercontrol.h \
inputmaster.h \
quartocam.h
quartocam.h \
board.h \
piece.h
# Quarto
A digital version of [the boardgame of the same name](https://en.wikipedia.org/wiki/Quarto_%28board_game%29) by Blaise Müller.
A digital version of [the boardgame of the same name](https://en.wikipedia.org/wiki/Quarto_%28board_game%29) by Blaise Müller, made using the Urho3D game engine.
![A rendered image of the board](https://raw.githubusercontent.com/Modanung/Quarto/master/Blends/Render/2.png)
\ No newline at end of file
<?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" />
<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" />
<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.25 0.19 0.14 1" />
<parameter name="MatEmissiveColor" value="0 0 0" />
<parameter name="MatEnvMapColor" value="1 1 1" />
<parameter name="MatSpecColor" value="0.32 0.35 0.3 5" />
<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.75 0.62 0.42 1" />
<parameter name="MatEmissiveColor" value="0 0 0" />
<parameter name="MatEnvMapColor" value="0.4 0.5 0.4" />
<parameter name="MatSpecColor" value="0.5 0.5 0.5 5" />
<cull value="ccw" />
<shadowcull value="ccw" />
<fill value="solid" />
<depthbias constant="0" slopescaled="0" />
<renderorder value="128" />
</material>
#include "board.h"
Board::Board(Context* context, MasterControl *masterControl): Object(context),
masterControl_{masterControl}
{
Node* rootNode = masterControl_->world.scene->CreateChild("Board");
model_ = rootNode->CreateComponent<StaticModel>();
model_->SetModel(masterControl_->cache_->GetResource<Model>("Resources/Models/Board.mdl"));
model_->SetMaterial(masterControl_->cache_->GetResource<Material>("Resources/Materials/Wood_board.xml"));
model_->SetCastShadows(true);
}
#ifndef BOARD_H
#define BOARD_H
#include <Urho3D/Urho3D.h>
#include "mastercontrol.h"
#include "piece.h"
namespace Urho3D {
class Node;
}
using namespace Urho3D;
class Board : public Object
{
URHO3D_OBJECT(Board, Object);
public:
Board(Context *context, MasterControl* masterControl);
private:
MasterControl* masterControl_;
StaticModel* model_;
};
#endif // BOARD_H
/* LucKey Productions Urho3D Project Template
//
// This is free and unencumbered software released into the public domain.
//
// Anyone is free to copy, modify, publish, use, compile, sell, or
// distribute this software, either in source code form or as a compiled
// binary, for any purpose, commercial or non-commercial, and by any
// means.
//
// In jurisdictions that recognize copyright laws, the author or authors
// of this software dedicate any and all copyright interest in the
// software to the public domain. We make this dedication for the benefit
// of the public at large and to the detriment of our heirs and
// successors. We intend this dedication to be an overt act of
// relinquishment in perpetuity of all present and future rights to this
// software under copyright law.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// For more information, please refer to <http://unlicense.org/>
*/
#include "inputmaster.h"
#include "quartocam.h"
......@@ -52,12 +24,12 @@ void InputMaster::HandleKeyDown(StringHash eventType, VariantMap &eventData)
case KEY_ESC:{
masterControl_->Exit();
} break;
//Take screenshot
//Take screenshot when 9 is pressed
case KEY_9:{
Graphics* graphics = GetSubsystem<Graphics>();
Image screenshot(context_);
graphics->TakeScreenShot(screenshot);
//Here we save in the Data folder with date and time appended
//Here we save in the Screenshots folder with date and time appended
String fileName = GetSubsystem<FileSystem>()->GetProgramDir() + "Screenshots/Screenshot_" +
Time::GetTimeStamp().Replaced(':', '_').Replaced('.', '_').Replaced(' ', '_')+".png";
Log::Write(1, fileName);
......
/* LucKey Productions Urho3D Project Template
//
// This is free and unencumbered software released into the public domain.
//
// Anyone is free to copy, modify, publish, use, compile, sell, or
// distribute this software, either in source code form or as a compiled
// binary, for any purpose, commercial or non-commercial, and by any
// means.
//
// In jurisdictions that recognize copyright laws, the author or authors
// of this software dedicate any and all copyright interest in the
// software to the public domain. We make this dedication for the benefit
// of the public at large and to the detriment of our heirs and
// successors. We intend this dedication to be an overt act of
// relinquishment in perpetuity of all present and future rights to this
// software under copyright law.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// For more information, please refer to <http://unlicense.org/>
*/
#ifndef INPUTMASTER_H
#define INPUTMASTER_H
......
/*
// Copyright (C) 2015 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
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef LUCKEY_H
#define LUCKEY_H
......
/* LucKey Productions Urho3D Project Template
// This is free and unencumbered software released into the public domain.
// Anyone is free to copy, modify, publish, use, compile, sell, or
// distribute this software, either in source code form or as a compiled
// binary, for any purpose, commercial or non-commercial, and by any
// means.
// In jurisdictions that recognize copyright laws, the author or authors
// of this software dedicate any and all copyright interest in the
// software to the public domain. We make this dedication for the benefit
// of the public at large and to the detriment of our heirs and
// successors. We intend this dedication to be an overt act of
// relinquishment in perpetuity of all present and future rights to this
// software under copyright law.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// For more information, please refer to <http://unlicense.org/>
*/
#include "mastercontrol.h"
#include "quartocam.h"
#include "inputmaster.h"
#include "quartocam.h"
#include "board.h"
URHO3D_DEFINE_APPLICATION_MAIN(MasterControl);
......@@ -76,38 +49,44 @@ void MasterControl::CreateScene()
world.scene->CreateComponent<Octree>();
world.camera = new QuartoCam(context_, this);
CreateLights();
Node* tableNode = world.scene->CreateChild("Table");
tableNode->SetPosition(Vector3::DOWN * 0.4f);
tableNode->SetRotation(Quaternion(23.5f, Vector3::UP));
tableNode->SetScale(23.0f);
StaticModel* tableModel = tableNode->CreateComponent<StaticModel>();
tableModel->SetModel(cache_->GetResource<Model>("Models/Plane.mdl"));
tableModel->SetMaterial(cache_->GetResource<Material>("Resources/Materials/Basic.xml"));
new Board(context_, this);
for (int p = 0; p < 16; ++p){
Piece* newPiece = new Piece(context_, this, std::bitset<4>(p));
newPiece->SetPosition(Quaternion(360.0f/16 * p, Vector3::UP) * Vector3::RIGHT * 9.0f +
Vector3::DOWN * 0.4f);
}
}
void MasterControl::CreateLights()
{
//Add a directional light to the world. Enable cascaded shadows on it
Node* downardsLightNode = world.scene->CreateChild("DirectionalLight");
downardsLightNode->SetPosition(Vector3(-2.0f, 10.0f, -5.0f));
downardsLightNode->SetPosition(Vector3(-5.0f, 23.0f, -2.0f));
downardsLightNode->LookAt(Vector3(0.0f, 0.0f, 0.0f));
Light* downwardsLight = downardsLightNode->CreateComponent<Light>();
downwardsLight->SetLightType(LIGHT_DIRECTIONAL);
downwardsLight->SetBrightness(0.666f);
downwardsLight->SetBrightness(1.0f);
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(1.0f, 5.0f, 23.0f, 100.0f, 0.8f));
//Add a directional light to the world. Enable cascaded shadows on it
Node* upwardsLightNode = world.scene->CreateChild("DirectionalLight");
upwardsLightNode->SetPosition(Vector3(3.0f, -10.0f, -5.0f));
upwardsLightNode->LookAt(Vector3(0.0f, 0.0f, 0.0f));
Light* upwardsLight = upwardsLightNode->CreateComponent<Light>();
upwardsLight->SetLightType(LIGHT_DIRECTIONAL);
upwardsLight->SetBrightness(0.5);
upwardsLight->SetColor(Color(0.23f, 0.666f, 1.0f));
//Create a point light. Enable cascaded shadows on it
Node* pointLightNode_ = world.scene->CreateChild("MovingLight");
Node* pointLightNode_ = world.scene->CreateChild("PointLight");
pointLightNode_->SetPosition(Vector3(0.0f, -1.0f, -13.0f));
Light* pointLight = pointLightNode_->CreateComponent<Light>();
pointLight->SetLightType(LIGHT_POINT);
pointLight->SetBrightness(0.1f);
pointLight->SetRange(23.0f);
pointLight->SetColor(Color(0.5f, 1.23f, 0.75f));
pointLight->SetBrightness(0.5f);
pointLight->SetRange(42.0f);
pointLight->SetColor(Color(0.75f, 1.0f, 0.75f));
}
/* LucKey Productions Urho3D Project Template
//
// This is free and unencumbered software released into the public domain.
//
// Anyone is free to copy, modify, publish, use, compile, sell, or
// distribute this software, either in source code form or as a compiled
// binary, for any purpose, commercial or non-commercial, and by any
// means.
//
// In jurisdictions that recognize copyright laws, the author or authors
// of this software dedicate any and all copyright interest in the
// software to the public domain. We make this dedication for the benefit
// of the public at large and to the detriment of our heirs and
// successors. We intend this dedication to be an overt act of
// relinquishment in perpetuity of all present and future rights to this
// software under copyright law.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// For more information, please refer to <http://unlicense.org/>
*/
#ifndef MASTERCONTROL_H
#define MASTERCONTROL_H
......
#include "piece.h"
Piece::Piece(Context* context, MasterControl *masterControl, std::bitset<4> attributes): Object(context),
masterControl_{masterControl}
{
rootNode_ = masterControl_->world.scene->CreateChild("Piece");
rootNode_->SetRotation(Quaternion(Random(360.0f), Vector3::UP));
attributes_ = attributes;
StaticModel* model = rootNode_->CreateComponent<StaticModel>();
model->SetCastShadows(true);
switch (attributes.to_ulong()){
case 0: case 8: model->SetModel(masterControl_->cache_->GetResource<Model>("Resources/Models/Piece_SSS.mdl"));
break;
case 1: case 9: model->SetModel(masterControl_->cache_->GetResource<Model>("Resources/Models/Piece_SSH.mdl"));
break;
case 2: case 10: model->SetModel(masterControl_->cache_->GetResource<Model>("Resources/Models/Piece_SRS.mdl"));
break;
case 3: case 11: model->SetModel(masterControl_->cache_->GetResource<Model>("Resources/Models/Piece_SRH.mdl"));
break;
case 4: case 12: model->SetModel(masterControl_->cache_->GetResource<Model>("Resources/Models/Piece_TSS.mdl"));
break;
case 5: case 13: model->SetModel(masterControl_->cache_->GetResource<Model>("Resources/Models/Piece_TSH.mdl"));
break;
case 6: case 14: model->SetModel(masterControl_->cache_->GetResource<Model>("Resources/Models/Piece_TRS.mdl"));
break;
case 7: case 15: model->SetModel(masterControl_->cache_->GetResource<Model>("Resources/Models/Piece_TRH.mdl"));
break;
}
if (attributes[3]){
model->SetMaterial(masterControl_->cache_->GetResource<Material>("Resources/Materials/Wood_dark.xml"));
}
else model->SetMaterial(masterControl_->cache_->GetResource<Material>("Resources/Materials/Wood_light.xml"));
}
#ifndef PIECE_H
#define PIECE_H
#include <Urho3D/Urho3D.h>
#include "mastercontrol.h"
#include <bitset>
namespace Urho3D {
class Node;
}
using namespace Urho3D;
enum class PieceState {FREE, SELECTED, PUT};
class Piece : public Object
{
URHO3D_OBJECT(Piece, Object);
public:
Piece(Context *context, MasterControl* masterControl, std::bitset<4> attributes);
void SetPosition(Vector3 pos) { rootNode_->SetPosition(pos); }
inline bool GetAttribute(int index) const noexcept { return attributes_[index]; }
private:
MasterControl* masterControl_;
Node* rootNode_;
std::bitset<4> attributes_;
PieceState state_;
};
#endif // PIECE_H
/* LucKey Productions Urho3D Project Template
//
// This is free and unencumbered software released into the public domain.
//
// Anyone is free to copy, modify, publish, use, compile, sell, or
// distribute this software, either in source code form or as a compiled
// binary, for any purpose, commercial or non-commercial, and by any
// means.
//
// In jurisdictions that recognize copyright laws, the author or authors
// of this software dedicate any and all copyright interest in the
// software to the public domain. We make this dedication for the benefit
// of the public at large and to the detriment of our heirs and
// successors. We intend this dedication to be an overt act of
// relinquishment in perpetuity of all present and future rights to this
// software under copyright law.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// For more information, please refer to <http://unlicense.org/>
*/
#include "quartocam.h"
QuartoCam::QuartoCam(Context *context, MasterControl *masterControl):
......@@ -36,12 +8,12 @@ QuartoCam::QuartoCam(Context *context, MasterControl *masterControl):
rootNode_ = masterControl_->world.scene->CreateChild("Camera");
camera_ = rootNode_->CreateComponent<Camera>();
camera_->SetFarClip(1024.0f);
rootNode_->SetPosition(Vector3(0.0f, 1.0f, -13.0f));
rootNode_->SetRotation(Quaternion(10.0f, 0.0f, 0.0f));
rootNode_->SetPosition(Vector3(0.0f, 5.0f, -13.0f));
rootNode_->LookAt(Vector3::UP);
// Zone* zone = rootNode_->CreateComponent<Zone>();
// zone->SetFogStart(13.0f);
// zone->SetFogEnd(23.0f);
Zone* zone = rootNode_->CreateComponent<Zone>();
zone->SetFogStart(23.0f);
zone->SetFogEnd(42.0f);
SetupViewport();
}
......
/* LucKey Productions Urho3D Project Template
//
// This is free and unencumbered software released into the public domain.
//
// Anyone is free to copy, modify, publish, use, compile, sell, or
// distribute this software, either in source code form or as a compiled
// binary, for any purpose, commercial or non-commercial, and by any
// means.
//
// In jurisdictions that recognize copyright laws, the author or authors
// of this software dedicate any and all copyright interest in the
// software to the public domain. We make this dedication for the benefit
// of the public at large and to the detriment of our heirs and
// successors. We intend this dedication to be an overt act of
// relinquishment in perpetuity of all present and future rights to this
// software under copyright law.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// For more information, please refer to <http://unlicense.org/>
*/
#ifndef TEMPLATECAM_H
#define TEMPLATECAM_H
......
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