File tree Expand file tree Collapse file tree 3 files changed +13
-12
lines changed Expand file tree Collapse file tree 3 files changed +13
-12
lines changed Original file line number Diff line number Diff line change 5
5
6
6
Snake::Snake (int startX, int startY) {
7
7
head = new Node (startX, startY);
8
- tail = head;
9
- length = 1 ;
8
+ NodePtr current = head;
9
+
10
+ for (int i = 1 ; i < 4 ; ++i) {
11
+ NodePtr newNode = new Node (startX - i, startY);
12
+ current->next = newNode;
13
+ current = newNode;
14
+ }
15
+
16
+ tail = current;
17
+ length = 4 ;
10
18
collisionCount = 0 ;
11
- dx = 1 ; dy = 0 ; // Initial direction to the right
19
+ dx = 1 ; dy = 0 ;
12
20
}
13
21
14
22
void Snake::move () {
@@ -35,12 +43,6 @@ void Snake::grow() {
35
43
length++;
36
44
}
37
45
38
- void Snake::heal () {
39
- if (collisionCount > 0 ) {
40
- collisionCount--;
41
- }
42
- }
43
-
44
46
void Snake::changeDirectionOnCollision (int & dx, int & dy) {
45
47
// Change the direction of the snake when it collides with itself
46
48
if (dx == 1 ) {
@@ -147,4 +149,4 @@ void Snake::setDirection(int dx, int dy) {
147
149
}
148
150
this ->dx = dx;
149
151
this ->dy = dy;
150
- }
152
+ }
Original file line number Diff line number Diff line change @@ -20,7 +20,6 @@ class Snake {
20
20
Snake (int startX, int startY);
21
21
void move ();
22
22
void grow ();
23
- void heal ();
24
23
bool checkSelfCollision ();
25
24
void checkWallCollision ();
26
25
void changeDirectionOnCollision (int & dx, int & dy);
Original file line number Diff line number Diff line change @@ -96,7 +96,7 @@ int main(int argc, char** argv) {
96
96
while (!glfwWindowShouldClose (window)) {
97
97
glClear (GL_COLOR_BUFFER_BIT);
98
98
99
- renderText (0 .0f , 2 .0f , " Score: " + std::to_string (snake.getLength () - 1 ));
99
+ renderText (0 .0f , 2 .0f , " Score: " + std::to_string (snake.getLength () - 4 ));
100
100
renderText (0 .0f , 6 .0f , " Health:" );
101
101
102
102
// Calculate health percentage (assuming max health is 3)
You can’t perform that action at this time.
0 commit comments