diff --git a/gamecore.cpp b/gamecore.cpp index 83dc130..a9c782e 100644 --- a/gamecore.cpp +++ b/gamecore.cpp @@ -3,7 +3,6 @@ #include "debug.h" int GameCore::NODE_SIZE = 25; -int GameCore::MAX_MOVE_DISTANCE = 200; GameCore::GameCore() { @@ -92,8 +91,9 @@ void GameCore::render() if (graph.get_current_vertex() != NULL) { Vertex* v = graph.get_current_vertex(); - DrawUtils::draw(display, move_template, v->x - MAX_MOVE_DISTANCE / 2, - v->y - MAX_MOVE_DISTANCE / 2); + DrawUtils::draw(display, move_template, + v->x - Graph::MAX_MOVE_DISTANCE, + v->y - Graph::MAX_MOVE_DISTANCE); } @@ -124,21 +124,5 @@ void GameCore::on_exit() void GameCore::on_lbutton_down(int x, int y) { - Vertex* v = graph.get_current_vertex(); - Vertex new_v = Vertex(); - new_v.x = x; - new_v.y = y; - -#ifdef DEBUG - if (v != NULL) - cerr << "debug: GameCore::on_lbutton_down(): distance=" - << Vertex::distance(*v, new_v) << "\n"; - else - cerr << "debug: GameCore::on_lbutton_down(): distance=0, current_vertex is NULL\n"; -#endif - - if (v != NULL && (Vertex::distance(*v, new_v) > MAX_MOVE_DISTANCE)) - return; - graph.do_vertex(x, y, NODE_SIZE); } diff --git a/gamecore.h b/gamecore.h index fae07fb..dd38c3c 100644 --- a/gamecore.h +++ b/gamecore.h @@ -45,7 +45,6 @@ class GameCore : public MainEvent // constants static int NODE_SIZE; - static int MAX_MOVE_DISTANCE; }; #endif diff --git a/graph.cpp b/graph.cpp index 57efbaf..7d126eb 100644 --- a/graph.cpp +++ b/graph.cpp @@ -4,6 +4,7 @@ using std::abs; +int Graph::MAX_MOVE_DISTANCE = 100; Graph::Graph() { @@ -75,10 +76,11 @@ void Graph::select_vertex(int x, int y) void Graph::add_vertex(int x, int y, int size) { - Vertex* v = new Vertex(); - v->x = x; - v->y = y; + if (current_vertex != NULL && + (Vertex::distance(*current_vertex, Vertex(x, y)) > MAX_MOVE_DISTANCE)) + return; + Vertex* v = new Vertex(x, y); v->x_min = x - size/2; v->x_max = x + size/2; v->y_min = y - size/2; diff --git a/graph.h b/graph.h index de426a0..e7aa325 100644 --- a/graph.h +++ b/graph.h @@ -14,6 +14,9 @@ using std::list; class Vertex { public: + Vertex(int x, int y) + { this->x = x; this->y = y; } + int x; int y; int x_min; @@ -44,6 +47,8 @@ class Graph void do_vertex(int x, int y, int size); Vertex* get_current_vertex() { return current_vertex; } + static int MAX_MOVE_DISTANCE; + private: void add_vertex(int x, int y, int size); void select_vertex(int x, int y);