mirror of
https://github.com/QuasarApp/Snake.git
synced 2025-04-27 18:24:41 +00:00
ref #88 added trees and grees
This commit is contained in:
parent
b2760c36b3
commit
fc0b60f15f
@ -16,6 +16,9 @@
|
||||
#include "Crawl/irender.h"
|
||||
|
||||
#define DEFAULT_VIEW_TEMPLATE "qrc:/CrawlModule/GraphicItem.qml"
|
||||
/** the AUTO_CLASS_NAME define gets name from the class and namespace.
|
||||
*/
|
||||
#define AUTO_CLASS_NAME typeid(this).name()
|
||||
|
||||
namespace CRAWL {
|
||||
|
||||
|
@ -24,7 +24,8 @@ namespace CRAWL {
|
||||
|
||||
|
||||
IWorld::IWorld() {
|
||||
|
||||
qRegisterMetaType<WorldRule::const_iterator>("WorldRule::const_iterator");
|
||||
connect(this, &IWorld::sigWorldChanged, this, &IWorld::worldChanged, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
IWorld::~IWorld() {
|
||||
@ -62,6 +63,7 @@ void IWorld::render(unsigned int tbfMsec) {
|
||||
emit sigGameFinished(_player->getCurrentStatus());
|
||||
}
|
||||
|
||||
updateWorld();
|
||||
|
||||
int waitTime = 1000 / _targetFps - tbfMsec;
|
||||
if (waitTime > 0)
|
||||
@ -84,7 +86,7 @@ bool IWorld::start() {
|
||||
_player->setControl(_userInterface);
|
||||
|
||||
|
||||
worldChanged(*_worldRules->begin());
|
||||
worldChanged(_worldRules->cbegin());
|
||||
setTargetFps(60);
|
||||
setRunning(true);
|
||||
|
||||
@ -338,6 +340,18 @@ void IWorld::setHdr(const QString &hdr) {
|
||||
emit hdrChanged();
|
||||
}
|
||||
|
||||
void IWorld::updateWorld() {
|
||||
|
||||
if (_currendWorldLevel->isEmpty() || !_worldRules || !_player)
|
||||
return;
|
||||
|
||||
float distance = _player->position().x();
|
||||
auto nextLevel = _currendWorldLevel + 1;
|
||||
if (nextLevel != _worldRules->cend() && distance > nextLevel.key()) {
|
||||
emit sigWorldChanged(nextLevel);
|
||||
}
|
||||
}
|
||||
|
||||
const QQuaternion &IWorld::cameraRatation() const {
|
||||
return _cameraRatation;
|
||||
}
|
||||
@ -377,8 +391,12 @@ const QVector3D &IWorld::cameraReleativePosition() const {
|
||||
return _cameraReleativePosition;
|
||||
}
|
||||
|
||||
void IWorld::worldChanged(WorldObjects objects) {
|
||||
void IWorld::worldChanged(WorldRule::const_iterator iterator) {
|
||||
|
||||
if (_currendWorldLevel == iterator)
|
||||
return;
|
||||
|
||||
auto objects = iterator.value();
|
||||
objects[_player->className()] = 1;
|
||||
|
||||
for (auto it = objects.begin(); it != objects.end(); ++it) {
|
||||
@ -395,6 +413,8 @@ void IWorld::worldChanged(WorldObjects objects) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_currendWorldLevel = iterator;
|
||||
}
|
||||
|
||||
int IWorld::wordlStatus() const {
|
||||
|
@ -276,6 +276,13 @@ signals:
|
||||
*/
|
||||
void hdrChanged();
|
||||
|
||||
/**
|
||||
* @brief sigWorldChanged emit this signal if you want to change level of the world.
|
||||
* @note this signal needed for the move WorldChange method into main thread.
|
||||
* @param objects this is iterator of the world rule object.
|
||||
*/
|
||||
void sigWorldChanged(WorldRule::const_iterator objects);
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
@ -369,6 +376,11 @@ protected:
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief updateWorld This method check current distance and load neede level and level objects.
|
||||
*/
|
||||
void updateWorld();
|
||||
|
||||
private slots:
|
||||
|
||||
/**
|
||||
@ -376,6 +388,13 @@ private slots:
|
||||
*/
|
||||
void handleStop();
|
||||
|
||||
/**
|
||||
* @brief worldChanged This method generate diff for the qml
|
||||
* @param objects This is iterator of the world rules object that contains list of object on lvl
|
||||
* @note This method addd player object to this list.
|
||||
*/
|
||||
void worldChanged(WorldRule::const_iterator objects);
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief prepare This method initialize world object.
|
||||
@ -383,6 +402,10 @@ private:
|
||||
* @return true if world initialized successful
|
||||
*/
|
||||
bool prepare();
|
||||
|
||||
/**
|
||||
* @brief reset This method reset all world objects.
|
||||
*/
|
||||
void reset();
|
||||
|
||||
|
||||
@ -399,12 +422,8 @@ private:
|
||||
void setRunning(bool newRunning);
|
||||
|
||||
/**
|
||||
* @brief worldChanged This method generate diff for the qml
|
||||
* @param objects This is list of object on lvl
|
||||
* @note This method addd player object to this list.
|
||||
* @brief clearItems This method remove all created items from world.
|
||||
*/
|
||||
void worldChanged(WorldObjects objects);
|
||||
|
||||
void clearItems();
|
||||
|
||||
/**
|
||||
@ -472,6 +491,8 @@ private:
|
||||
|
||||
QString _hdrMap;
|
||||
WorldRule *_worldRules = nullptr;
|
||||
WorldRule::const_iterator _currendWorldLevel;
|
||||
|
||||
IPlayer *_player = nullptr;
|
||||
IControl *_userInterface = nullptr;
|
||||
IAI *_backgroundAI = nullptr;
|
||||
|
@ -89,7 +89,9 @@ View3D {
|
||||
|
||||
for (var i = 0; i < arrayObjects.length; ++i) {
|
||||
if (id === arrayObjects[i].guiId) {
|
||||
arrayObjects[i].destroy();
|
||||
arrayObjects.splice(i,1);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
24
src/JungleLvl/private/grees.cpp
Normal file
24
src/JungleLvl/private/grees.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
//#
|
||||
//# 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 "grees.h"
|
||||
|
||||
namespace JungleLvl {
|
||||
|
||||
Grees::Grees(): CRAWL::IWorldItem(AUTO_CLASS_NAME) {
|
||||
setMash("qrc:/mesh/meshes/Plant/Grass.mesh");
|
||||
setBaseColorMap("qrc:/mesh/meshes/Plant/Grass_Base.jpg");
|
||||
setSize({1,1,1});
|
||||
setRatation(QQuaternion::fromEulerAngles({0,0, static_cast<float>(rand() % 360)}));
|
||||
|
||||
}
|
||||
|
||||
void Grees::onIntersects(const IWorldItem *) {
|
||||
|
||||
}
|
||||
|
||||
}
|
32
src/JungleLvl/private/grees.h
Normal file
32
src/JungleLvl/private/grees.h
Normal file
@ -0,0 +1,32 @@
|
||||
//#
|
||||
//# 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 GREES_H
|
||||
#define GREES_H
|
||||
|
||||
#include <Crawl/iworlditem.h>
|
||||
#include <jungle_global.h>
|
||||
|
||||
namespace JungleLvl {
|
||||
|
||||
/**
|
||||
* @brief The Grees class
|
||||
*/
|
||||
class CRAWL_JUNGLE_LEVEL_EXPORT Grees: public CRAWL::IWorldItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Grees();
|
||||
|
||||
// IWorldItem interface
|
||||
protected:
|
||||
void onIntersects(const IWorldItem *item) override;
|
||||
};
|
||||
}
|
||||
#endif // GREES_H
|
21
src/JungleLvl/private/longgress.cpp
Normal file
21
src/JungleLvl/private/longgress.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
//#
|
||||
//# 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 "longgress.h"
|
||||
namespace JungleLvl {
|
||||
|
||||
LongGress::LongGress(): CRAWL::IWorldItem(AUTO_CLASS_NAME) {
|
||||
setMash("qrc:/mesh/meshes/Plant/Long_grass.mesh");
|
||||
setBaseColorMap("qrc:/mesh/meshes/Plant/LongGrass_Base.jpg");
|
||||
setSize({1,1,1});
|
||||
setRatation(QQuaternion::fromEulerAngles({0,0, static_cast<float>(rand() % 360)}));
|
||||
}
|
||||
|
||||
void LongGress::onIntersects(const IWorldItem *) {
|
||||
|
||||
}
|
||||
}
|
32
src/JungleLvl/private/longgress.h
Normal file
32
src/JungleLvl/private/longgress.h
Normal file
@ -0,0 +1,32 @@
|
||||
//#
|
||||
//# 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 LONGGRESS_H
|
||||
#define LONGGRESS_H
|
||||
|
||||
#include <Crawl/iworlditem.h>
|
||||
#include <jungle_global.h>
|
||||
|
||||
|
||||
namespace JungleLvl {
|
||||
|
||||
class CRAWL_JUNGLE_LEVEL_EXPORT LongGress: public CRAWL::IWorldItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
LongGress();
|
||||
|
||||
// IWorldItem interface
|
||||
protected:
|
||||
void onIntersects(const IWorldItem *item) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // LONGGRESS_H
|
37
src/JungleLvl/private/tree.cpp
Normal file
37
src/JungleLvl/private/tree.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
//#
|
||||
//# 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 "tree.h"
|
||||
namespace JungleLvl {
|
||||
|
||||
Tree::Tree(): CRAWL::IWorldItem(AUTO_CLASS_NAME) {
|
||||
|
||||
QStringList mashes {
|
||||
"qrc:/mesh/meshes/Plant/Tree_1.mesh",
|
||||
"qrc:/mesh/meshes/Plant/Tree_2.mesh",
|
||||
"qrc:/mesh/meshes/Plant/Tree_3.mesh",
|
||||
"qrc:/mesh/meshes/Plant/Tree_4.mesh",
|
||||
"qrc:/mesh/meshes/Plant/Tree_5.mesh",
|
||||
"qrc:/mesh/meshes/Plant/Tree_6.mesh",
|
||||
|
||||
};
|
||||
|
||||
setMash(mashes[rand() % mashes.size()]);
|
||||
setBaseColorMap("qrc:/mesh/meshes/Plant/Tree_Base.jpg");
|
||||
setSize({1,1,1});
|
||||
setRatation(QQuaternion::fromEulerAngles({static_cast<float>(rand() % 60 - 30),
|
||||
static_cast<float>(rand() % 60 - 30),
|
||||
static_cast<float>(rand() % 360)}));
|
||||
|
||||
if (rand() % 2)
|
||||
setZ(-static_cast<float>(rand() % 10));
|
||||
}
|
||||
|
||||
void Tree::onIntersects(const IWorldItem *) {
|
||||
|
||||
}
|
||||
}
|
30
src/JungleLvl/private/tree.h
Normal file
30
src/JungleLvl/private/tree.h
Normal file
@ -0,0 +1,30 @@
|
||||
//#
|
||||
//# 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 TREE_H
|
||||
#define TREE_H
|
||||
|
||||
#include <Crawl/iworlditem.h>
|
||||
#include <jungle_global.h>
|
||||
|
||||
namespace JungleLvl {
|
||||
|
||||
/**
|
||||
* @brief The Tree class
|
||||
*/
|
||||
class CRAWL_JUNGLE_LEVEL_EXPORT Tree : public CRAWL::IWorldItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Tree();
|
||||
|
||||
// IWorldItem interface
|
||||
protected:
|
||||
void onIntersects(const IWorldItem *) override;
|
||||
};
|
||||
}
|
||||
#endif // TREE_H
|
@ -5,8 +5,11 @@
|
||||
//# of this license document, but changing it is not allowed.
|
||||
//#
|
||||
|
||||
#include "grees.h"
|
||||
#include "ground.h"
|
||||
#include "longgress.h"
|
||||
#include "snake.h"
|
||||
#include "tree.h"
|
||||
#include "world.h"
|
||||
#include "Crawl/iworlditem.h"
|
||||
|
||||
@ -21,7 +24,21 @@ World::World() {
|
||||
CRAWL::WorldRule *World::initWorldRules() {
|
||||
return new CRAWL::WorldRule {
|
||||
{0, {
|
||||
{registerObject<Ground>(), 1}}}
|
||||
{registerObject<Ground>(), 1},
|
||||
{registerObject<Grees>(), 500},
|
||||
{registerObject<LongGress>(), 100},
|
||||
{registerObject<Tree>(), 0}
|
||||
|
||||
}
|
||||
},
|
||||
{500, {
|
||||
{registerObject<Ground>(), 1},
|
||||
{registerObject<Grees>(), 500},
|
||||
{registerObject<LongGress>(), 100},
|
||||
{registerObject<Tree>(), 100}
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user