Added menu buttons for building types of units
This commit is contained in:
parent
793d6bd9a2
commit
6085267cc4
36
game.cpp
36
game.cpp
|
@ -47,12 +47,24 @@ bool Game::init()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
buttons.push_back(new MenuButton("Move", font, 155, display->h - 95,
|
int row1 = display->h - 95;
|
||||||
BUTTON_MOVE));
|
int row2 = display->h - 50;
|
||||||
buttons.push_back(new MenuButton("Attack", font, 260, display->h - 95,
|
int col1 = 155;
|
||||||
BUTTON_ATTACK));
|
int col2 = 260;
|
||||||
buttons.push_back(new MenuButton("Build", font, 155, display->h - 50,
|
int col3 = 365;
|
||||||
|
int col4 = 470;
|
||||||
|
|
||||||
|
buttons.push_back(new MenuButton("Move", font, col1, row1, BUTTON_MOVE));
|
||||||
|
buttons.push_back(new MenuButton("Build", font, col1, row2,
|
||||||
BUTTON_BUILD));
|
BUTTON_BUILD));
|
||||||
|
buttons.push_back(new MenuButton("Attack", font, col2, row1,
|
||||||
|
BUTTON_ATTACK));
|
||||||
|
buttons.push_back(new MenuButton("Attacker", font, col3, row1,
|
||||||
|
BUTTON_BUILD_ATTACKER));
|
||||||
|
buttons.push_back(new MenuButton("Defender", font, col3, row2,
|
||||||
|
BUTTON_BUILD_DEFENDER));
|
||||||
|
buttons.push_back(new MenuButton("Producer", font, col4, row1,
|
||||||
|
BUTTON_BUILD_PRODUCER));
|
||||||
|
|
||||||
|
|
||||||
return GameState::init();
|
return GameState::init();
|
||||||
|
@ -141,6 +153,13 @@ void Game::render()
|
||||||
cursor != buttons.end(); cursor++)
|
cursor != buttons.end(); cursor++)
|
||||||
{
|
{
|
||||||
MenuButton* button = *cursor;
|
MenuButton* button = *cursor;
|
||||||
|
|
||||||
|
if ((button->get_action() & (BUTTON_BUILD_ATTACKER |
|
||||||
|
BUTTON_BUILD_DEFENDER |
|
||||||
|
BUTTON_BUILD_PRODUCER)) &&
|
||||||
|
data.get_mode() != MODE_BUILD)
|
||||||
|
continue;
|
||||||
|
|
||||||
draw_button(button);
|
draw_button(button);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,11 +173,16 @@ void Game::draw_button(MenuButton* button)
|
||||||
int colour = 0x000000;
|
int colour = 0x000000;
|
||||||
ButtonAction action = button->get_action();
|
ButtonAction action = button->get_action();
|
||||||
Mode mode = data.get_mode();
|
Mode mode = data.get_mode();
|
||||||
|
VertexType build_type = data.get_build_type();
|
||||||
|
|
||||||
// fixme - there's really got to be a better way...
|
// fixme - there's really got to be a better way...
|
||||||
if ((action == BUTTON_BUILD && mode == MODE_BUILD) ||
|
if ((action == BUTTON_BUILD && mode == MODE_BUILD) ||
|
||||||
(action == BUTTON_ATTACK && mode == MODE_ATTACK) ||
|
(action == BUTTON_ATTACK && mode == MODE_ATTACK) ||
|
||||||
(action == BUTTON_MOVE && mode == MODE_MOVE))
|
(action == BUTTON_MOVE && mode == MODE_MOVE) ||
|
||||||
|
(action == BUTTON_BUILD_ATTACKER && build_type == VERTEX_ATTACKER) ||
|
||||||
|
(action == BUTTON_BUILD_DEFENDER && build_type == VERTEX_DEFENDER) ||
|
||||||
|
(action == BUTTON_BUILD_PRODUCER && build_type == VERTEX_PRODUCER)
|
||||||
|
)
|
||||||
colour = 0x0000ff;
|
colour = 0x0000ff;
|
||||||
else if (button->is_at(cursor_x, cursor_y)) colour = 0xff0000;
|
else if (button->is_at(cursor_x, cursor_y)) colour = 0xff0000;
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,9 @@
|
||||||
#include "graph.h"
|
#include "graph.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
|
||||||
enum Mode {MODE_MOVE, MODE_ATTACK, MODE_BUILD, MODE_SELECT};
|
enum Mode {MODE_MOVE=0x1, MODE_ATTACK=0x2, MODE_BUILD=0x4, MODE_SELECT=0x8};
|
||||||
enum VertexType {VERTEX_ATTACKER, VERTEX_DEFENDER, VERTEX_PRODUCER, VERTEX_NONE};
|
enum VertexType {VERTEX_NONE=0x1, VERTEX_ATTACKER=0x2, VERTEX_DEFENDER=0x4,
|
||||||
|
VERTEX_PRODUCER=0x8};
|
||||||
|
|
||||||
class GameVertex : public Vertex
|
class GameVertex : public Vertex
|
||||||
{
|
{
|
||||||
|
@ -43,6 +44,7 @@ class GameData : public Graph
|
||||||
Mode get_mode() const { return mode; }
|
Mode get_mode() const { return mode; }
|
||||||
void set_mode(Mode m);
|
void set_mode(Mode m);
|
||||||
|
|
||||||
|
VertexType get_build_type() const { return build_type; }
|
||||||
void set_build_type(VertexType type) { build_type = type; }
|
void set_build_type(VertexType type) { build_type = type; }
|
||||||
|
|
||||||
// returns the move/attack range for the specified node
|
// returns the move/attack range for the specified node
|
||||||
|
|
|
@ -13,9 +13,9 @@ using std::string;
|
||||||
|
|
||||||
// fixme: there's probably a better way to do this, but SDL's event model
|
// fixme: there's probably a better way to do this, but SDL's event model
|
||||||
// has me hard-pressed to figure out what it is.
|
// has me hard-pressed to figure out what it is.
|
||||||
enum ButtonAction {BUTTON_BUILD, BUTTON_ATTACK, BUTTON_MOVE,
|
enum ButtonAction {BUTTON_BUILD=0x1, BUTTON_ATTACK=0x2, BUTTON_MOVE=0x4,
|
||||||
BUTTON_BUILD_ATTACKER, BUTTON_BUILD_DEFENDER,
|
BUTTON_BUILD_ATTACKER=0x8, BUTTON_BUILD_DEFENDER=0x10,
|
||||||
BUTTON_BUILD_PRODUCER};
|
BUTTON_BUILD_PRODUCER=0x20};
|
||||||
|
|
||||||
class MenuButton
|
class MenuButton
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user