From dbc36aab9f252b915d76d3bf82f1743abb8bacb9 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Tue, 21 Aug 2018 15:44:12 +0200 Subject: [PATCH] Fixes #41, Minimap --- src/defines.h | 11 ++++++----- src/gui.c | 37 +++++++++++++++++++++++++++++++++---- src/gui.h | 6 +++++- src/main.c | 15 +++++++++++---- src/map.c | 7 +++++-- src/map.h | 1 + 6 files changed, 61 insertions(+), 16 deletions(-) diff --git a/src/defines.h b/src/defines.h index 41e791f..d7db9f7 100644 --- a/src/defines.h +++ b/src/defines.h @@ -33,20 +33,21 @@ #define SPRITE_DIMENSION 16 /* Display stuff */ -#define GAME_VIEW_WIDTH (MAP_ROOM_WIDTH * TILE_DIMENSION) -#define GAME_VIEW_HEIGHT (MAP_ROOM_HEIGHT * TILE_DIMENSION) +#define GAME_VIEW_WIDTH (MAP_ROOM_WIDTH * TILE_DIMENSION) // 16 * 32 +#define GAME_VIEW_HEIGHT (MAP_ROOM_HEIGHT * TILE_DIMENSION) // 12 * 32 #define SKILL_BAR_WIDTH GAME_VIEW_WIDTH #define SKILL_BAR_HEIGHT 32 -#define RIGHT_GUI_WIDTH (10 * SPRITE_DIMENSION) -#define RIGHT_GUI_HEIGHT (GAME_VIEW_HEIGHT + SKILL_BAR_HEIGHT) +#define RIGHT_GUI_WIDTH (10 * SPRITE_DIMENSION) // 10 * 16 +#define MINIMAP_GUI_HEIGHT 128 +#define STATS_GUI_HEIGHT (GAME_VIEW_HEIGHT + SKILL_BAR_HEIGHT - MINIMAP_GUI_HEIGHT) #define BOTTOM_GUI_HEIGHT (10 * SPRITE_DIMENSION) #define BOTTOM_GUI_WIDTH (GAME_VIEW_WIDTH + RIGHT_GUI_WIDTH) #define SCREEN_WIDTH (GAME_VIEW_WIDTH + RIGHT_GUI_WIDTH) -#define SCREEN_HEIGHT (RIGHT_GUI_HEIGHT + BOTTOM_GUI_HEIGHT) +#define SCREEN_HEIGHT (GAME_VIEW_HEIGHT + SKILL_BAR_HEIGHT + BOTTOM_GUI_HEIGHT) /* Quality of life stuff */ #define DEFAULT_DIMENSION (Dimension) { 16, 16 } diff --git a/src/gui.c b/src/gui.c index 479e7fb..b70ec5e 100644 --- a/src/gui.c +++ b/src/gui.c @@ -163,12 +163,16 @@ init_sprites(Gui *gui, Camera *cam) s->pos = (Position) { 16, POS_Y_COLLECTABLES + 32 }; linkedlist_append(&gui->sprites, s); - gui->rightFrame = gui_util_create_frame_sprite(RIGHT_GUI_WIDTH/16, - RIGHT_GUI_HEIGHT/16, + gui->statsFrame = gui_util_create_frame_sprite(RIGHT_GUI_WIDTH/16, + STATS_GUI_HEIGHT/16, cam); gui->bottomFrame = gui_util_create_frame_sprite(BOTTOM_GUI_WIDTH/16, BOTTOM_GUI_HEIGHT/16, cam); + + gui->miniMapFrame = gui_util_create_frame_sprite(RIGHT_GUI_WIDTH/16, + MINIMAP_GUI_HEIGHT/16, + cam); } Gui* @@ -393,7 +397,7 @@ gui_update_player_stats(Gui *gui, Player *player, Map *map, SDL_Renderer *render void gui_render_panel(Gui *gui, Camera *cam) { - sprite_render(gui->rightFrame, cam); + sprite_render(gui->statsFrame, cam); LinkedList *item = gui->health; while (item != NULL) { Sprite *s = item->data; @@ -417,6 +421,30 @@ gui_render_panel(Gui *gui, Camera *cam) sprite_render(gui->labels[i], cam); } +void +gui_render_minimap(Gui *gui, Map *map, Camera *cam) +{ + sprite_render(gui->miniMapFrame, cam); + + SDL_Rect box = { 0, 0, 12, 8 }; + for (Uint8 i = 0; i < MAP_H_ROOM_COUNT; ++i) { + for (Uint8 j = 0; j < MAP_V_ROOM_COUNT; ++j) { + Room *room = map->rooms[i][j]; + box.x = i*14 + 10; + box.y = j*10 + 14; + if (room && room->visited) { + if (map->currentRoom.x == i && map->currentRoom.y == j) + SDL_SetRenderDrawColor(cam->renderer, 0, 255, 255, 255); + else + SDL_SetRenderDrawColor(cam->renderer, 255, 255, 255, 255); + SDL_RenderFillRect(cam->renderer, &box); + SDL_SetRenderDrawColor(cam->renderer, 60, 134, 252, 255); + SDL_RenderDrawRect(cam->renderer, &box); + } + } + } +} + void gui_log(const char *fmt, ...) { @@ -578,7 +606,8 @@ gui_destroy(Gui *gui) texture_destroy(gui->event_message); sprite_destroy(gui->bottomFrame); - sprite_destroy(gui->rightFrame); + sprite_destroy(gui->statsFrame); + sprite_destroy(gui->miniMapFrame); while (gui->sprites != NULL) sprite_destroy(linkedlist_pop(&gui->sprites)); diff --git a/src/gui.h b/src/gui.h index e70f563..f5a0d09 100644 --- a/src/gui.h +++ b/src/gui.h @@ -47,7 +47,8 @@ typedef struct Gui { LinkedList *health; LinkedList *xp_bar; Sprite *bottomFrame; - Sprite *rightFrame; + Sprite *statsFrame; + Sprite *miniMapFrame; Sprite *labels[LABEL_COUNT]; Sprite *activeTooltip; Texture *log_lines[LOG_LINES_COUNT]; @@ -64,6 +65,9 @@ gui_update_player_stats(Gui*, Player*, Map*, SDL_Renderer*); void gui_render_panel(Gui*, Camera*); +void +gui_render_minimap(Gui*, Map*, Camera*); + void gui_render_log(Gui*, Camera*); diff --git a/src/main.c b/src/main.c index 86c3e94..80c5f00 100644 --- a/src/main.c +++ b/src/main.c @@ -152,7 +152,8 @@ static GameState gGameState; static SDL_Rect gameViewport; static SDL_Rect skillBarViewport; static SDL_Rect bottomGuiViewport; -static SDL_Rect rightGuiViewport; +static SDL_Rect statsGuiViewport; +static SDL_Rect minimapViewport; static SDL_Rect menuViewport; static Turn currentTurn = PLAYER; static Input input; @@ -253,8 +254,11 @@ initViewports(void) bottomGuiViewport = (SDL_Rect) { 0, GAME_VIEW_HEIGHT + SKILL_BAR_HEIGHT, BOTTOM_GUI_WIDTH, BOTTOM_GUI_WIDTH }; - rightGuiViewport = (SDL_Rect) { GAME_VIEW_WIDTH, 0, - RIGHT_GUI_WIDTH, RIGHT_GUI_HEIGHT }; + statsGuiViewport = (SDL_Rect) { GAME_VIEW_WIDTH, 0, + RIGHT_GUI_WIDTH, STATS_GUI_HEIGHT }; + + minimapViewport = (SDL_Rect) { GAME_VIEW_WIDTH, STATS_GUI_HEIGHT, + RIGHT_GUI_WIDTH, MINIMAP_GUI_HEIGHT }; menuViewport = (SDL_Rect) { (SCREEN_WIDTH - GAME_VIEW_WIDTH)/2, @@ -707,9 +711,12 @@ run_game_render(void) actiontextbuilder_render(gCamera); gui_render_event_message(gGui, gCamera); - SDL_RenderSetViewport(gRenderer, &rightGuiViewport); + SDL_RenderSetViewport(gRenderer, &statsGuiViewport); gui_render_panel(gGui, gCamera); + SDL_RenderSetViewport(gRenderer, &minimapViewport); + gui_render_minimap(gGui, gMap, gCamera); + SDL_RenderSetViewport(gRenderer, &skillBarViewport); skillbar_render(gSkillBar, gPlayer, gCamera); diff --git a/src/map.c b/src/map.c index e19044c..a9d166f 100644 --- a/src/map.c +++ b/src/map.c @@ -27,8 +27,8 @@ #include "update_data.h" #include "trap.h" -static -Room* create_room(void) +static Room* +create_room(void) { int i, j; Room *room; @@ -40,6 +40,7 @@ Room* create_room(void) room->tiles[i][j] = NULL; room->decorations[i][j] = NULL; room->traps[i][j] = NULL; + room->visited = false; } } return room; @@ -388,6 +389,8 @@ void map_set_current_room(Map *map, Position *pos) map->currentRoom.x = MAP_H_ROOM_COUNT - 1; if (map->currentRoom.y >= MAP_V_ROOM_COUNT) map->currentRoom.y = MAP_V_ROOM_COUNT - 1; + + map->rooms[map->currentRoom.x][map->currentRoom.y]->visited = true; } static diff --git a/src/map.h b/src/map.h index a769607..d4f2c5a 100644 --- a/src/map.h +++ b/src/map.h @@ -51,6 +51,7 @@ typedef struct Room_t { MapTile* decorations[MAP_ROOM_WIDTH][MAP_ROOM_HEIGHT]; Trap* traps[MAP_ROOM_WIDTH][MAP_ROOM_HEIGHT]; RoomModifierData modifier; + bool visited; } Room; typedef struct Map_t {