From ee50b88f56ca0fe60e2c82f1dc2ffa926209cdd8 Mon Sep 17 00:00:00 2001 From: SemvdH Date: Wed, 25 Aug 2021 23:36:31 +0200 Subject: [PATCH] [ADD] pretty display of score in a separate window #4 --- src/main.c | 43 +++++++------------------------------------ src/toolbox/drawing.c | 36 ++++++++++++++++++++++++++++++++++++ src/toolbox/drawing.h | 25 +++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 36 deletions(-) diff --git a/src/main.c b/src/main.c index ac56c6f..277c2e7 100644 --- a/src/main.c +++ b/src/main.c @@ -537,13 +537,6 @@ void draw_menu() void draw_game() { sprites_draw_player(player_x, player_y, PLAYER_SCALE); - // vita2d_draw_rectangle(x2_pos, y2_pos, (float)10, (float)10, RGBA8(169, 60, 23, 255)); - - // vita2d_draw_rectangle(300, 50, 30, 30, RGBA8(255, 0, 255, 255)); - - char timertext[100]; - sprintf(timertext, "time %lu", bullet_timer.time); - vita2d_pgf_draw_text(pgf, 10, 30, RGBA8(0, 255, 150, 255), 1.0f, timertext); for (int i = 0; i < 255; i++) { @@ -556,39 +549,17 @@ void draw_game() sprites_draw_enemy(&enemies[i]); } - char score_text[40]; - sprintf(score_text, "score: %07d", score); - vita2d_pvf_draw_text(pvf, 700, 100, RGBA8(0, 255, 0, 255), 1.0f, score_text); + drawing_draw_window_filled(20, 40, 160, 80, "SCORE", pgf, SECONDARY_BORDER_COLOR); + + char score_text[15]; + sprintf(score_text, "%07d", score); + vita2d_pgf_draw_text(pgf, 42, 97, COLOR_BLACK, 1.2f, score_text); - drawing_draw_rectangle_open(0, 0, SCREEN_WIDTH, SCREEN_HEIGTH, 10, MAIN_BORDER_COLOR); - drawing_draw_hline(0, 10, SCREEN_WIDTH, 20, MAIN_BORDER_COLOR); - for (int i = 0; i < 3; i++) - { - int box_x = SCREEN_WIDTH - 22 * i - 30; - vita2d_draw_rectangle(box_x, 6, 20, 20, SECONDARY_BORDER_COLOR); - drawing_draw_rectangle_open(box_x, 6, 20, 20, 2, COLOR_BLACK); - switch (i) - { - case 0: - for (int i = 0; i < 3; i++) - { - vita2d_draw_line(box_x + 4, 8 + i, box_x + 16, 20 + i, COLOR_MAGENTA); - vita2d_draw_line(box_x + 16, 8 + i, box_x + 4, 20 + i, COLOR_MAGENTA); - } - break; - case 1: - drawing_draw_rectangle_open(box_x + 4, 12, 12, 10, 3, COLOR_MAGENTA); - break; - case 2: - drawing_draw_hline(box_x + 4, 20, 12, 3, COLOR_MAGENTA); - break; - } - } - drawing_draw_rectangle_open(0, 0, SCREEN_WIDTH, SCREEN_HEIGTH, 3, COLOR_BLACK); // line around screen char title_text[40]; sprintf(title_text, "CYBERSHOT_PSVITA - FPS: %d", timing_get_fps(deltaTime)); - vita2d_pgf_draw_text(pgf, 20, 18, COLOR_MAGENTA, 0.8, title_text); + + drawing_draw_window_clear(0, 0, SCREEN_WIDTH, SCREEN_HEIGTH, title_text, pgf); } void draw_gameover() diff --git a/src/toolbox/drawing.c b/src/toolbox/drawing.c index e9a1970..3b5d356 100644 --- a/src/toolbox/drawing.c +++ b/src/toolbox/drawing.c @@ -25,4 +25,40 @@ void drawing_draw_vline(float x0, float y0, float height, int thiccness, unsigne { vita2d_draw_line(x0 + i, y0, x0 + i, y0 + height, color); } +} + +void drawing_draw_window_clear(float x, float y, float width, float heigth, const char *title_text, vita2d_pgf *pgf) +{ + drawing_draw_rectangle_open(x, y, width, heigth, 10, MAIN_BORDER_COLOR); + drawing_draw_hline(x, y + 10, width, 20, MAIN_BORDER_COLOR); + for (int i = 0; i < 3; i++) + { + int box_x = width - 22 * i - 30 + x; + vita2d_draw_rectangle(box_x, y + 6, 20, 20, COLOR_MAGENTA); + drawing_draw_rectangle_open(box_x, y + 6, 20, 20, 2, COLOR_BLACK); + switch (i) + { + case 0: + for (int i = 0; i < 3; i++) + { + vita2d_draw_line(box_x + 4, 8 + i + y, box_x + 16, 20 + i + y, COLOR_BLACK); + vita2d_draw_line(box_x + 16, 8 + i + y, box_x + 4, 20 + i + y, COLOR_BLACK); + } + break; + case 1: + drawing_draw_rectangle_open(box_x + 4, y + 12, 12, 10, 3, COLOR_BLACK); + break; + case 2: + drawing_draw_hline(box_x + 4, y + 20, 12, 3, COLOR_BLACK); + break; + } + } + drawing_draw_rectangle_open(x, y, width, heigth, 2, COLOR_BLACK); // line around screen + vita2d_pgf_draw_text(pgf, x + 10, y + 23, COLOR_MAGENTA, 0.9, title_text); +} + +void drawing_draw_window_filled(float x, float y, float width, float heigth, const char *title_text, vita2d_pgf *pgf, unsigned int color) +{ + drawing_draw_window_clear(x, y, width, heigth, title_text, pgf); + vita2d_draw_rectangle(x + 10, y + 30, width - 20, heigth - 40, color); } \ No newline at end of file diff --git a/src/toolbox/drawing.h b/src/toolbox/drawing.h index 1ad8a40..eabd456 100644 --- a/src/toolbox/drawing.h +++ b/src/toolbox/drawing.h @@ -53,4 +53,29 @@ void drawing_draw_hline(float x0, float y0, float width, int thiccness, unsigned */ void drawing_draw_vline(float x0, float y0, float height, int thiccness, unsigned int color); +/** + * @brief draws a window frame with the specified features + * + * @param x the top left x position of the frame + * @param y the top left y position of the frame + * @param width the width of the frame + * @param heigth the heigth of the frame + * @param title_text the title text to be displayed at the top of the frame + * @param pgf pointer to the pgf font to be used + */ +void drawing_draw_window_clear(float x, float y, float width, float heigth, const char *title_text, vita2d_pgf *pgf); + +/** + * @brief draws a window frame with the specified features + * + * @param x the top left x position of the frame + * @param y the top left y position of the frame + * @param width the width of the frame + * @param heigth the heigth of the frame + * @param title_text the title text to be displayed at the top of the frame + * @param pgf pointer to the pgf font to be used + * @param color the color of the background of the window + */ +void drawing_draw_window_filled(float x, float y, float width, float heigth, const char *title_text, vita2d_pgf *pgf, unsigned int color); + #endif // !DRAWING_H