feat: (snake point main) finally got tail to work with a few bugs
This commit is contained in:
+23
-21
@@ -1,4 +1,5 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <cstdlib>
|
||||
#include <unistd.h>
|
||||
@@ -17,42 +18,43 @@ int main (int argc, char *argv[]) {
|
||||
Body body;
|
||||
Head head { 2, 0, 0 };
|
||||
bool running = true;
|
||||
// std::thread input_thread(&Input::get_input, &input, std::ref(head.m_head.m_direction), std::ref(running));
|
||||
std::thread input_thread(&Input::get_input, &input, std::ref(head.m_head.m_direction), std::ref(running));
|
||||
int count = 0;
|
||||
|
||||
/* TODO
|
||||
* Each tail is not meant to follow the head. Each tail should follow the tail or head in front of it. Tail 6 should follow tail 5 and not the head.
|
||||
*/
|
||||
body.m_body.push_back(Tail{2, 0, 0});
|
||||
body.m_body.push_back(Tail{2, 0, 0});
|
||||
body.m_body.push_back(Tail{2, 0, 0});
|
||||
body.m_body.push_back(Tail{2, 0, 0});
|
||||
body.m_body.push_back(Tail{2, 0, 0});
|
||||
body.m_body.push_back(Tail{2, 0, 0});
|
||||
while (running) {
|
||||
// if(tail.m_tail_pos.m_direction != head.m_head.m_direction) {
|
||||
// tail.m_move_history.push_back(Point{ head.m_head.m_row, head.m_head.m_col, head.m_head.m_direction });
|
||||
// tail.m_tail_pos.m_direction = head.
|
||||
// }
|
||||
//
|
||||
/* FIXME
|
||||
* It teleports the tail to the head because i am basing off of the head. It needs to be isolated but just follow the head
|
||||
* */
|
||||
// body.m_body.at(0).m_tail_pos.m_row = head.m_head.m_row - 1;
|
||||
// body.m_body.at(1).m_tail_pos.m_row = body.m_body.at(0).m_tail_pos.m_row - 1;
|
||||
body.move(head);
|
||||
for (int i = 0; i < body.m_body.size(); i++) {
|
||||
if(i == 0) {
|
||||
body.m_body.at(i).m_previous_tail_pos.set_new_point(head.m_head.m_row, head.m_head.m_col, head.m_head.m_direction);
|
||||
} else {
|
||||
body.m_body.at(i).m_previous_tail_pos.set_new_point(body.m_body.at(i - 1).m_tail_pos.m_row, body.m_body.at(i - 1).m_tail_pos.m_col, body.m_body.at(i - 1).m_tail_pos.m_direction);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < body.m_body.size(); i++) {
|
||||
body.m_body.at(i).get_new_point();
|
||||
}
|
||||
fruit.reset(window.m_board, head.m_head.m_row, head.m_head.m_col, window.m_score, count);
|
||||
|
||||
window.m_board[head.m_head.m_row][head.m_head.m_col] = '*';
|
||||
window.m_board[fruit.m_row][fruit.m_col] = 'X';
|
||||
body.draw(window.m_board);
|
||||
window.draw_score();
|
||||
for(int i = 0; i < body.m_body.size(); i++) {
|
||||
std::cout << body.m_body.at(i).m_tail_pos.to_string() << std::endl;
|
||||
}
|
||||
// for(int i = 0; i < body.m_body.size(); i++) {
|
||||
// std::cout << "Index: " + std::to_string(i) + " " + body.m_body.at(i).m_tail_pos.to_string() << std::endl;
|
||||
// }
|
||||
// std::cout << "Head: " + head.m_head.to_string() << std::endl;
|
||||
window.update_loop(FPS);
|
||||
body.clear(window.m_board);
|
||||
head.m_head.clear(window.m_board);
|
||||
head.get_new_point(head.m_head.m_direction);
|
||||
}
|
||||
//
|
||||
// input_thread.join();
|
||||
// return 0;
|
||||
|
||||
input_thread.join();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user