Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added snake button to home menu #121

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NERODevelopment/content/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion NERODevelopment/content/HomeMenuItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Rectangle {
LabelText {
id: label
padding: 8
font.pixelSize: 16
font.pixelSize: 12
text: parent.text
}
}
13 changes: 12 additions & 1 deletion NERODevelopment/content/NavigationController.qml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ 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
property int efficiencyPageIndex: 3
property int debugPageIndex: 4
property int configurationPageIndex: 5
property int flappyPageIndex: 6
property int snakePageIndex: 7

Keys.onPressed: event => {
console.log(navigationController.isSelected,
Expand Down Expand Up @@ -89,6 +90,11 @@ Item {
text: "Flappy Bird"
}

HomeMenuItem {
highlighted: selectedPageIndex === snakePageIndex
text: "Snake"
}

HomeMenuItem {
highlighted: selectedPageIndex === exitPageIndex
text: "Exit"
Expand Down Expand Up @@ -129,4 +135,9 @@ Item {
visible: selectedPageIndex === flappyPageIndex && isSelected
isFocused: selectedPageIndex === flappyPageIndex && isSelected
}

Snake {
visible: selectedPageIndex === snakePageIndex && isSelected
isFocused: selectedPageIndex === snakePageIndex && isSelected
}
}
46 changes: 46 additions & 0 deletions NERODevelopment/content/Snake.qml
Original file line number Diff line number Diff line change
@@ -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
}
}
17 changes: 17 additions & 0 deletions NERODevelopment/content/SnakeBody.qml
Original file line number Diff line number Diff line change
@@ -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"
}
}
17 changes: 17 additions & 0 deletions NERODevelopment/content/SnakeFood.qml
Original file line number Diff line number Diff line change
@@ -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"
}
}
2 changes: 1 addition & 1 deletion NERODevelopment/src/controllers/navigationcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading