mirror of
https://github.com/QuasarApp/Snake.git
synced 2025-04-27 10:14:39 +00:00
begin refactoring init level system
This commit is contained in:
parent
3adc7c9eb3
commit
1148a0c566
@ -24,5 +24,6 @@
|
|||||||
<file>CrawlCoreAssets/particles/smokeSprite.png</file>
|
<file>CrawlCoreAssets/particles/smokeSprite.png</file>
|
||||||
<file>CrawlModule/particles/Fire.qml</file>
|
<file>CrawlModule/particles/Fire.qml</file>
|
||||||
<file>CrawlModule/particles/Wint.qml</file>
|
<file>CrawlModule/particles/Wint.qml</file>
|
||||||
|
<file>CrawlModule/PreviewScane.qml</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
@ -8,8 +8,7 @@
|
|||||||
#ifndef DEFAULTCONTROL_H
|
#ifndef DEFAULTCONTROL_H
|
||||||
#define DEFAULTCONTROL_H
|
#define DEFAULTCONTROL_H
|
||||||
|
|
||||||
#include "icontrol.h"
|
#include "player.h"
|
||||||
#include "global.h"
|
|
||||||
|
|
||||||
namespace CRAWL {
|
namespace CRAWL {
|
||||||
|
|
||||||
@ -17,7 +16,7 @@ namespace CRAWL {
|
|||||||
/**
|
/**
|
||||||
* @brief The DefaultControl class This class contains default implementation of the game menu.
|
* @brief The DefaultControl class This class contains default implementation of the game menu.
|
||||||
*/
|
*/
|
||||||
class CRAWL_EXPORT DefaultControl : public IControl {
|
class CRAWL_EXPORT DefaultControl : public Player {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
DefaultControl();
|
DefaultControl();
|
||||||
|
@ -22,6 +22,7 @@ class CRAWL_EXPORT IItem
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
IItem();
|
IItem();
|
||||||
|
virtual ~IItem() = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief itemTextId All items contains own ids, override this method for create base for generate new item id.
|
* @brief itemTextId All items contains own ids, override this method for create base for generate new item id.
|
||||||
|
@ -5,4 +5,31 @@
|
|||||||
//# of this license document, but changing it is not allowed.
|
//# of this license document, but changing it is not allowed.
|
||||||
//#
|
//#
|
||||||
|
|
||||||
|
#include "iitem.h"
|
||||||
#include "ilevel.h"
|
#include "ilevel.h"
|
||||||
|
#include "iworld.h"
|
||||||
|
|
||||||
|
namespace CRAWL {
|
||||||
|
|
||||||
|
ILevel::~ILevel() {
|
||||||
|
delete _world;
|
||||||
|
delete _previewScane;
|
||||||
|
}
|
||||||
|
|
||||||
|
IWorld *ILevel::world() {
|
||||||
|
return _world;
|
||||||
|
}
|
||||||
|
|
||||||
|
IWorld *ILevel::previewScane() {
|
||||||
|
return _previewScane;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ILevel::setWorld(IWorld *newWorld) {
|
||||||
|
_world = newWorld;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ILevel::setPreviewScane(IWorld *newPreviewScane) {
|
||||||
|
_previewScane = newPreviewScane;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
//# of this license document, but changing it is not allowed.
|
//# of this license document, but changing it is not allowed.
|
||||||
//#
|
//#
|
||||||
|
|
||||||
|
#include <QHash>
|
||||||
|
|
||||||
#ifndef LEVEL_H
|
#ifndef LEVEL_H
|
||||||
#define LEVEL_H
|
#define LEVEL_H
|
||||||
|
|
||||||
@ -12,22 +14,54 @@ namespace CRAWL {
|
|||||||
|
|
||||||
|
|
||||||
class IWorld;
|
class IWorld;
|
||||||
|
class IItem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The ILevel class This interface make the world instance object.
|
* @brief The ILevel class This interface make the world instance object.
|
||||||
* All levels libraries should be override this interface.
|
* All levels libraries should be override this interface.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
class ILevel
|
class ILevel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ILevel() = default;
|
ILevel() = default;
|
||||||
virtual ~ILevel() = default;
|
virtual ~ILevel();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief world This method should be return pointer to the level world.
|
* @brief world This method should be return pointer to the level world.
|
||||||
* @return pointer to the level world.
|
* @return pointer to the level world.
|
||||||
|
* @see ILevel::setWorld
|
||||||
*/
|
*/
|
||||||
virtual IWorld* world() = 0;
|
IWorld* world();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief previewScane this method should be create a model of the snake preview scane.
|
||||||
|
* @return pointer to the model of the preview scane.
|
||||||
|
* @see ILevel::setPreviewScane
|
||||||
|
*/
|
||||||
|
IWorld* previewScane();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/**
|
||||||
|
* @brief setWorld This method sets new world pointer.
|
||||||
|
* @param newWorld This is new world model object.
|
||||||
|
* @note The @a newWorld item will be distroued with the parent object.
|
||||||
|
* @see ILevel::world
|
||||||
|
*/
|
||||||
|
void setWorld(IWorld *newWorld);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief setPreviewScane This method sets new object for the preview scane.
|
||||||
|
* @param newPreviewScane This is new value of the preview scane.
|
||||||
|
* @note The @a newPreviewScane item will be distroued with the parent object.
|
||||||
|
* @see ILevel::previewScane
|
||||||
|
*/
|
||||||
|
void setPreviewScane(IWorld *newPreviewScane);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
IWorld* _world = nullptr;
|
||||||
|
IWorld* _previewScane = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
47
src/Core/Crawl/ipreviewscaneworld.cpp
Normal file
47
src/Core/Crawl/ipreviewscaneworld.cpp
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
//#
|
||||||
|
//# Copyright (C) 2021-2021 QuasarApp.
|
||||||
|
//# Distributed under the GPLv3 software license, see the accompanying
|
||||||
|
//# Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
//# of this license document, but changing it is not allowed.
|
||||||
|
//#
|
||||||
|
|
||||||
|
#include "ipreviewscaneworld.h"
|
||||||
|
namespace CRAWL {
|
||||||
|
|
||||||
|
IPreviewScaneWorld::IPreviewScaneWorld() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QString IPreviewScaneWorld::itemTextId() const {
|
||||||
|
return "preview";
|
||||||
|
}
|
||||||
|
|
||||||
|
QString IPreviewScaneWorld::itemName() const {
|
||||||
|
return itemTextId();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString IPreviewScaneWorld::description() const {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
QString IPreviewScaneWorld::image() const {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
int IPreviewScaneWorld::cost() const {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int IPreviewScaneWorld::requiredTier() const {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IPreviewScaneWorld::start(const StartData& config) {
|
||||||
|
_configuration = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IPreviewScaneWorld::stop() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
43
src/Core/Crawl/ipreviewscaneworld.h
Normal file
43
src/Core/Crawl/ipreviewscaneworld.h
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
//#
|
||||||
|
//# Copyright (C) 2021-2021 QuasarApp.
|
||||||
|
//# Distributed under the GPLv3 software license, see the accompanying
|
||||||
|
//# Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
//# of this license document, but changing it is not allowed.
|
||||||
|
//#
|
||||||
|
|
||||||
|
#ifndef IPREVIEWSCANEWORLD_H
|
||||||
|
#define IPREVIEWSCANEWORLD_H
|
||||||
|
|
||||||
|
#include "iworld.h"
|
||||||
|
|
||||||
|
namespace CRAWL {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The IPreviewScaneWorld class is interface of the all preview scanes models.
|
||||||
|
*/
|
||||||
|
class CRAWL_EXPORT IPreviewScaneWorld: public IWorld
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
IPreviewScaneWorld();
|
||||||
|
|
||||||
|
// IItem interface
|
||||||
|
public:
|
||||||
|
QString itemTextId() const override final;
|
||||||
|
QString itemName() const override final;
|
||||||
|
QString description() const override final;
|
||||||
|
QString image() const override final;
|
||||||
|
int cost() const override final;
|
||||||
|
int requiredTier() const override final;
|
||||||
|
|
||||||
|
bool start(const StartData &config) override;
|
||||||
|
bool stop() override;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void sigPrepareIsFinished(const StartData& config);
|
||||||
|
|
||||||
|
private:
|
||||||
|
StartData _configuration;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif // IPREVIEWSCANEWORLD_H
|
@ -20,6 +20,7 @@
|
|||||||
#include "chrono"
|
#include "chrono"
|
||||||
#include "diff.h"
|
#include "diff.h"
|
||||||
#include "eventserver.h"
|
#include "eventserver.h"
|
||||||
|
#include "player.h"
|
||||||
|
|
||||||
namespace CRAWL {
|
namespace CRAWL {
|
||||||
|
|
||||||
@ -40,9 +41,11 @@ IWorld::~IWorld() {
|
|||||||
delete _eventServer;
|
delete _eventServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IWorld::init() {prepare();}
|
void IWorld::init() {
|
||||||
|
prepare();
|
||||||
|
}
|
||||||
|
|
||||||
IControl *IWorld::initUserInterface() const {
|
Player *IWorld::initUserInterface() const {
|
||||||
return new DefaultControl;
|
return new DefaultControl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,12 +86,13 @@ void IWorld::initPlayerControl(IControl *control) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IWorld::start() {
|
bool IWorld::start(const StartData& config) {
|
||||||
_player->setposition({0,0,0});
|
_player->setposition({0,0,0});
|
||||||
|
|
||||||
setWorldStatus(WorldStatus::Game);
|
setWorldStatus(WorldStatus::Game);
|
||||||
_backgroundAI->stopAI();
|
_backgroundAI->stopAI();
|
||||||
_player->setControl(_userInterface);
|
_player->setControl(_userInterface);
|
||||||
|
setPlayer(initPlayer());
|
||||||
|
|
||||||
|
|
||||||
worldChanged(_worldRules->cbegin());
|
worldChanged(_worldRules->cbegin());
|
||||||
@ -151,8 +155,6 @@ bool IWorld::prepare() {
|
|||||||
_worldRules = initWorldRules();
|
_worldRules = initWorldRules();
|
||||||
|
|
||||||
setHdr(initHdrBackGround());
|
setHdr(initHdrBackGround());
|
||||||
setPlayer(initPlayer());
|
|
||||||
_player->initOnWorld(this, _player);
|
|
||||||
_userInterface = initUserInterface();
|
_userInterface = initUserInterface();
|
||||||
_backgroundAI = initBackGroundAI();
|
_backgroundAI = initBackGroundAI();
|
||||||
|
|
||||||
@ -283,7 +285,7 @@ void IWorld::addAtomicItem(IWorldItem* obj) {
|
|||||||
_items.insert(obj->guiId(), obj);
|
_items.insert(obj->guiId(), obj);
|
||||||
_itemsGroup.insert(obj->className(), obj->guiId());
|
_itemsGroup.insert(obj->className(), obj->guiId());
|
||||||
|
|
||||||
obj->initOnWorld(this, _player);
|
obj->initOnWorld(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IWorld::removeAtomicItem(int id) {
|
bool IWorld::removeAtomicItem(int id) {
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include "gameresult.h"
|
#include "gameresult.h"
|
||||||
#include "iitem.h"
|
#include "iitem.h"
|
||||||
#include "playableobject.h"
|
#include "playableobject.h"
|
||||||
|
#include "startdata.h"
|
||||||
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
@ -42,6 +43,7 @@ class IControl;
|
|||||||
class IAI;
|
class IAI;
|
||||||
class IWorldLight;
|
class IWorldLight;
|
||||||
class EventServer;
|
class EventServer;
|
||||||
|
class Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief WorldObjects This is map list of the avalable objects and its count on a lvl-long point.
|
* @brief WorldObjects This is map list of the avalable objects and its count on a lvl-long point.
|
||||||
@ -110,7 +112,7 @@ public:
|
|||||||
* @note The base implementation return default user interface.
|
* @note The base implementation return default user interface.
|
||||||
* @return pointer to userInterface.
|
* @return pointer to userInterface.
|
||||||
*/
|
*/
|
||||||
virtual IControl* initUserInterface() const;
|
virtual Player *initUserInterface() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief initHdrBackGround The implementation of this method must be return valid path to the hdr image map.
|
* @brief initHdrBackGround The implementation of this method must be return valid path to the hdr image map.
|
||||||
@ -127,17 +129,18 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief initPlayerControl This method should be configure all connections of @a control object.
|
* @brief initPlayerControl This method should be configure all connections of @a control object.
|
||||||
* @brief control This is control object
|
* @param control This is control object
|
||||||
* @note override this method if you have own IControl object.
|
* @note override this method if you have own IControl object.
|
||||||
*/
|
*/
|
||||||
virtual void initPlayerControl(IControl* control);
|
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.
|
||||||
|
* @param config This is initialize level arguments.
|
||||||
* @note The Default implementation reset all positions for all objects.
|
* @note The Default implementation reset all positions for all objects.
|
||||||
* @return true if game started successful.
|
* @return true if game started successful.
|
||||||
*/
|
*/
|
||||||
virtual bool start();
|
virtual bool start(const StartData &config);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief stop This methos will be invoked when user click to return to main menu button.
|
* @brief stop This methos will be invoked when user click to return to main menu button.
|
||||||
@ -487,8 +490,8 @@ private:
|
|||||||
WorldRule::const_iterator _currendWorldLevel;
|
WorldRule::const_iterator _currendWorldLevel;
|
||||||
|
|
||||||
PlayableObject *_player = nullptr;
|
PlayableObject *_player = nullptr;
|
||||||
IControl *_userInterface = nullptr;
|
|
||||||
IAI *_backgroundAI = nullptr;
|
IAI *_backgroundAI = nullptr;
|
||||||
|
Player *_userInterface = nullptr;
|
||||||
int _worldStatus = 0;
|
int _worldStatus = 0;
|
||||||
QHash<QString, std::function<IWorldItem*()>> _registeredTypes;
|
QHash<QString, std::function<IWorldItem*()>> _registeredTypes;
|
||||||
|
|
||||||
|
@ -30,10 +30,17 @@ const IWorldItem *IWorldItem::getItem(int id) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const IWorldItem *IWorldItem::getPlayer() const {
|
const IWorldItem *IWorldItem::getPlayer() const {
|
||||||
return _playerObject;
|
if (!_world)
|
||||||
|
return nullptr;
|
||||||
|
return static_cast<const IWorldItem *>(_world->player());
|
||||||
}
|
}
|
||||||
|
|
||||||
void IWorldItem::render(unsigned int) {
|
void IWorldItem::render(unsigned int) {
|
||||||
|
auto _playerObject = getPlayer();
|
||||||
|
|
||||||
|
if (!_playerObject)
|
||||||
|
return;
|
||||||
|
|
||||||
if (_playerObject->position().distanceToPoint(position()) >
|
if (_playerObject->position().distanceToPoint(position()) >
|
||||||
_world->cameraReleativePosition().z() * 3) {
|
_world->cameraReleativePosition().z() * 3) {
|
||||||
respawn();
|
respawn();
|
||||||
@ -42,9 +49,8 @@ void IWorldItem::render(unsigned int) {
|
|||||||
|
|
||||||
void IWorldItem::init() {}
|
void IWorldItem::init() {}
|
||||||
|
|
||||||
void IWorldItem::initOnWorld(const IWorld *world, const IWorldItem * player) {
|
void IWorldItem::initOnWorld(const IWorld *world) {
|
||||||
_world = world;
|
_world = world;
|
||||||
_playerObject = player;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int IWorldItem::supportedEvents() const {
|
int IWorldItem::supportedEvents() const {
|
||||||
@ -60,6 +66,11 @@ void IWorldItem::destroy() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void IWorldItem::respawn() {
|
void IWorldItem::respawn() {
|
||||||
|
auto _playerObject = getPlayer();
|
||||||
|
|
||||||
|
if (!_playerObject)
|
||||||
|
return;
|
||||||
|
|
||||||
float dX = _world->cameraReleativePosition().z() * 2 +
|
float dX = _world->cameraReleativePosition().z() * 2 +
|
||||||
(rand() % static_cast<int>(_world->cameraReleativePosition().z()));
|
(rand() % static_cast<int>(_world->cameraReleativePosition().z()));
|
||||||
|
|
||||||
|
@ -135,10 +135,9 @@ protected:
|
|||||||
void dropSupportOfEvent(int depricatedEvent);
|
void dropSupportOfEvent(int depricatedEvent);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initOnWorld(const IWorld* world, const IWorldItem *player);
|
void initOnWorld(const IWorld* world);
|
||||||
|
|
||||||
const IWorld* _world = nullptr;
|
const IWorld* _world = nullptr;
|
||||||
const IWorldItem *_playerObject = nullptr;
|
|
||||||
|
|
||||||
bool _fDecorative = true;
|
bool _fDecorative = true;
|
||||||
bool _fDistroy = false;
|
bool _fDistroy = false;
|
||||||
|
@ -6,9 +6,29 @@
|
|||||||
//#
|
//#
|
||||||
|
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
#include <user.h>
|
||||||
|
|
||||||
namespace CRAWL {
|
namespace CRAWL {
|
||||||
|
|
||||||
Player::Player() {
|
Player::Player() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Player::addXp(int newXp) {
|
||||||
|
if (_userData)
|
||||||
|
_userData->setXp(_userData->getXp() + newXp);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Player::addMoney(int money) {
|
||||||
|
if (_userData)
|
||||||
|
_userData->setMoney(_userData->getMoney() + money);
|
||||||
|
}
|
||||||
|
|
||||||
|
User *Player::userData() const {
|
||||||
|
return _userData;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Player::setUserData(User *newUserData) {
|
||||||
|
_userData = newUserData;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,11 @@
|
|||||||
|
|
||||||
#include "icontrol.h"
|
#include "icontrol.h"
|
||||||
|
|
||||||
|
|
||||||
namespace CRAWL {
|
namespace CRAWL {
|
||||||
|
|
||||||
|
class User;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The Player class is main class of users.
|
* @brief The Player class is main class of users.
|
||||||
*/
|
*/
|
||||||
@ -21,6 +24,34 @@ class CRAWL_EXPORT Player: public IControl
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Player();
|
Player();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief addXp This method add new xp to palyer.
|
||||||
|
* @param newXp this is value of experience
|
||||||
|
*/
|
||||||
|
void addXp(int newXp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief addMoney This method add money to user.
|
||||||
|
* @param money added amount of money
|
||||||
|
*/
|
||||||
|
void addMoney(int money);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief userData This method sets user that control this object.
|
||||||
|
* @return current control user.
|
||||||
|
*/
|
||||||
|
User *userData() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief setUserData This method sets user that control this object.
|
||||||
|
* @param newUserData This is new pointer of the new user.
|
||||||
|
*/
|
||||||
|
void setUserData(User *newUserData);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
User *_userData = nullptr;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif // PLAYER_H
|
#endif // PLAYER_H
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#ifndef CRAWL_SNAKE_H
|
#ifndef CRAWL_SNAKE_H
|
||||||
#define CRAWL_SNAKE_H
|
#define CRAWL_SNAKE_H
|
||||||
|
|
||||||
|
#include "iitem.h"
|
||||||
#include "playableobject.h"
|
#include "playableobject.h"
|
||||||
#include "Extensions/autogenerateclaster.h"
|
#include "Extensions/autogenerateclaster.h"
|
||||||
|
|
||||||
@ -18,7 +19,7 @@ class SnakeItem;
|
|||||||
/**
|
/**
|
||||||
* @brief The Snake class This class implement render mehod for snake object.
|
* @brief The Snake class This class implement render mehod for snake object.
|
||||||
*/
|
*/
|
||||||
class CRAWL_EXPORT Snake : public PlayableObject, public AutoGenerateClaster
|
class CRAWL_EXPORT Snake : public PlayableObject, public AutoGenerateClaster, public IItem
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
@ -34,7 +35,6 @@ public:
|
|||||||
void remove(int id) override;
|
void remove(int id) override;
|
||||||
void init() override;
|
void init() override;
|
||||||
|
|
||||||
|
|
||||||
// IPlayer interface
|
// IPlayer interface
|
||||||
/**
|
/**
|
||||||
* @brief lengthBetwinItems This method return length betwin snake items;
|
* @brief lengthBetwinItems This method return length betwin snake items;
|
||||||
@ -132,7 +132,6 @@ private:
|
|||||||
float _speed;
|
float _speed;
|
||||||
|
|
||||||
int _hp = 100;
|
int _hp = 100;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
38
src/Core/Crawl/startdata.cpp
Normal file
38
src/Core/Crawl/startdata.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
//#
|
||||||
|
//# Copyright (C) 2021-2021 QuasarApp.
|
||||||
|
//# Distributed under the GPLv3 software license, see the accompanying
|
||||||
|
//# Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
//# of this license document, but changing it is not allowed.
|
||||||
|
//#
|
||||||
|
|
||||||
|
#include "startdata.h"
|
||||||
|
|
||||||
|
namespace CRAWL {
|
||||||
|
|
||||||
|
StartData::StartData() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
StartData::StartData(User *player, int snake) {
|
||||||
|
setPlayer(player);
|
||||||
|
setSnakeType(snake);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
User *StartData::player() const{
|
||||||
|
return _player;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StartData::setPlayer(User *newPlayer) {
|
||||||
|
_player = newPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
int StartData::snakeType() const {
|
||||||
|
return _snakeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StartData::setSnakeType(int newSnake) {
|
||||||
|
_snakeType = newSnake;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
61
src/Core/Crawl/startdata.h
Normal file
61
src/Core/Crawl/startdata.h
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
//#
|
||||||
|
//# Copyright (C) 2021-2021 QuasarApp.
|
||||||
|
//# Distributed under the GPLv3 software license, see the accompanying
|
||||||
|
//# Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
//# of this license document, but changing it is not allowed.
|
||||||
|
//#
|
||||||
|
|
||||||
|
#ifndef STARTDATA_H
|
||||||
|
#define STARTDATA_H
|
||||||
|
|
||||||
|
namespace CRAWL {
|
||||||
|
|
||||||
|
class User;
|
||||||
|
class PlayableObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The StartData class This class contains arguments for starting new game session.
|
||||||
|
*/
|
||||||
|
class StartData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
StartData();
|
||||||
|
|
||||||
|
StartData(User * player, int snake);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief player This method return pointer to user that will be control player snake.
|
||||||
|
* @return pointer to user that will be control player snake.
|
||||||
|
* @see StartData::setPlayer
|
||||||
|
*/
|
||||||
|
User *player() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief setPlayer This method sets
|
||||||
|
* @param newPlayer This is new object of the user.
|
||||||
|
* @see StartData::player
|
||||||
|
*/
|
||||||
|
void setPlayer(User *newPlayer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief snakeType This method return select for game snake object type.
|
||||||
|
* @return select for game snake object.
|
||||||
|
* @see StartData::setSnakeType
|
||||||
|
*/
|
||||||
|
int snakeType() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief setSnakeType This method sets new selected for game object type,
|
||||||
|
* @param newSnake This is new selected for game object
|
||||||
|
* @see StartData::snakeType
|
||||||
|
*/
|
||||||
|
void setSnakeType(int newSnake);
|
||||||
|
|
||||||
|
private:
|
||||||
|
User *_player = nullptr;
|
||||||
|
int _snakeType;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // STARTDATA_H
|
135
src/Core/CrawlModule/PreviewScane.qml
Normal file
135
src/Core/CrawlModule/PreviewScane.qml
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
import QtQuick
|
||||||
|
import QtQuick3D
|
||||||
|
import QtQuick.Controls.Material
|
||||||
|
import QtQuick.Controls
|
||||||
|
import QtQuick.Layouts
|
||||||
|
import QtQuick3D.Particles3D
|
||||||
|
|
||||||
|
|
||||||
|
View3D {
|
||||||
|
id: scene;
|
||||||
|
|
||||||
|
property var model: null;
|
||||||
|
renderMode: View3D.Offscreen
|
||||||
|
|
||||||
|
PerspectiveCamera {
|
||||||
|
id: camera
|
||||||
|
position: Qt.vector3d(0,0, 100)
|
||||||
|
}
|
||||||
|
|
||||||
|
SceneEnvironment {
|
||||||
|
id: defautlBackground
|
||||||
|
backgroundMode: SceneEnvironment.Color
|
||||||
|
clearColor: "#777777"
|
||||||
|
}
|
||||||
|
|
||||||
|
environment: /*(privateRoot.world)? background:*/ defautlBackground
|
||||||
|
|
||||||
|
ParticleSystem3D {
|
||||||
|
id: privateRoot
|
||||||
|
property var arrayObjects: []
|
||||||
|
property var world: (model)? model.world: null
|
||||||
|
|
||||||
|
property var gameMenuModel: (model)? model.menu: null
|
||||||
|
property var player: (world)? world.player: null
|
||||||
|
property var releativeCameraPosition: (world)? world.cameraReleativePosition: null
|
||||||
|
|
||||||
|
function add (cppObjId) {
|
||||||
|
if (!model) {
|
||||||
|
console.log("create object fail")
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const objModel = model.getGameObject(cppObjId);
|
||||||
|
|
||||||
|
if (!objModel) {
|
||||||
|
console.log("object model not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var viewTemplate = objModel.viewTemplate;
|
||||||
|
|
||||||
|
var temp = Qt.createComponent(viewTemplate)
|
||||||
|
if (temp.status === Component.Ready) {
|
||||||
|
var obj = temp.createObject(privateRoot)
|
||||||
|
obj.model = objModel;
|
||||||
|
arrayObjects.push(obj)
|
||||||
|
} else {
|
||||||
|
console.log("wrong viewTemplate in model " + temp.errorString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function remove(id) {
|
||||||
|
if (typeof id !== "number" || id < 0) {
|
||||||
|
console.log("id not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < arrayObjects.length; ++i) {
|
||||||
|
if (id === arrayObjects[i].guiId) {
|
||||||
|
arrayObjects[i].destroy();
|
||||||
|
arrayObjects.splice(i,1);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: privateRoot.world;
|
||||||
|
function onSigOBjctsListChanged(diff) {
|
||||||
|
if (!diff) {
|
||||||
|
console.log("diff not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let tempDifRem = [];
|
||||||
|
tempDifRem = diff.getRemoveIds();
|
||||||
|
let tempDifAdd = [];
|
||||||
|
tempDifAdd = diff.getAddedIds();
|
||||||
|
|
||||||
|
for (let i = 0; i < tempDifAdd.length; ++i) {
|
||||||
|
privateRoot.add(tempDifAdd[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let j = 0; j < tempDifRem.length; ++j) {
|
||||||
|
privateRoot.remove(tempDifRem[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: privateRoot;
|
||||||
|
|
||||||
|
function onGameMenuModelChanged() {
|
||||||
|
if (!privateRoot.gameMenuModel) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const comp = Qt.createComponent(privateRoot.gameMenuModel.view);
|
||||||
|
if (comp.status === Component.Ready) {
|
||||||
|
if (privateRoot.gameMenu) {
|
||||||
|
privateRoot.gameMenu.destroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
privateRoot.gameMenu = comp.createObject(scene);
|
||||||
|
if (privateRoot.gameMenu === null) {
|
||||||
|
// Error Handling
|
||||||
|
console.log("Error creating object");
|
||||||
|
}
|
||||||
|
|
||||||
|
privateRoot.gameMenu.model = privateRoot.gameMenuModel;
|
||||||
|
|
||||||
|
} else if (comp.status === Component.Error) {
|
||||||
|
// Error Handling
|
||||||
|
console.log("Error loading component: " + privateRoot.gameMenuModel.view, comp.errorString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onShowMenuChanged() {
|
||||||
|
if (privateRoot.gameMenu) {
|
||||||
|
privateRoot.gameMenu.visible = !showMenu
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user