Fixed issues with events and SideBar text.

This commit is contained in:
Tim Schubert 2016-01-25 01:45:35 +01:00
parent 100065e158
commit 21249de7d6
8 changed files with 272 additions and 243 deletions

View file

@ -14,7 +14,7 @@
const int SCREEN_WIDTH = 800;
const int SCREEN_HEIGTH = 600;
const int SIDEBAR_WIDTH = 200;
const int SIDEBAR_WIDTH = 300;
const std::string TITLE = "Bob - Battles of Bacteria";
class Game
@ -23,19 +23,18 @@ class Game
public:
Game(SDL_Rect *window_dimensions, Sint16 size)
{
this->event_context = new EventContext();
this->layout = new Layout(pointy_orientation, size,
this->layout = new Layout(pointy_orientation, 20,
{window_dimensions->w / 2, window_dimensions->h / 2},
{0, 0, window_dimensions->w - SIDEBAR_WIDTH, window_dimensions->h});
{SIDEBAR_WIDTH, 0, window_dimensions->w - SIDEBAR_WIDTH, window_dimensions->h});
this->grid = new HexagonGrid(size, this->layout);
for (int i = 0; i < 4; i++)
{
this->move[i] = false;
}
this->quit = false;
SDL_Color fg = {0x00, 0xff, 0x00, 0xff};
try
{
this->font = load_font_from_file("/usr/share/fonts/dejavu/DejaVuSans.ttf", 12);
this->window = new Window(TITLE, window_dimensions, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
this->renderer = new Renderer(this->window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC
@ -43,10 +42,18 @@ public:
SDL_Rect side_bar_dimensions = {window_dimensions->x - SIDEBAR_WIDTH, 0, SIDEBAR_WIDTH,
window_dimensions->y};
this->side_bar = new Container(this->window, this->renderer, side_bar_dimensions);
this->field_box = new FieldBox(this->renderer,
{0, 20, SIDEBAR_WIDTH, SCREEN_HEIGTH},
fg,
this->font,
this->grid->point_to_field({0.0, 0.0})
);
this->test_box = new TextBox(this->renderer,
{SCREEN_WIDTH - SIDEBAR_WIDTH, 0, SIDEBAR_WIDTH, SCREEN_HEIGTH},
{0x00, 0xff, 0x00, 0xff}, this->font);
{0, 0, SIDEBAR_WIDTH, SCREEN_HEIGTH},
fg, this->font
);
this->side_bar->add(test_box);
this->side_bar->add(field_box);
this->side_bar->set_visible(true);
}
catch (const SDL_Exception &sdl_except)
@ -60,6 +67,7 @@ public:
~Game()
{
delete this->test_box;
delete this->field_box;
delete this->move_timer;
delete this->frame_timer;
delete this->side_bar;
@ -67,7 +75,7 @@ public:
delete this->renderer;
delete this->window;
delete this->layout;
delete this->event_context;
//delete this->events;
}
void render();
@ -77,7 +85,7 @@ public:
int game_loop();
private:
EventContext *event_context;
FieldBox *field_box;
TextBox *test_box;
TTF_Font *font;
Window *window;