snake can collide and removed some magic numbers
This commit is contained in:
+14
-11
@@ -11,26 +11,29 @@ int main () {
|
||||
Input input;
|
||||
bool running = true;
|
||||
|
||||
Point* segments[ROW * COL] = {};
|
||||
segments[0] = new Point { 5, 5, '*', 1 }; // Head
|
||||
segments[2] = new Point { (rand() % ROW), (rand() % COL), 'o', 0 }; // Fruit
|
||||
Point* segments[(ROW * COL) + 3] = {}; // 2 for head, 1 for fruit, rest for tail
|
||||
segments[0] = new Point { 5, 5, '*' }; // Head
|
||||
segments[2] = new Point { (rand() % ROW), (rand() % COL), 'o' }; // Fruit
|
||||
|
||||
std::thread input_thread(
|
||||
&Input::get_input, &input,
|
||||
std::ref(segments[0]->m_direction),
|
||||
std::ref(segments[0]->m_dir),
|
||||
std::ref(running));
|
||||
|
||||
while (running) {
|
||||
on_fruit_eaten(window.m_board, segments);
|
||||
determine_index_zero_pos(window.m_board, segments);
|
||||
move_tail_indicies(segments);
|
||||
// if(body.m_body.size() >= (ROW * COL)) {
|
||||
// std::cout << "You win! Score: " + std::to_string(body.m_body.size()) << std::endl;
|
||||
// running = false;
|
||||
// } else if(body.check_collision(head)) {
|
||||
// std::cout << "You died! Score: " + std::to_string(body.m_body.size()) << std::endl;
|
||||
// running = false;
|
||||
// }
|
||||
|
||||
for(int i = (ROW * COL) - 1; i > 3; i--) {
|
||||
if(segments[i] == nullptr) break;
|
||||
std::cout << "You win! Score: " << get_score() << std::endl;
|
||||
running = false;
|
||||
}
|
||||
if(segment_overlap(segments)) {
|
||||
std::cout << "You died! Score: " << get_score() << std::endl;
|
||||
running = false;
|
||||
}
|
||||
window.clear_display();
|
||||
window.update_display(segments);
|
||||
window.draw_display(200);
|
||||
|
||||
Reference in New Issue
Block a user