Skip to content

Commit

Permalink
Merge pull request #121 from Northeastern-Electric-Racing/snake-button
Browse files Browse the repository at this point in the history
added snake button to home menu
  • Loading branch information
mattrwang authored Oct 18, 2024
2 parents d2221c3 + eb47a93 commit 86366fa
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 3 deletions.
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

0 comments on commit 86366fa

Please sign in to comment.