elements: starting the collision, finally work on it
This commit is contained in:
@@ -11,6 +11,7 @@ struct Point {
|
||||
int m_row;
|
||||
int m_col;
|
||||
int m_symbol;
|
||||
void assign();
|
||||
void assign(int row, int col);
|
||||
};
|
||||
|
||||
@@ -18,6 +19,7 @@ struct PointCollection {
|
||||
std::vector<Point> m_point_list;
|
||||
void move();
|
||||
void set_direction(char direction);
|
||||
void check_collision();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
#include "elements.hpp"
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
|
||||
void Point::assign() {
|
||||
std::srand(std::time(0));
|
||||
m_row = (rand() % (ROW));
|
||||
m_col = (rand() % (ROW));
|
||||
}
|
||||
|
||||
void Point::assign(int row, int col) {
|
||||
m_row = row;
|
||||
@@ -28,3 +36,16 @@ void PointCollection::move() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PointCollection::check_collision() {
|
||||
for(int i = m_point_list.size() - 1; i >= 0; i--) {
|
||||
if(m_point_list[i].m_direction == 'u') {
|
||||
}
|
||||
if(m_point_list[i].m_direction == 'd') {
|
||||
}
|
||||
if(m_point_list[i].m_direction == 'l') {
|
||||
}
|
||||
if(m_point_list[i].m_direction == 'r') {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,18 +13,26 @@ void Input::get_input(bool &running, PointCollection &collection) {
|
||||
if(_getch == 65) {
|
||||
_getch = 0;
|
||||
collection.set_direction('u');
|
||||
collection.m_point_list.push_back(Point());
|
||||
collection.m_point_list.back().assign();
|
||||
}
|
||||
else if(_getch == 66) {
|
||||
_getch = 0;
|
||||
collection.set_direction('d');
|
||||
collection.m_point_list.push_back(Point());
|
||||
collection.m_point_list.back().assign();
|
||||
}
|
||||
else if(_getch == 67) {
|
||||
_getch = 0;
|
||||
collection.set_direction('r');
|
||||
collection.m_point_list.push_back(Point());
|
||||
collection.m_point_list.back().assign();
|
||||
}
|
||||
else if(_getch == 68) {
|
||||
_getch = 0;
|
||||
collection.set_direction('l');
|
||||
collection.m_point_list.push_back(Point());
|
||||
collection.m_point_list.back().assign();
|
||||
}
|
||||
else if(_getch == 113) running = false;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ int main() {
|
||||
std::thread input_thread(&Input::get_input, &input, std::ref(running), std::ref(collection));
|
||||
|
||||
collection.m_point_list.push_back(Point());
|
||||
collection.m_point_list.back().assign();
|
||||
|
||||
while (running) {
|
||||
collection.move();
|
||||
|
||||
+1
-1
@@ -17,5 +17,5 @@ void Window::draw_window(PointCollection &collection) {
|
||||
}
|
||||
std::cout << "\r\n";
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(33));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(16));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user