Improvements to button menu and keyboard controls

This commit is contained in:
Anna Rose 2011-07-04 02:00:43 -04:00
parent 67cbd43740
commit 7d1ceb396b
2 changed files with 29 additions and 25 deletions

View File

@ -61,18 +61,19 @@ bool Game::init()
int col5 = 575; int col5 = 575;
int col6 = 680; int col6 = 680;
buttons.push_back(new MenuButton("Move", font, col1, row1, BUTTON_MOVE)); buttons.push_back(new MenuButton("Move (m)", font, col1, row1,
buttons.push_back(new MenuButton("Build", font, col1, row2, BUTTON_MOVE));
buttons.push_back(new MenuButton("Build (b)", font, col1, row2,
BUTTON_BUILD)); BUTTON_BUILD));
buttons.push_back(new MenuButton("Attack", font, col2, row1, buttons.push_back(new MenuButton("Attack (a)", font, col2, row1,
BUTTON_ATTACK)); BUTTON_ATTACK));
buttons.push_back(new MenuButton("Attacker", font, col3, row1, buttons.push_back(new MenuButton("Attacker (t)", font, col3, row1,
BUTTON_BUILD_ATTACKER)); BUTTON_BUILD_ATTACKER));
buttons.push_back(new MenuButton("Defender", font, col3, row2, buttons.push_back(new MenuButton("Defender (d)", font, col3, row2,
BUTTON_BUILD_DEFENDER)); BUTTON_BUILD_DEFENDER));
buttons.push_back(new MenuButton("Producer", font, col4, row1, buttons.push_back(new MenuButton("Producer (p)", font, col4, row1,
BUTTON_BUILD_PRODUCER)); BUTTON_BUILD_PRODUCER));
buttons.push_back(new MenuButton("End Turn", font, col6, row2, buttons.push_back(new MenuButton("End Turn (e)", font, col6, row2,
BUTTON_END_TURN)); BUTTON_END_TURN));
@ -202,24 +203,24 @@ void Game::draw_button(MenuButton* button)
void Game::draw_node(GameVertex* v) void Game::draw_node(GameVertex* v)
{ {
DrawUtils::draw_circle_filled(display, v->x, v->y, v->r, DrawUtils::draw_circle_filled(display, v->x, v->y, v->r,
v->colour); v->colour);
DrawUtils::draw_text(display, itos(v->score), v->x, v->y, font, DrawUtils::draw_text(display, itos(v->score), v->x, v->y, font,
0x00ff00, true, true); 0x00ff00, true, true);
switch (v->type) switch (v->type)
{ {
case VERTEX_ATTACKER: case VERTEX_ATTACKER:
DrawUtils::draw(display, attacker_icon, v->x + 5, v-> y + 5); DrawUtils::draw(display, attacker_icon, v->x + 5, v-> y + 5);
break; break;
case VERTEX_DEFENDER: case VERTEX_DEFENDER:
DrawUtils::draw(display, defender_icon, v->x + 5, v-> y + 5); DrawUtils::draw(display, defender_icon, v->x + 5, v-> y + 5);
break; break;
case VERTEX_PRODUCER: case VERTEX_PRODUCER:
DrawUtils::draw(display, producer_icon, v->x + 5, v-> y + 5); DrawUtils::draw(display, producer_icon, v->x + 5, v-> y + 5);
break; break;
} }
} }
@ -348,6 +349,9 @@ void Game::on_key_down(SDLKey sym, SDLMod mod, Uint16 unicode)
else if (sym == SDLK_a) data.set_mode(MODE_ATTACK); else if (sym == SDLK_a) data.set_mode(MODE_ATTACK);
else if (sym == SDLK_m) data.set_mode(MODE_MOVE); else if (sym == SDLK_m) data.set_mode(MODE_MOVE);
else if (sym == SDLK_b) data.set_mode(MODE_BUILD); else if (sym == SDLK_b) data.set_mode(MODE_BUILD);
else if (sym == SDLK_d) data.set_build_type(VERTEX_DEFENDER);
else if (sym == SDLK_p) data.set_build_type(VERTEX_PRODUCER);
else if (sym == SDLK_t) data.set_build_type(VERTEX_ATTACKER);
else if (sym == SDLK_s || sym == SDLK_ESCAPE) data.set_mode(MODE_SELECT); else if (sym == SDLK_s || sym == SDLK_ESCAPE) data.set_mode(MODE_SELECT);
else if (sym == SDLK_e) data.toggle_turn(); else if (sym == SDLK_e) data.toggle_turn();

View File

@ -23,13 +23,13 @@ void MenuButton::set_hover(bool is_hovering)
void MenuButton::draw(SDL_Surface* display, int colour, int background_colour) void MenuButton::draw(SDL_Surface* display, int colour, int background_colour)
{ {
SDL_Rect pen = {x, y, 100, 40}; SDL_Rect pen = {x, y, 80, 20};
SDL_FillRect(display, &pen, background_colour); SDL_FillRect(display, &pen, background_colour);
int temp_colour = 0x000000; int temp_colour = 0x000000;
DrawUtils::draw_text(display, text, x + 50, y + 20, font, colour, 1, 1); DrawUtils::draw_text(display, text, x + 40, y + 10, font, colour, 1, 1);
} }