diff --git a/back-end/controller.cpp b/back-end/controller.cpp index d365823..0474ad5 100644 --- a/back-end/controller.cpp +++ b/back-end/controller.cpp @@ -15,10 +15,12 @@ bool Controller::nextLvl() { if (lvl + 1 >= lvls.size()) { return true; } + m_generalLong += static_cast(world.getCurrentLong()); generateDiff(world.init(lvls.value(++lvl))); startTimer(); + return false; } @@ -62,6 +64,8 @@ void Controller::update() { } long_changed(static_cast(world.getCurrentLong())); + generalLongchanged(generalLong()); + } void Controller::newGame() { @@ -70,6 +74,7 @@ void Controller::newGame() { WorldRules newGameRules = lvls.first(); lvl = 0; + m_generalLong = 0; generateDiff(world.init(newGameRules)); startTimer(); } @@ -90,11 +95,18 @@ int Controller::long_() const { return static_cast(world.getCurrentLong()); } +int Controller::generalLong() const { + return m_generalLong + long_(); +} + void Controller::buttonPress() { world.reversClick(); } void Controller::setPause(bool p){ pause = p; + if (!pause) { + world.unPause(); + } } diff --git a/back-end/controller.h b/back-end/controller.h index b8e933a..a1f0d3e 100644 --- a/back-end/controller.h +++ b/back-end/controller.h @@ -13,6 +13,7 @@ class Controller : public QObject Q_OBJECT Q_PROPERTY(int long_ READ long_ NOTIFY long_changed) + Q_PROPERTY(int generalLong READ generalLong NOTIFY generalLongchanged) private: World world; @@ -22,6 +23,9 @@ private: QMap objectsContainer; void generateDiff(const QMap &); + + int m_generalLong = 0; + public: Controller(); void startTimer(); @@ -29,6 +33,8 @@ public: int long_() const; + int generalLong() const; + public slots: void buttonPress(); @@ -69,6 +75,7 @@ signals: */ void gameObjectsChanged(const Diff &dif); void long_changed(int m_long); + void generalLongchanged(int generalLong); }; #endif // CONTROLLER_H diff --git a/back-end/head.cpp b/back-end/head.cpp index 812f821..64583df 100644 --- a/back-end/head.cpp +++ b/back-end/head.cpp @@ -13,19 +13,19 @@ void Head::render() { if (*speed < 1) { setColor(generalSpeadColor); - setRadius(static_cast(m_w * 0.0)); + setRadius(static_cast(m_w * 0.1)); } else if (*speed < normSpead) { setColor(normSpeadColor); - setRadius(static_cast(m_w * 0.15)); + setRadius(static_cast(m_w * 0.2)); } else if (*speed < fastSpead) { setColor(fastSpeadColor); - setRadius(static_cast(m_w * 0.35)); + setRadius(static_cast(m_w * 0.3)); } else if (*speed < megaFastSpead) { setColor(megaFastSpeadColor); - setRadius(static_cast(m_w * 0.5)); + setRadius(static_cast(m_w * 0.4)); } @@ -35,6 +35,10 @@ void Head::render() { void Head::reset() { } +void Head::unPause() { + time = QDateTime::currentMSecsSinceEpoch(); +} + Head::Head(double x, double y, double h, double w, double *spead): GuiObject ("SnakeItem") { setX(x); diff --git a/back-end/head.h b/back-end/head.h index 6a434d4..47fb207 100644 --- a/back-end/head.h +++ b/back-end/head.h @@ -25,6 +25,7 @@ public: void setAngle(double angle) override; void render() override; void reset() override; + void unPause(); ~Head() override; }; diff --git a/back-end/snake.cpp b/back-end/snake.cpp index f57d03b..e7cd1b9 100644 --- a/back-end/snake.cpp +++ b/back-end/snake.cpp @@ -15,6 +15,14 @@ const QVector &Snake::getItems() const { void Snake::render() { + auto centerX = [](const Head* head) { + return head->x()/* + (head->w() / 2)*/; + }; + + auto centerY = [](const Head* head) { + return head->y() /*+ (head->h() / 2)*/; + }; + for (int i = items.length() - 1; i >= 0; --i) { if (dead) { @@ -31,9 +39,10 @@ void Snake::render() { } isClick = false; } - }else { - double _atan2 = atan2(items[i - 1]->rect().center().y() - items[i]->rect().center().y(), - items[i - 1]->rect().center().x() - items[i]->rect().center().x()) * 180; + } else { + + double _atan2 = atan2(centerY(items[i - 1]) - centerY(items[i]), + centerX(items[i - 1]) - centerX(items[i])) * 180; items[i]->setAngle(_atan2); } @@ -59,6 +68,12 @@ void Snake::setRataticonDistance(double value) { rataticonDistance = value; } +void Snake::unPause() { + for ( int i = 0; i < items.size(); ++i ) { + items[i]->unPause(); + } +} + double Snake::sizeByLvl(double lvl , int count) const { double maxSize = 9; double minSize = 5; @@ -66,34 +81,32 @@ double Snake::sizeByLvl(double lvl , int count) const { double pos = (1 - (lvl / count)); QList> snakeGradientSize { - {1, 4}, - {0.9, 7}, - {0.7, 5}, - {0.5, 6}, + {1, 5}, + {0.99, 7}, + {0.9, 5}, + {0.8, 6}, {0.0, 3} }; - double localPos = 0; + double local = 0; int index = 0; while (index + 1 < snakeGradientSize.size() && pos <= snakeGradientSize[index].first) { - maxSize = std::max(snakeGradientSize[index].second, - snakeGradientSize[index + 1].second); + maxSize = snakeGradientSize[index].second; + minSize = snakeGradientSize[index + 1].second; - minSize = std::min(snakeGradientSize[index].second, - snakeGradientSize[index + 1].second); + auto range = snakeGradientSize[index].first - + snakeGradientSize[index + 1].first; - auto range = snakeGradientSize[index].first - snakeGradientSize[index + 1].first; - - localPos = ( range - (snakeGradientSize[index].first - pos)) / + local = ( range - (snakeGradientSize[index].first - pos)) / range; index++; } - return localPos * (maxSize - minSize) + minSize; + return local * (maxSize - minSize) + minSize; } void Snake::changeCountObjects(int count) { diff --git a/back-end/snake.h b/back-end/snake.h index fe4d8bc..b919028 100644 --- a/back-end/snake.h +++ b/back-end/snake.h @@ -46,6 +46,7 @@ public: void setRataticonDistance(double value); int getDeadTimer() const; void setDeadTimer(int value); + void unPause(); }; #endif // SNAKE_H diff --git a/back-end/world.cpp b/back-end/world.cpp index d572aa8..62f799c 100644 --- a/back-end/world.cpp +++ b/back-end/world.cpp @@ -27,6 +27,11 @@ QMultiMap World::getItems() const return items; } +void World::unPause() { + time = QDateTime::currentMSecsSinceEpoch(); + snake.unPause(); +} + void World::clearItems() { for (auto i : items) { delete i; diff --git a/back-end/world.h b/back-end/world.h index b01c56b..e760ed6 100644 --- a/back-end/world.h +++ b/back-end/world.h @@ -42,6 +42,7 @@ public: void reversClick(); double getCurrentLong() const; QMultiMap getItems() const; + void unPause(); }; #endif // WORLD_H diff --git a/front-end/Scene.qml b/front-end/Scene.qml index 465177e..e8820ca 100644 --- a/front-end/Scene.qml +++ b/front-end/Scene.qml @@ -26,6 +26,8 @@ Item { property var model: (contr)? contr: null; property var arrayObjects: [] property bool showMenu: false + property bool isPause: false + function add (cppObjId) { if (!model) { console.log("create object fail") @@ -44,7 +46,7 @@ Item { if (temp.status === Component.Ready) { var obj = temp.createObject(parent) // parent - это обьект на который будет помещен соззданный элемент obj.model = model.getGameObject(cppObjId); - obj.z = -1; + obj.z = -2; arrayObjects.push(obj) } else { console.log("wrong viewTemplate in model"); @@ -186,20 +188,56 @@ Item { anchors.topMargin: point z: 1 + onClicked: { + showMenu = true; + } + visible: !showMenu } Button { id: pause - text: "||" + text: (isPause)? "▶" :"||" anchors.left: returnToMenu.right anchors.leftMargin: point anchors.top: parent.top anchors.topMargin: point - z: 1 + z: returnToMenu.z + + onClicked: { + isPause = !isPause; + if (model) model.setPause(isPause); + } + + visible: !showMenu + + } + + Button { + id: long_ + Label { + anchors.fill: parent; + + textFormat: Text.AutoText + verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignHCenter + wrapMode: Text.WordWrap + + text: qsTr("lvl long: ") + ((model)? model.long_: "0") + } + + width: 35 * point; + height: pause.height; + + anchors.left: pause.right + anchors.leftMargin: point + + anchors.top: parent.top + anchors.topMargin: point + z: returnToMenu.z visible: !showMenu @@ -214,18 +252,18 @@ Item { horizontalAlignment: Text.AlignHCenter wrapMode: Text.WordWrap - text: qsTr("long: ") + (model)? model.long_: "0" + text: qsTr("general long: ") + ((model)? model.generalLong: "0") } - width: 15 * point; - height: pause.height; + width: 35 * point; + height: long_.height; - anchors.left: pause.right + anchors.left: long_.right anchors.leftMargin: point anchors.top: parent.top anchors.topMargin: point - z: 1 + z: returnToMenu.z visible: !showMenu