diff options
-rw-r--r-- | src/main/engine/engine.c | 11 | ||||
-rw-r--r-- | src/main/engine/shape/circle.c | 11 | ||||
-rw-r--r-- | src/main/engine/shape/circle.h | 1 | ||||
-rw-r--r-- | src/main/engine/shape/line.c | 7 | ||||
-rw-r--r-- | src/main/engine/shape/line.h | 2 | ||||
-rw-r--r-- | src/main/game/domain/board.c | 4 | ||||
-rw-r--r-- | src/main/game/game.c | 13 |
7 files changed, 40 insertions, 9 deletions
diff --git a/src/main/engine/engine.c b/src/main/engine/engine.c index 495b960..d9477cc 100644 --- a/src/main/engine/engine.c +++ b/src/main/engine/engine.c @@ -96,14 +96,21 @@ engine_calculate_fps() } static void +engine_set_background(Engine *engine) +{ + if (engine == NULL || engine->rendering_background == NULL) return; + Color *bk = engine->rendering_background; + glClearColor(bk->r, bk->g, bk->b, bk->a); +} + +static void draw_frames(void *data) { if (data == NULL) return; Engine *engine = data; - Color *bk = engine->rendering_background; - glClearColor(bk->r, bk->g, bk->b, bk->a); + engine_set_background(engine); glClear(GL_COLOR_BUFFER_BIT); glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); diff --git a/src/main/engine/shape/circle.c b/src/main/engine/shape/circle.c index f60e917..996ae19 100644 --- a/src/main/engine/shape/circle.c +++ b/src/main/engine/shape/circle.c @@ -40,6 +40,10 @@ engine_render_circle(Circle *circle) { glBegin(GL_LINE_LOOP); + if (circle->color != NULL) { + glColor3f(circle->color->r, circle->color->g, circle->color->b); + } + for (int i = 0; i < circle->num_segments; i++) { float theta = 2.0f * M_PI * i / circle->num_segments; float x = circle->r * cosf(theta); @@ -49,3 +53,10 @@ engine_render_circle(Circle *circle) glEnd(); } + +void +engine_circle_set_color(Circle *circle, Color *color) +{ + if (circle == NULL) return; + circle->color = color; +} diff --git a/src/main/engine/shape/circle.h b/src/main/engine/shape/circle.h index 67c3a46..3830256 100644 --- a/src/main/engine/shape/circle.h +++ b/src/main/engine/shape/circle.h @@ -33,5 +33,6 @@ typedef struct { Circle *engine_circle_new(float cx, float cy, float r, int num_segments, int outline); void engine_render_circle(Circle *circle); +void engine_circle_set_color(Circle *, Color *); #endif /* __CIRCLE_H__ */ diff --git a/src/main/engine/shape/line.c b/src/main/engine/shape/line.c index 7c0bc18..c3ef502 100644 --- a/src/main/engine/shape/line.c +++ b/src/main/engine/shape/line.c @@ -47,13 +47,16 @@ engine_render_line(Line *line) } void -engine_render_lines(list_t *lines) +engine_render_lines(list_t *lines, Color *color) { if (lines == NULL || lines->size <= 0) return; glLineWidth(5.0f); glBegin(GL_LINES); - glColor3f(1.0f, 1.0f, 0.0f); /* Yellow */ + + if (color != NULL) { + glColor3f(color->r, color->g, color->b); + } list_node_t *current = lines->head; do { diff --git a/src/main/engine/shape/line.h b/src/main/engine/shape/line.h index c1a933d..ec589a9 100644 --- a/src/main/engine/shape/line.h +++ b/src/main/engine/shape/line.h @@ -30,6 +30,6 @@ typedef struct Line { Line *engine_line_new(float x1, float y1, float x2, float y2); void engine_render_line(Line *line); -void engine_render_lines(list_t *lines); +void engine_render_lines(list_t *lines, Color *color); #endif /* __ENGINE_LINE_H__ */ diff --git a/src/main/game/domain/board.c b/src/main/game/domain/board.c index 82b1784..3f486b0 100644 --- a/src/main/game/domain/board.c +++ b/src/main/game/domain/board.c @@ -43,8 +43,8 @@ board_new(float left, float right, float top, float bottom, float box_size) } board->default_color = color_new(0.0f, 0.0f, 0.2f, 1.0f); - board->wining_color = color_new(0.0f, 0.5f, 0.0f, 1.0f); - board->draft_color = color_new(0.1f, 0.3f, 0.5f, 1.0f); + board->wining_color = color_new(0.6f, 0.8f, 0.6f, 1.0f); + board->draft_color = color_new(0.4f, 0.6f, 0.8f, 1.0f); board->lines = list_create(); diff --git a/src/main/game/game.c b/src/main/game/game.c index 35d5c21..9881896 100644 --- a/src/main/game/game.c +++ b/src/main/game/game.c @@ -73,13 +73,17 @@ init_log(void) static void game_draw_field(TrisGame *game, float box_size); static char game_next_sign(TrisGame *game); +static Color *COLOR_BOARD; +static Color *COLOR_CIRCLE; +static Color *COLOR_CROSS; + static void draw_frames(void *data) { if (data == NULL) return; TrisGame *game = data; - engine_render_lines(game->board->lines); + engine_render_lines(game->board->lines, COLOR_BOARD); for (int i = 0; i < BOARD_SIZE; i++) { Cell *cell = game->cells[i]; @@ -87,7 +91,7 @@ draw_frames(void *data) engine_render_circle(cell->shape); } else if (cell->sign == SIGN_CROSS) { CrossShape *shape = cell->shape; - engine_render_lines(shape->lines); + engine_render_lines(shape->lines, COLOR_CROSS); } } } @@ -149,6 +153,7 @@ draw_sign(TrisGame *game, Cell *cell) cell_set_sign(cell, sign); if (sign == SIGN_CIRCLE) { cell->shape = engine_circle_new(x, y, l, 120, 1); + engine_circle_set_color(cell->shape, COLOR_CIRCLE); game->sign = SIGN_CROSS; } else if (sign == SIGN_CROSS) { cell->shape = cross_shape_new(x - l, x + l, y + l, y - l); @@ -202,6 +207,10 @@ game_init(int width, int height) game->engine = engine_new(width, height); game->ended = false; + COLOR_BOARD = color_new(1.0f, 1.0f, 0.0f, 1.0f); + COLOR_CIRCLE = color_new(1.0f, 0.3f, 0.5f, 1.0f); + COLOR_CROSS = color_new(0.3f, 0.2f, 0.8f, 1.0f); + engine_set_window_title(game->engine, "Tris Game"); engine_set_mouse_button_listener(game_mouse_button_pressed, game); |