mirror of
https://github.com/QuasarApp/Snake.git
synced 2025-04-29 03:04:42 +00:00
updare resources
This commit is contained in:
parent
c6fb56513d
commit
e82ad370a1
@ -29,6 +29,10 @@ Snake::Snake(const QString &name, const QString &viewTempalte, QObject *ptr):
|
|||||||
setScales({{0, 0.8},
|
setScales({{0, 0.8},
|
||||||
{0.4, 1.2},
|
{0.4, 1.2},
|
||||||
{1, 0.5}});
|
{1, 0.5}});
|
||||||
|
|
||||||
|
setLengthBetwinItemsMap({{0, 0.8},
|
||||||
|
{0.4, 1.2},
|
||||||
|
{1, 0.5}});
|
||||||
}
|
}
|
||||||
|
|
||||||
Snake::~Snake( ){
|
Snake::~Snake( ){
|
||||||
@ -86,43 +90,65 @@ void Snake::onTap() {
|
|||||||
setMovableVector(_vectors[_clickIndex++ % 2]);
|
setMovableVector(_vectors[_clickIndex++ % 2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Snake::generateItems() {
|
float CRAWL::Snake::getValueFromMap(const QMap<float, float> &map,
|
||||||
|
float position,
|
||||||
auto scaleIt = _scales.begin();
|
float defaultValue) {
|
||||||
|
auto it = map.cbegin();
|
||||||
|
|
||||||
float from = 0, fromKey = 0;
|
float from = 0, fromKey = 0;
|
||||||
float to = scaleIt.value(), toKey = scaleIt.key();
|
float to = it.value(), toKey = it.key();
|
||||||
|
|
||||||
|
if (it != _scales.cend()) {
|
||||||
|
while (position >= it.key() && it != _scales.cend()) {
|
||||||
|
it++;
|
||||||
|
|
||||||
|
if (it != _scales.cend()) {
|
||||||
|
from = to;
|
||||||
|
to = it.value();
|
||||||
|
fromKey = toKey;
|
||||||
|
toKey = it.key();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ((position - fromKey) * toKey / (to - from)) + from;
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Snake::generateItems() {
|
||||||
|
|
||||||
for(unsigned int i = 0; i < itemsCount(); ++i) {
|
for(unsigned int i = 0; i < itemsCount(); ++i) {
|
||||||
|
|
||||||
auto item = factory();
|
SnakeItem* item = dynamic_cast<SnakeItem*>(factory());
|
||||||
|
|
||||||
if (!item)
|
if (!item) {
|
||||||
|
QuasarAppUtils::Params::log("The snake item class should be child class"
|
||||||
|
" of the SnakeItem class.",
|
||||||
|
QuasarAppUtils::Error);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
float scale = 1;
|
|
||||||
if (scaleIt != _scales.end()) {
|
|
||||||
float position = static_cast<float>(i) / itemsCount();
|
|
||||||
while (position >= scaleIt.key() && scaleIt != _scales.end()) {
|
|
||||||
scaleIt++;
|
|
||||||
|
|
||||||
if (scaleIt != _scales.end()) {
|
|
||||||
from = to;
|
|
||||||
to = scaleIt.value();
|
|
||||||
fromKey = toKey;
|
|
||||||
toKey = scaleIt.key();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
scale = ((position - fromKey) * toKey / (to - from)) + from;
|
float scale = getValueFromMap(_scales,
|
||||||
}
|
static_cast<float>(i) / itemsCount());
|
||||||
|
float lengthBIt = getValueFromMap(_lengthBetwinItemsMap,
|
||||||
|
static_cast<float>(i) / itemsCount());
|
||||||
|
|
||||||
item->setSize(item->size() * scale);
|
item->setSize(item->size() * scale);
|
||||||
|
item->setLengthBetwinItems(lengthBIt);
|
||||||
|
|
||||||
add(item);
|
add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QMap<float, float> &Snake::lengthBetwinItemsMap() const {
|
||||||
|
return _lengthBetwinItemsMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Snake::setLengthBetwinItemsMap(const QMap<float, float> &newLengthBetwinItemsMap) {
|
||||||
|
_lengthBetwinItemsMap = newLengthBetwinItemsMap;
|
||||||
|
}
|
||||||
|
|
||||||
float Snake::speed() const {
|
float Snake::speed() const {
|
||||||
return _speed;
|
return _speed;
|
||||||
}
|
}
|
||||||
|
@ -81,6 +81,39 @@ public:
|
|||||||
|
|
||||||
unsigned int itemsCount() const override;
|
unsigned int itemsCount() const override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief lengthBetwinItemsMap This method return map with lengths betwin items.
|
||||||
|
* The key of map are position of snake Body and the value are length betwin this current and parent items.
|
||||||
|
* The default map of snake are:
|
||||||
|
* ```
|
||||||
|
* 0.0 - 0.8
|
||||||
|
* 0.6 - 1.2
|
||||||
|
* 1 - 0.5
|
||||||
|
* ```
|
||||||
|
* @return length betwin items map of snake body.
|
||||||
|
*/
|
||||||
|
const QMap<float, float> &lengthBetwinItemsMap() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief setLengthBetwinItemsMap This method sets new valud of the length betwin items map.
|
||||||
|
* @param newLengthBetwinItemsMap this is new value of the length betwin tems map.
|
||||||
|
* @note for get more information see the lengthBetwinItemsMap method.
|
||||||
|
*/
|
||||||
|
void setLengthBetwinItemsMap(const QMap<float, float> &newLengthBetwinItemsMap);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief getValueFromMap This method return near value from the map by position.
|
||||||
|
* @param map This is map that contains list of the values.
|
||||||
|
* @param position This requried position from map.
|
||||||
|
* @param defaultValue This value will be returned when map are empty.
|
||||||
|
* @return near value of the requried position.
|
||||||
|
*
|
||||||
|
* @note This function works as a gradient.
|
||||||
|
*/
|
||||||
|
float getValueFromMap(const QMap<float, float> &map,
|
||||||
|
float position,
|
||||||
|
float defaultValue = 1);
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void onTap() override;
|
void onTap() override;
|
||||||
|
|
||||||
@ -88,7 +121,9 @@ protected slots:
|
|||||||
private:
|
private:
|
||||||
void generateItems() override;
|
void generateItems() override;
|
||||||
|
|
||||||
|
|
||||||
QMap<float, float> _scales;
|
QMap<float, float> _scales;
|
||||||
|
QMap<float, float> _lengthBetwinItemsMap;
|
||||||
|
|
||||||
float _lengthBetwinItems;
|
float _lengthBetwinItems;
|
||||||
const IWorldItem* _lastSnakeItem = nullptr;
|
const IWorldItem* _lastSnakeItem = nullptr;
|
||||||
|
@ -32,9 +32,9 @@ void SnakeItem::render(unsigned int tbfMsec) {
|
|||||||
if (auto claster = static_cast<Snake*>(parentClaster())) {
|
if (auto claster = static_cast<Snake*>(parentClaster())) {
|
||||||
float ratationLength = ratationVector.length();
|
float ratationLength = ratationVector.length();
|
||||||
|
|
||||||
if (ratationLength > claster->lengthBetwinItems() * 10) {
|
if (ratationLength > lengthBetwinItems() * 10) {
|
||||||
setposition(_prevObject->position());
|
setposition(_prevObject->position());
|
||||||
} else if (ratationLength > claster->lengthBetwinItems()) {
|
} else if (ratationLength > lengthBetwinItems()) {
|
||||||
setMovableVector(ratationVector.normalized() * claster->currentMovableVector().length());
|
setMovableVector(ratationVector.normalized() * claster->currentMovableVector().length());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -45,4 +45,12 @@ void SnakeItem::render(unsigned int tbfMsec) {
|
|||||||
const IWorldItem * SnakeItem::prev() const {
|
const IWorldItem * SnakeItem::prev() const {
|
||||||
return _prevObject;
|
return _prevObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float SnakeItem::lengthBetwinItems() const {
|
||||||
|
return _lengthBetwinItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SnakeItem::setLengthBetwinItems(float newLengthBetwinItems) {
|
||||||
|
_lengthBetwinItems = newLengthBetwinItems;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,8 +36,22 @@ public:
|
|||||||
*/
|
*/
|
||||||
const IWorldItem * prev() const;
|
const IWorldItem * prev() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief lengthBetwinItems This method return current length betwin current and parew item.
|
||||||
|
* @return current length betwin current and parew item.
|
||||||
|
* @note See also the setPrev method.
|
||||||
|
*/
|
||||||
|
float lengthBetwinItems() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief setLengthBetwinItems This method sets new valeu of the length betwin current and parew item.
|
||||||
|
* @param newLengthBetwinItems This is new value of the length betwin current and parew item.
|
||||||
|
*/
|
||||||
|
void setLengthBetwinItems(float newLengthBetwinItems);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const IWorldItem *_prevObject = nullptr;
|
const IWorldItem *_prevObject = nullptr;
|
||||||
|
float _lengthBetwinItems = 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ Model {
|
|||||||
|
|
||||||
PrincipledMaterial {
|
PrincipledMaterial {
|
||||||
id: objMaterial
|
id: objMaterial
|
||||||
|
roughness : 1
|
||||||
baseColorMap: Texture {
|
baseColorMap: Texture {
|
||||||
source: (model)? model.baseColorMap: ""
|
source: (model)? model.baseColorMap: ""
|
||||||
tilingModeHorizontal: (tilies > 1)? Texture.Repeat : Texture.ClampToEdge
|
tilingModeHorizontal: (tilies > 1)? Texture.Repeat : Texture.ClampToEdge
|
||||||
|
@ -27,11 +27,11 @@ View3D {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PointLight {
|
DirectionalLight {
|
||||||
position: camera.position
|
position: Qt.vector3d(10000, 0, 10000);
|
||||||
rotation: camera.rotation
|
rotation: camera.rotation
|
||||||
|
|
||||||
brightness: 250
|
brightness: 120
|
||||||
}
|
}
|
||||||
|
|
||||||
environment: SceneEnvironment {
|
environment: SceneEnvironment {
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 1f2571634d50dd8791f59b0707cc037a435f9fdb
|
Subproject commit a2dee2c0f82b7af35d55fbfda903697de02bbb26
|
@ -15,6 +15,8 @@ GroundPlate::GroundPlate(): CRAWL::GroundTile("JungleGroundTile",
|
|||||||
setSize({6, 6, 0.01});
|
setSize({6, 6, 0.01});
|
||||||
setBaseColorMap("qrc:/mesh/meshes/Other/Terrain_Base.jpg");
|
setBaseColorMap("qrc:/mesh/meshes/Other/Terrain_Base.jpg");
|
||||||
setNormalMap("qrc:/mesh/meshes/Other/Terrain_Normal.jpg");
|
setNormalMap("qrc:/mesh/meshes/Other/Terrain_Normal.jpg");
|
||||||
|
// setRoughnessMap("qrc:/mesh/meshes/Other/Roughness_without.jpg");
|
||||||
|
// setEmissiveMap("qrc:/mesh/meshes/Other/Emission_without.jpg");
|
||||||
setTiliesCount(6);
|
setTiliesCount(6);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,15 +11,31 @@
|
|||||||
namespace JungleLvl {
|
namespace JungleLvl {
|
||||||
|
|
||||||
Snake::Snake(): CRAWL::Snake("JungleSnake") {
|
Snake::Snake(): CRAWL::Snake("JungleSnake") {
|
||||||
|
setBreakingForce(50);
|
||||||
|
setAngularVelocity(100);
|
||||||
|
|
||||||
registerItemType<JungleLvl::SnakeItem>();
|
registerItemType<JungleLvl::SnakeItem>();
|
||||||
setMash("qrc:/mesh/meshes/Other/Snake_head.mesh");
|
setMash("qrc:/mesh/meshes/Other/Snake_head.mesh");
|
||||||
setBaseColorMap("qrc:/mesh/meshes/Other/Snake_Base.jpg");
|
setBaseColorMap("qrc:/mesh/meshes/Other/Snake_Base.jpg");
|
||||||
setSize({1.5,1.5,1.5});
|
setSize({1,1,1});
|
||||||
setStaticRotation(QQuaternion::fromEulerAngles(0,90,-90));
|
setStaticRotation(QQuaternion::fromEulerAngles(0,0,0));
|
||||||
|
|
||||||
|
|
||||||
|
setScales({{0, 0.9},
|
||||||
|
{0.4, 1.2},
|
||||||
|
{1, 0.5}});
|
||||||
|
|
||||||
|
setLengthBetwinItemsMap({{0, 4.5},
|
||||||
|
{0.01, 1},
|
||||||
|
{0.4, 1.5},
|
||||||
|
{1, 0.5}});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Snake::onIntersects(const IWorldItem *) {
|
void Snake::onIntersects(const IWorldItem *) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int Snake::itemsCount() const {
|
||||||
|
return 35;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,8 @@ public:
|
|||||||
// IWorldItem interface
|
// IWorldItem interface
|
||||||
protected:
|
protected:
|
||||||
void onIntersects(const IWorldItem *) override;
|
void onIntersects(const IWorldItem *) override;
|
||||||
|
unsigned int itemsCount() const override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ namespace JungleLvl {
|
|||||||
SnakeItem::SnakeItem(): CRAWL::SnakeItem("JungleSnakeItem") {
|
SnakeItem::SnakeItem(): CRAWL::SnakeItem("JungleSnakeItem") {
|
||||||
setMash("qrc:/mesh/meshes/Other/Snake_body.mesh");
|
setMash("qrc:/mesh/meshes/Other/Snake_body.mesh");
|
||||||
setBaseColorMap("qrc:/mesh/meshes/Other/Snake_Base.jpg");
|
setBaseColorMap("qrc:/mesh/meshes/Other/Snake_Base.jpg");
|
||||||
setSize({2,2,2});
|
setSize({1.5,1.5,1.5});
|
||||||
}
|
}
|
||||||
|
|
||||||
void SnakeItem::init() {
|
void SnakeItem::init() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user