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"
|
#include "debug.h"
|
||||||
|
|
||||||
int GameCore::NODE_SIZE = 25;
|
int GameCore::NODE_SIZE = 25;
|
||||||
int GameCore::MAX_MOVE_DISTANCE = 200;
|
|
||||||
|
|
||||||
GameCore::GameCore()
|
GameCore::GameCore()
|
||||||
{
|
{
|
||||||
|
@ -92,8 +91,9 @@ void GameCore::render()
|
||||||
if (graph.get_current_vertex() != NULL)
|
if (graph.get_current_vertex() != NULL)
|
||||||
{
|
{
|
||||||
Vertex* v = graph.get_current_vertex();
|
Vertex* v = graph.get_current_vertex();
|
||||||
DrawUtils::draw(display, move_template, v->x - MAX_MOVE_DISTANCE / 2,
|
DrawUtils::draw(display, move_template,
|
||||||
v->y - MAX_MOVE_DISTANCE / 2);
|
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)
|
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);
|
graph.do_vertex(x, y, NODE_SIZE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,6 @@ class GameCore : public MainEvent
|
||||||
|
|
||||||
// constants
|
// constants
|
||||||
static int NODE_SIZE;
|
static int NODE_SIZE;
|
||||||
static int MAX_MOVE_DISTANCE;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
using std::abs;
|
using std::abs;
|
||||||
|
|
||||||
|
int Graph::MAX_MOVE_DISTANCE = 100;
|
||||||
|
|
||||||
Graph::Graph()
|
Graph::Graph()
|
||||||
{
|
{
|
||||||
|
@ -75,10 +76,11 @@ void Graph::select_vertex(int x, int y)
|
||||||
|
|
||||||
void Graph::add_vertex(int x, int y, int size)
|
void Graph::add_vertex(int x, int y, int size)
|
||||||
{
|
{
|
||||||
Vertex* v = new Vertex();
|
if (current_vertex != NULL &&
|
||||||
v->x = x;
|
(Vertex::distance(*current_vertex, Vertex(x, y)) > MAX_MOVE_DISTANCE))
|
||||||
v->y = y;
|
return;
|
||||||
|
|
||||||
|
Vertex* v = new Vertex(x, y);
|
||||||
v->x_min = x - size/2;
|
v->x_min = x - size/2;
|
||||||
v->x_max = x + size/2;
|
v->x_max = x + size/2;
|
||||||
v->y_min = y - size/2;
|
v->y_min = y - size/2;
|
||||||
|
|
5
graph.h
5
graph.h
|
@ -14,6 +14,9 @@ using std::list;
|
||||||
class Vertex
|
class Vertex
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Vertex(int x, int y)
|
||||||
|
{ this->x = x; this->y = y; }
|
||||||
|
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
int x_min;
|
int x_min;
|
||||||
|
@ -44,6 +47,8 @@ class Graph
|
||||||
void do_vertex(int x, int y, int size);
|
void do_vertex(int x, int y, int size);
|
||||||
Vertex* get_current_vertex() { return current_vertex; }
|
Vertex* get_current_vertex() { return current_vertex; }
|
||||||
|
|
||||||
|
static int MAX_MOVE_DISTANCE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void add_vertex(int x, int y, int size);
|
void add_vertex(int x, int y, int size);
|
||||||
void select_vertex(int x, int y);
|
void select_vertex(int x, int y);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user