From 5588abc063a523aafe04f7ea7d390dcb1081809f Mon Sep 17 00:00:00 2001 From: Steve Date: Sun, 4 Feb 2018 07:50:54 +0000 Subject: [PATCH] Show hud messages. --- src/world/hud.c | 42 +++++++++++++++++++++++++++++++++++++++++- src/world/hud.h | 3 +++ src/world/world.c | 5 ++--- src/world/world.h | 1 + 4 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/world/hud.c b/src/world/hud.c index b8d5cca..3a68dc5 100644 --- a/src/world/hud.c +++ b/src/world/hud.c @@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static int messageTime; static char message[MAX_DESCRIPTION_LENGTH]; static int messageType; +static SDL_Color messageColor; static char infoMessage[MAX_DESCRIPTION_LENGTH]; @@ -30,6 +31,8 @@ void initHud(void) { messageTime = FPS * 2; messageType = MSG_STANDARD; + strcpy(message, ""); + messageColor = colors.white; } void doHud(void) @@ -46,11 +49,27 @@ void doHud(void) void drawHud(void) { - drawText(SCREEN_WIDTH / 2, SCREEN_HEIGHT - 25, 14, TA_CENTER, colors.white, "Bob [%.0f, %.0f]", world.bob->x / MAP_TILE_SIZE, world.bob->y / MAP_TILE_SIZE); + int x, y; + + if (messageTime > 0) + { + drawRect(0, SCREEN_HEIGHT - 32, SCREEN_WIDTH, 32, 0, 0, 0, 200); + + drawText(SCREEN_WIDTH / 2, SCREEN_HEIGHT - 26, 16, TA_CENTER, messageColor, message); + } + + if (dev.debug) + { + x = -camera.x + world.bob->x + (world.bob->w / 2); + y = -camera.y + world.bob->y - world.bob->h; + + drawText(x, y, 14, TA_CENTER, colors.white, "[%.0f, %.0f]", world.bob->x / MAP_TILE_SIZE, world.bob->y / MAP_TILE_SIZE); + } } void setGameplayMessage(int newMessageType, const char *format, ...) { + int i; char newMessage[MAX_DESCRIPTION_LENGTH]; va_list args; @@ -66,7 +85,28 @@ void setGameplayMessage(int newMessageType, const char *format, ...) messageType = newMessageType; messageTime = FPS * 3; + for (i = 0 ; i < strlen(message) ; i++) + { + message[i] = toupper(message[i]); + } + SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "%s", message); + + switch (messageType) + { + case MSG_STANDARD: + case MSG_GAMEPLAY: + messageColor = colors.white; + break; + + case MSG_PROGRESS: + messageColor = colors.cyan; + break; + + case MSG_OBJECTIVE: + messageColor = colors.green; + break; + } } } diff --git a/src/world/hud.h b/src/world/hud.h index 7a15ba2..9a7672d 100644 --- a/src/world/hud.h +++ b/src/world/hud.h @@ -22,6 +22,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern void showWidgetGroup(char *groupName); extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...); +extern void drawRect(int x, int y, int w, int h, int r, int g, int b, int a); +extern Dev dev; +extern Camera camera; extern Colors colors; extern World world; diff --git a/src/world/world.c b/src/world/world.c index 450eda7..7f6d1de 100644 --- a/src/world/world.c +++ b/src/world/world.c @@ -42,6 +42,8 @@ void initWorld(void) background = getTexture(world.background); initObjectives(); + + initHud(); world.enemySpawnTimer = (FPS * rrnd(world.minEnemySpawnTime, world.maxEnemySpawnTime)); @@ -65,9 +67,6 @@ void initWorld(void) app.delegate.draw = draw; startMission(); - - world.bob->x = 110 * MAP_TILE_SIZE; - world.bob->y = 105 * MAP_TILE_SIZE; } static void logic(void) diff --git a/src/world/world.h b/src/world/world.h index 8b60ca0..ed13fd4 100644 --- a/src/world/world.h +++ b/src/world/world.h @@ -52,6 +52,7 @@ extern void drawMap(void); extern void blitScaled(SDL_Texture *texture, int x, int y, int w, int h, int center); extern void clearScreen(void); extern void drawHud(void); +extern void initHud(void); extern App app; extern Dev dev;