From eb47a93a24344cd2cbaf385c821bd0d671ff8d79 Mon Sep 17 00:00:00 2001 From: mattrwang Date: Thu, 17 Oct 2024 22:44:46 -0400 Subject: [PATCH] added snake button to home menu --- NERODevelopment/content/CMakeLists.txt | 3 ++ NERODevelopment/content/HomeMenuItem.qml | 2 +- .../content/NavigationController.qml | 13 +++++- NERODevelopment/content/Snake.qml | 46 +++++++++++++++++++ NERODevelopment/content/SnakeBody.qml | 17 +++++++ NERODevelopment/content/SnakeFood.qml | 17 +++++++ .../src/controllers/navigationcontroller.h | 2 +- 7 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 NERODevelopment/content/Snake.qml create mode 100644 NERODevelopment/content/SnakeBody.qml create mode 100644 NERODevelopment/content/SnakeFood.qml diff --git a/NERODevelopment/content/CMakeLists.txt b/NERODevelopment/content/CMakeLists.txt index c18a9d9..904fff3 100644 --- a/NERODevelopment/content/CMakeLists.txt +++ b/NERODevelopment/content/CMakeLists.txt @@ -47,6 +47,9 @@ qt6_add_qml_module(content Arrow.qml OffScreen2.qml StatusDisplay.qml + Snake.qml + SnakeBody.qml + SnakeFood.qml RESOURCES fonts/fonts.txt diff --git a/NERODevelopment/content/HomeMenuItem.qml b/NERODevelopment/content/HomeMenuItem.qml index 926ae7e..6f34399 100644 --- a/NERODevelopment/content/HomeMenuItem.qml +++ b/NERODevelopment/content/HomeMenuItem.qml @@ -13,7 +13,7 @@ Rectangle { LabelText { id: label padding: 8 - font.pixelSize: 16 + font.pixelSize: 12 text: parent.text } } diff --git a/NERODevelopment/content/NavigationController.qml b/NERODevelopment/content/NavigationController.qml index 4e11906..b5e6268 100644 --- a/NERODevelopment/content/NavigationController.qml +++ b/NERODevelopment/content/NavigationController.qml @@ -7,7 +7,7 @@ Item { focus: !navigation.isSelected property int selectedPageIndex: navigationController.selectedPageIndex property bool isSelected: navigationController.isSelected - property int exitPageIndex: 7 + property int exitPageIndex: 8 property int offPageIndex: 0 property int pitPageIndex: 1 property int speedPageIndex: 2 @@ -15,6 +15,7 @@ Item { property int debugPageIndex: 4 property int configurationPageIndex: 5 property int flappyPageIndex: 6 + property int snakePageIndex: 7 Keys.onPressed: event => { console.log(navigationController.isSelected, @@ -89,6 +90,11 @@ Item { text: "Flappy Bird" } + HomeMenuItem { + highlighted: selectedPageIndex === snakePageIndex + text: "Snake" + } + HomeMenuItem { highlighted: selectedPageIndex === exitPageIndex text: "Exit" @@ -129,4 +135,9 @@ Item { visible: selectedPageIndex === flappyPageIndex && isSelected isFocused: selectedPageIndex === flappyPageIndex && isSelected } + + Snake { + visible: selectedPageIndex === snakePageIndex && isSelected + isFocused: selectedPageIndex === snakePageIndex && isSelected + } } diff --git a/NERODevelopment/content/Snake.qml b/NERODevelopment/content/Snake.qml new file mode 100644 index 0000000..49be328 --- /dev/null +++ b/NERODevelopment/content/Snake.qml @@ -0,0 +1,46 @@ +import QtQuick 2.15 +import QtQuick.Controls 2.15 + +Rectangle { + id: snake + + anchors.fill: parent + focus: snake.isFocused + visible: true + + property bool isFocused: false + + width: 800 + height: 480 + color: "black" + + property int minX: 200 + property int maxX: 600 + property int minY: 40 + property int maxY: 440 + + property var snakeBody: [{"x": 300, "y": 300}, {"x": 280, "y": 300}, {"x": 260, "y": 300}] + property int segmentSize: 20 + property string direction: "right" + + property int score: 0 + + Rectangle { + width: 400 + height: 400 + anchors.centerIn: parent + border.color: "white" + border.width: 2 + color: "transparent" + } + + Text { + id: scoreText + text: "Score: " + snake.score + font.pixelSize: 24 + color: "white" + anchors.top: parent.top + anchors.horizontalCenter: parent.horizontalCenter + anchors.topMargin: 10 + } +} diff --git a/NERODevelopment/content/SnakeBody.qml b/NERODevelopment/content/SnakeBody.qml new file mode 100644 index 0000000..6283614 --- /dev/null +++ b/NERODevelopment/content/SnakeBody.qml @@ -0,0 +1,17 @@ +import QtQuick 2.15 +import QtQuick.Controls 2.15 + +Item { + id: food + property int dimension: 20 + + width: dimension + height: dimension + + Rectangle { + id: foodColor + height: dimension + width: dimension + color: "lime" + } +} diff --git a/NERODevelopment/content/SnakeFood.qml b/NERODevelopment/content/SnakeFood.qml new file mode 100644 index 0000000..43852a6 --- /dev/null +++ b/NERODevelopment/content/SnakeFood.qml @@ -0,0 +1,17 @@ +import QtQuick 2.15 +import QtQuick.Controls 2.15 + +Item { + id: food + property int dimension: 20 + + width: dimension + height: dimension + + Rectangle { + id: foodColor + height: dimension + width: dimension + color: "red" + } +} diff --git a/NERODevelopment/src/controllers/navigationcontroller.h b/NERODevelopment/src/controllers/navigationcontroller.h index 0c6d8c3..2f448e5 100644 --- a/NERODevelopment/src/controllers/navigationcontroller.h +++ b/NERODevelopment/src/controllers/navigationcontroller.h @@ -34,7 +34,7 @@ public slots: private: bool m_isSelected = false; int m_selectedPageIndex = 0; - int m_numPages = 8; + int m_numPages = 9; }; #endif // NAVIGATIONCONTROLLER_H