Code for some of the basic game design - selecting existing nodes, limiting edge distance
This commit is contained in:
27
gamecore.cpp
27
gamecore.cpp
@ -5,11 +5,15 @@
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
int GameCore::NODE_SIZE = 25;
|
||||
int GameCore::MAX_MOVE_DISTANCE = 200;
|
||||
|
||||
GameCore::GameCore()
|
||||
{
|
||||
display = NULL;
|
||||
background = NULL;
|
||||
node = NULL;
|
||||
move_template = NULL;
|
||||
is_running = true;
|
||||
}
|
||||
|
||||
@ -51,7 +55,11 @@ bool GameCore::init()
|
||||
node = DrawUtils::load("node.bmp");
|
||||
DrawUtils::transpare(node, 255, 0, 255);
|
||||
|
||||
if (background == NULL || node == NULL)
|
||||
move_template = DrawUtils::load("move_template.bmp");
|
||||
DrawUtils::transpare(move_template, 255, 0, 255);
|
||||
SDL_SetAlpha(move_template, SDL_SRCALPHA, 128);
|
||||
|
||||
if (background == NULL || node == NULL || move_template == NULL)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << "GameCore::init(): error: Couldn't load an image file\n";
|
||||
@ -85,6 +93,13 @@ void GameCore::render()
|
||||
0x000000);
|
||||
}
|
||||
|
||||
if (graph.get_current_vertex() != NULL)
|
||||
{
|
||||
Vertex* v = graph.get_current_vertex();
|
||||
DrawUtils::draw(display, move_template, v->x, v->y);
|
||||
}
|
||||
|
||||
|
||||
SDL_Flip(display);
|
||||
}
|
||||
|
||||
@ -112,5 +127,13 @@ void GameCore::on_exit()
|
||||
|
||||
void GameCore::on_lbutton_down(int x, int y)
|
||||
{
|
||||
graph.add_vertex(x, y, 25);
|
||||
Vertex* v = graph.get_current_vertex();
|
||||
Vertex new_v = Vertex();
|
||||
new_v.x = x;
|
||||
new_v.y = y;
|
||||
|
||||
if (v != NULL && (Vertex::distance(*v, new_v) > MAX_MOVE_DISTANCE))
|
||||
return
|
||||
|
||||
graph.do_vertex(x, y, NODE_SIZE);
|
||||
}
|
||||
|
Reference in New Issue
Block a user