diff --git a/include/snake.hpp b/include/snake.hpp index 1e1a0d0..ea505f7 100644 --- a/include/snake.hpp +++ b/include/snake.hpp @@ -4,14 +4,38 @@ #include #include "point.hpp" -struct Snake { - Snake(int default_direction, int row, int col); - Point m_head; - std::vector m_tails; - int m_direction; // 1: Down, 2: Up, 3: Left, 4: Right +/* 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 + */ - void create_tail(int row, int col); // Adds a new tail to m_tails at { row, col } - void get_new_tail_point(int tail_index, int direction); +/* Struct Tail + * separate the snake and tail from each other + * */ + +struct Snake { + Snake(int default_direction, int row, int col); + Point m_head; + std::vector m_tails; + // 1: Down, 2: Up, 3: Left, 4: Right + int m_direction; + // Adds a new tail to m_tails at { row, col } + void create_tail(int row, int col); + void get_new_head_point(int tail_index, int direction); }; +// struct Tail { +// +// } + #endif diff --git a/src/main.cpp b/src/main.cpp index 877ab37..ed537bb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,6 +18,11 @@ int main (int argc, char *argv[]) { std::thread input_thread(&Input::get_input, &input); bool running = true; int count = 0; + /* NOTE + * if 3 or 4 then "-" + * if 1 or 2 then "|" + * if "corner" then "~" + */ while (running) { switch (input.m_current_key) { case 's': @@ -38,17 +43,6 @@ int main (int argc, char *argv[]) { } fruit.reset(window.m_board, snake.m_head.m_row, snake.m_head.m_col, window.m_score, count); - if (window.m_score % 2 == 0 && count > 0) { - if (snake.m_direction == 1) { - int r = snake.m_head.m_row; - if (r + 1 > ROW - 1) { - r = snake.m_head.m_row; - } - snake.create_tail(snake.m_head.m_row + r + 1, snake.m_head.m_col); - ++r; - } - count--; - } /* TODO * update tail positions diff --git a/src/snake.cpp b/src/snake.cpp index 82cc0ae..d5b8aa1 100644 --- a/src/snake.cpp +++ b/src/snake.cpp @@ -17,7 +17,7 @@ void Snake::create_tail(int row, int col) { m_tails.push_back(Point {row, col}); } -void Snake::get_new_tail_point(int tail_index, int direction) { +void Snake::get_new_head_point(int tail_index, int direction) { if (direction == 1) { if (m_tails.at(tail_index).m_row >= ROW - 1) m_tails.at(tail_index).m_row = 0; else ++m_tails.at(tail_index).m_row;