4
1
mirror of https://github.com/QuasarApp/Snake.git synced 2025-05-01 20:19:43 +00:00

added supprt of initalize controllers

This commit is contained in:
Andrei Yankovich 2021-06-15 16:04:18 +03:00
parent db42acdb70
commit ad221f815d
6 changed files with 51 additions and 2 deletions

@ -108,6 +108,7 @@ void ClientApp::start(const QString &lvl) {
} }
_engine->setWorld(data.model); _engine->setWorld(data.model);
_engine->start();
} }
QList<QFileInfo> ClientApp::availablePlugins() const { QList<QFileInfo> ClientApp::availablePlugins() const {

@ -15,7 +15,7 @@ class IAI
{ {
public: public:
IAI(); IAI();
virtual ~IAI() = default;
/** /**
* @brief startAI This method must be run ai. * @brief startAI This method must be run ai.

@ -6,6 +6,7 @@
#include "iground.h" #include "iground.h"
#include "defaultcontrol.h" #include "defaultcontrol.h"
#include "worldstatus.h" #include "worldstatus.h"
#include "iai.h"
IWorld::IWorld() { IWorld::IWorld() {
@ -35,6 +36,14 @@ void IWorld::render(unsigned int tbfMsec) {
} }
} }
void IWorld::initPlayerControl(IControl *control) {
auto controlObject = dynamic_cast<DefaultControl*>(control);
if (controlObject) {
connect(controlObject, &DefaultControl::backToMenu, this, &IWorld::handleStop);
}
}
bool IWorld::start() { bool IWorld::start() {
_player->setposition({0,0,0}); _player->setposition({0,0,0});
_player->setSpeed(0); _player->setSpeed(0);
@ -77,7 +86,6 @@ bool IWorld::init() {
_userInterface = initUserInterface(); _userInterface = initUserInterface();
_backgroundAI = initBackGroundAI(); _backgroundAI = initBackGroundAI();
if (!isInit()) { if (!isInit()) {
QuasarAppUtils::Params::log("Failed to init world implementation."); QuasarAppUtils::Params::log("Failed to init world implementation.");
deinit(); deinit();
@ -91,6 +99,9 @@ bool IWorld::init() {
return false; return false;
} }
initPlayerControl(_userInterface);
initPlayerControl(dynamic_cast<IControl*>(_backgroundAI));
generateGround(); generateGround();
worldChanged(*_worldRules->begin()); worldChanged(*_worldRules->begin());
@ -122,6 +133,11 @@ void IWorld::deinit() {
_userInterface = nullptr; _userInterface = nullptr;
} }
if (_backgroundAI) {
delete _backgroundAI;
_backgroundAI = nullptr;
}
clearItems(); clearItems();
_hdrMap = ""; _hdrMap = "";
@ -182,6 +198,10 @@ void IWorld::setTap(bool newTap) {
_tap = newTap; _tap = newTap;
} }
IAI *IWorld::backgroundAI() const {
return _backgroundAI;
}
IControl *IWorld::userInterface() const { IControl *IWorld::userInterface() const {
return _userInterface; return _userInterface;
} }

@ -124,6 +124,13 @@ public:
*/ */
virtual QVector3D initCameraPosition() = 0; virtual QVector3D initCameraPosition() = 0;
/**
* @brief initPlayerControl This method should be configure all connections of @a control object.
* @brief control This is control object
* @note override this method if you have own IControl object.
*/
virtual void initPlayerControl(IControl* control);
/** /**
* @brief start This method will be invoked when user click start button. * @brief start This method will be invoked when user click start button.
* @note The Default implementation reset all positions for all objects. * @note The Default implementation reset all positions for all objects.
@ -188,6 +195,12 @@ public:
*/ */
void setWorldStatus(int newWorldStatus); void setWorldStatus(int newWorldStatus);
/**
* @brief backgroundAI This method return current backgroundAI.
* @return Raw pointer to background AI object
*/
IAI *backgroundAI() const;
signals: signals:
/** /**
* @brief sigGameFinished This signal emit when game are finished * @brief sigGameFinished This signal emit when game are finished

@ -152,6 +152,16 @@ int Engine::prepareLvlProgress() const {
return _prepareLvlProgress; return _prepareLvlProgress;
} }
bool Engine::start() const {
if (!_currentWorld)
return false;
if (!_currentWorld->isInit())
return false;
return _currentWorld->start();
}
void Engine::setPrepareLvlProgress(int newPrepareLvlProgress) { void Engine::setPrepareLvlProgress(int newPrepareLvlProgress) {
if (_prepareLvlProgress == newPrepareLvlProgress) if (_prepareLvlProgress == newPrepareLvlProgress)
return; return;

@ -91,6 +91,11 @@ public:
*/ */
int prepareLvlProgress() const; int prepareLvlProgress() const;
/**
* @brief start This method run current lvl
* @return true if lvl started successful.
*/
bool start() const;
private slots: private slots: