From cccea19ee3879d17e817d0cb1ba1e5ccece248d3 Mon Sep 17 00:00:00 2001 From: EndrII Date: Tue, 22 Jun 2021 18:12:34 +0300 Subject: [PATCH] fix test lvl --- src/Core/Crawl/clientapp.cpp | 1 - src/Core/Crawl/guiobject.cpp | 2 +- src/Core/Crawl/iplayer.cpp | 18 +++++++++++++++++- src/Core/Crawl/iplayer.h | 8 +++++--- src/Core/Crawl/movableobject.cpp | 3 +++ src/Core/Crawl/movableobject.h | 4 ++-- src/Core/CrawlModule/Scene.qml | 5 ++++- src/CrawlTestLvl | 2 +- 8 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/Core/Crawl/clientapp.cpp b/src/Core/Crawl/clientapp.cpp index cd0cfde..8c8935f 100644 --- a/src/Core/Crawl/clientapp.cpp +++ b/src/Core/Crawl/clientapp.cpp @@ -31,7 +31,6 @@ QByteArray ClientApp::initTheme() { case 1: return "Dark"; default: return "Light"; } - } ClientApp::ClientApp() { diff --git a/src/Core/Crawl/guiobject.cpp b/src/Core/Crawl/guiobject.cpp index 88319e3..a80bf63 100644 --- a/src/Core/Crawl/guiobject.cpp +++ b/src/Core/Crawl/guiobject.cpp @@ -30,7 +30,7 @@ void GuiObject::setColor(QString color) { void GuiObject::generateId() { static int id = 0; - _guiId = id++; + setGuiId(id++); } const QString &GuiObject::className() const { diff --git a/src/Core/Crawl/iplayer.cpp b/src/Core/Crawl/iplayer.cpp index d1d80ff..a9ee4dc 100644 --- a/src/Core/Crawl/iplayer.cpp +++ b/src/Core/Crawl/iplayer.cpp @@ -5,12 +5,13 @@ //# of this license document, but changing it is not allowed. //# +#include "defaultcontrol.h" #include "iplayer.h" IPlayer::IPlayer(const QString &name, const QString &viewTempalte, QObject *ptr): - IWorldItem(name, viewTempalte, ptr) { + MovableObject(name, viewTempalte, ptr) { } @@ -52,6 +53,21 @@ void IPlayer::setSpeed(float newSpead) { } } +void IPlayer::setControl(const IControl *control) { + + + if (auto oldControl = dynamic_cast(_currentControl)) { + disconnect(oldControl, &DefaultControl::userTap, this, &IPlayer::onTap); + } + + auto defaultControl = dynamic_cast(control); + _currentControl = defaultControl; + + if (_currentControl) { + connect(defaultControl, &DefaultControl::userTap, this, &IPlayer::onTap); + } +} + void IPlayer::kill() { _fDead = true; } diff --git a/src/Core/Crawl/iplayer.h b/src/Core/Crawl/iplayer.h index 0a3a3dc..94de13c 100644 --- a/src/Core/Crawl/iplayer.h +++ b/src/Core/Crawl/iplayer.h @@ -9,15 +9,15 @@ #define IPLAYER_H #include "gameresult.h" -#include "iworlditem.h" #include "global.h" +#include "movableobject.h" class IControl; /** * @brief The IPlayer class This is base class of the player functions. */ -class CRAWL_EXPORT IPlayer: public IWorldItem { +class CRAWL_EXPORT IPlayer: public MovableObject { Q_OBJECT public: IPlayer(const QString& name, @@ -53,7 +53,7 @@ public: * @param control This is control object. * @note This method can invoked two or more times, for example connect with AI control object and player control object. So your implementation should be contains disconnect methods. */ - virtual void setControl(const IControl* control) = 0; + virtual void setControl(const IControl* control); protected: @@ -92,6 +92,7 @@ protected: */ void fine(int value); +protected slots: /** * @brief onTap This method invoked when user tap on screen. * @note method connected in the IPlayer::setControl function. So if you overrid the IPlayer::setControl method then please invoke method of a parent class. @@ -102,6 +103,7 @@ private: bool _fDead = false; int _currentPoints = 0; float _speed = 0; + const IControl * _currentControl = nullptr; }; #endif // IPLAYER_H diff --git a/src/Core/Crawl/movableobject.cpp b/src/Core/Crawl/movableobject.cpp index 907b1ed..5a8b3fd 100644 --- a/src/Core/Crawl/movableobject.cpp +++ b/src/Core/Crawl/movableobject.cpp @@ -28,6 +28,9 @@ void MovableObject::render(unsigned int tbfMsec) { // recalc new currentMovable vector (applay changes) _currentMovableVector += tempVector; + // update movable vector + _movableVector *= _breakingForce; + } const QVector3D &MovableObject::movableVector() const { diff --git a/src/Core/Crawl/movableobject.h b/src/Core/Crawl/movableobject.h index 4c01151..8abaa6f 100644 --- a/src/Core/Crawl/movableobject.h +++ b/src/Core/Crawl/movableobject.h @@ -12,7 +12,7 @@ * * **Angular velocity** This property sets spead of the angle moving. * * **Braking force** This property are delta decriment the Power of the movable vector on time. */ -class MovableObject: public IWorldItem +class CRAWL_EXPORT MovableObject: public IWorldItem { Q_OBJECT public: @@ -72,7 +72,7 @@ private: QVector3D _currentMovableVector; float _angularVelocity = 0; - float _breakingForce = 0; + float _breakingForce = 1; }; diff --git a/src/Core/CrawlModule/Scene.qml b/src/Core/CrawlModule/Scene.qml index e86dede..6c1d6a0 100644 --- a/src/Core/CrawlModule/Scene.qml +++ b/src/Core/CrawlModule/Scene.qml @@ -33,7 +33,9 @@ View3D { PointLight { position: camera.position - brightness: 1500 + rotation: camera.rotation + + brightness: 250 } environment: SceneEnvironment { @@ -64,6 +66,7 @@ View3D { console.log("create object fail") return; } + const objModel = model.getGameObject(cppObjId); if (!objModel) { diff --git a/src/CrawlTestLvl b/src/CrawlTestLvl index 3f8198a..d23bfac 160000 --- a/src/CrawlTestLvl +++ b/src/CrawlTestLvl @@ -1 +1 @@ -Subproject commit 3f8198a0767f860fa17fed86f6772f09462077fa +Subproject commit d23bfac78fa12f38aafaffc99955bcaea35e59a9