fix: (tail) fixed where tail index 0 is on top of the head

This commit is contained in:
DarthMooMancer
2025-08-28 20:14:35 -04:00
parent ac23c873c3
commit 157933c122
9 changed files with 86 additions and 84 deletions
+2 -1
View File
@@ -7,9 +7,10 @@ struct Fruit {
Fruit();
int unsigned m_row;
int unsigned m_col;
int unsigned m_total_eaten;
Point m_point;
void create_point();
void reset(std::array<std::array<char, COL>, ROW> &arr, int row, int col, int &score, int &count);
void reset(std::array<std::array<char, COL>, ROW> &arr, int row, int col, int &score);
};
#endif // FRUIT_HPP
+1
View File
@@ -3,6 +3,7 @@
struct Input {
char m_current_key = ' ';
char m_getch = ' ';
void get_input(int &d, bool &r);
};
+4 -22
View File
@@ -4,30 +4,12 @@
#include <vector>
#include "point.hpp"
/* NOTE
* tail
* ARGS
* - direction
* - old point
* - new point
* - new direction (x and y of old point and what direction it needs to swtich to so once it gets to it changes)
* - symbol
* IMPLEMENTATION
* - predict the new point
* - save old point
* - find if previous tail has new direction
* - once tail hits point change direction
*/
/* Struct Tail
* separate the snake and tail from each other
* */
struct Head {
Head(int default_direction, int row, int col);
Point m_head;
Point m_previous_head;
void get_new_point(int direction);
void get_previous_point();
};
struct Tail {
@@ -35,8 +17,7 @@ struct Tail {
Point m_tail_pos;
Point m_previous_tail_pos;
std::vector<Point> m_move_history;
// void set_point(Point &d);
void get_new_point();
void get_previous_point();
};
struct Body {
@@ -44,6 +25,7 @@ struct Body {
void clear(std::array<std::array<char, COL>, ROW> &arr);
void draw(std::array<std::array<char, COL>, ROW> &arr);
void move(Head &head);
void get_new_points(Head &head);
};
#endif
+13 -9
View File
@@ -2,18 +2,22 @@
#define WINDOW_HPP
#include <array>
#include "globals.hpp"
#include "fruit.hpp"
#include "snake.hpp"
struct Window {
std::array<std::array<char, COL>, ROW> m_board;
int m_score;
// Initializes board with . for each value
Window();
Window();
std::array<std::array<char, COL>, ROW> m_board;
int m_score;
int m_reset;
int m_previous_reset;
void draw_score();
void draw_window();
void clear_window();
void tick(double frames_per_second);
void update_loop(int fps);
void draw_score();
void draw_window();
void clear_window();
void tick(double frames_per_second);
void update_score(Fruit &fruit, Body &body);
void update_loop(int fps);
};
#endif // WINDOW_HPP