Moved distance limiting code to a smarter location, refactored related code
This commit is contained in:
parent
1606dfb058
commit
ecb16a4b5c
22
gamecore.cpp
22
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);
|
||||
}
|
||||
|
|
|
@ -45,7 +45,6 @@ class GameCore : public MainEvent
|
|||
|
||||
// constants
|
||||
static int NODE_SIZE;
|
||||
static int MAX_MOVE_DISTANCE;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -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;
|
||||
|
|
5
graph.h
5
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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user