Fixes #41, Minimap

This commit is contained in:
Linus Probert 2018-08-21 15:44:12 +02:00
parent c390c024f6
commit dbc36aab9f
6 changed files with 61 additions and 16 deletions

View File

@ -33,20 +33,21 @@
#define SPRITE_DIMENSION 16 #define SPRITE_DIMENSION 16
/* Display stuff */ /* Display stuff */
#define GAME_VIEW_WIDTH (MAP_ROOM_WIDTH * TILE_DIMENSION) #define GAME_VIEW_WIDTH (MAP_ROOM_WIDTH * TILE_DIMENSION) // 16 * 32
#define GAME_VIEW_HEIGHT (MAP_ROOM_HEIGHT * TILE_DIMENSION) #define GAME_VIEW_HEIGHT (MAP_ROOM_HEIGHT * TILE_DIMENSION) // 12 * 32
#define SKILL_BAR_WIDTH GAME_VIEW_WIDTH #define SKILL_BAR_WIDTH GAME_VIEW_WIDTH
#define SKILL_BAR_HEIGHT 32 #define SKILL_BAR_HEIGHT 32
#define RIGHT_GUI_WIDTH (10 * SPRITE_DIMENSION) #define RIGHT_GUI_WIDTH (10 * SPRITE_DIMENSION) // 10 * 16
#define RIGHT_GUI_HEIGHT (GAME_VIEW_HEIGHT + SKILL_BAR_HEIGHT) #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_HEIGHT (10 * SPRITE_DIMENSION)
#define BOTTOM_GUI_WIDTH (GAME_VIEW_WIDTH + RIGHT_GUI_WIDTH) #define BOTTOM_GUI_WIDTH (GAME_VIEW_WIDTH + RIGHT_GUI_WIDTH)
#define SCREEN_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 */ /* Quality of life stuff */
#define DEFAULT_DIMENSION (Dimension) { 16, 16 } #define DEFAULT_DIMENSION (Dimension) { 16, 16 }

View File

@ -163,12 +163,16 @@ init_sprites(Gui *gui, Camera *cam)
s->pos = (Position) { 16, POS_Y_COLLECTABLES + 32 }; s->pos = (Position) { 16, POS_Y_COLLECTABLES + 32 };
linkedlist_append(&gui->sprites, s); linkedlist_append(&gui->sprites, s);
gui->rightFrame = gui_util_create_frame_sprite(RIGHT_GUI_WIDTH/16, gui->statsFrame = gui_util_create_frame_sprite(RIGHT_GUI_WIDTH/16,
RIGHT_GUI_HEIGHT/16, STATS_GUI_HEIGHT/16,
cam); cam);
gui->bottomFrame = gui_util_create_frame_sprite(BOTTOM_GUI_WIDTH/16, gui->bottomFrame = gui_util_create_frame_sprite(BOTTOM_GUI_WIDTH/16,
BOTTOM_GUI_HEIGHT/16, BOTTOM_GUI_HEIGHT/16,
cam); cam);
gui->miniMapFrame = gui_util_create_frame_sprite(RIGHT_GUI_WIDTH/16,
MINIMAP_GUI_HEIGHT/16,
cam);
} }
Gui* Gui*
@ -393,7 +397,7 @@ gui_update_player_stats(Gui *gui, Player *player, Map *map, SDL_Renderer *render
void void
gui_render_panel(Gui *gui, Camera *cam) gui_render_panel(Gui *gui, Camera *cam)
{ {
sprite_render(gui->rightFrame, cam); sprite_render(gui->statsFrame, cam);
LinkedList *item = gui->health; LinkedList *item = gui->health;
while (item != NULL) { while (item != NULL) {
Sprite *s = item->data; Sprite *s = item->data;
@ -417,6 +421,30 @@ gui_render_panel(Gui *gui, Camera *cam)
sprite_render(gui->labels[i], 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 void
gui_log(const char *fmt, ...) gui_log(const char *fmt, ...)
{ {
@ -578,7 +606,8 @@ gui_destroy(Gui *gui)
texture_destroy(gui->event_message); texture_destroy(gui->event_message);
sprite_destroy(gui->bottomFrame); sprite_destroy(gui->bottomFrame);
sprite_destroy(gui->rightFrame); sprite_destroy(gui->statsFrame);
sprite_destroy(gui->miniMapFrame);
while (gui->sprites != NULL) while (gui->sprites != NULL)
sprite_destroy(linkedlist_pop(&gui->sprites)); sprite_destroy(linkedlist_pop(&gui->sprites));

View File

@ -47,7 +47,8 @@ typedef struct Gui {
LinkedList *health; LinkedList *health;
LinkedList *xp_bar; LinkedList *xp_bar;
Sprite *bottomFrame; Sprite *bottomFrame;
Sprite *rightFrame; Sprite *statsFrame;
Sprite *miniMapFrame;
Sprite *labels[LABEL_COUNT]; Sprite *labels[LABEL_COUNT];
Sprite *activeTooltip; Sprite *activeTooltip;
Texture *log_lines[LOG_LINES_COUNT]; Texture *log_lines[LOG_LINES_COUNT];
@ -64,6 +65,9 @@ gui_update_player_stats(Gui*, Player*, Map*, SDL_Renderer*);
void void
gui_render_panel(Gui*, Camera*); gui_render_panel(Gui*, Camera*);
void
gui_render_minimap(Gui*, Map*, Camera*);
void void
gui_render_log(Gui*, Camera*); gui_render_log(Gui*, Camera*);

View File

@ -152,7 +152,8 @@ static GameState gGameState;
static SDL_Rect gameViewport; static SDL_Rect gameViewport;
static SDL_Rect skillBarViewport; static SDL_Rect skillBarViewport;
static SDL_Rect bottomGuiViewport; static SDL_Rect bottomGuiViewport;
static SDL_Rect rightGuiViewport; static SDL_Rect statsGuiViewport;
static SDL_Rect minimapViewport;
static SDL_Rect menuViewport; static SDL_Rect menuViewport;
static Turn currentTurn = PLAYER; static Turn currentTurn = PLAYER;
static Input input; static Input input;
@ -253,8 +254,11 @@ initViewports(void)
bottomGuiViewport = (SDL_Rect) { 0, GAME_VIEW_HEIGHT + SKILL_BAR_HEIGHT, bottomGuiViewport = (SDL_Rect) { 0, GAME_VIEW_HEIGHT + SKILL_BAR_HEIGHT,
BOTTOM_GUI_WIDTH, BOTTOM_GUI_WIDTH }; BOTTOM_GUI_WIDTH, BOTTOM_GUI_WIDTH };
rightGuiViewport = (SDL_Rect) { GAME_VIEW_WIDTH, 0, statsGuiViewport = (SDL_Rect) { GAME_VIEW_WIDTH, 0,
RIGHT_GUI_WIDTH, RIGHT_GUI_HEIGHT }; RIGHT_GUI_WIDTH, STATS_GUI_HEIGHT };
minimapViewport = (SDL_Rect) { GAME_VIEW_WIDTH, STATS_GUI_HEIGHT,
RIGHT_GUI_WIDTH, MINIMAP_GUI_HEIGHT };
menuViewport = (SDL_Rect) { menuViewport = (SDL_Rect) {
(SCREEN_WIDTH - GAME_VIEW_WIDTH)/2, (SCREEN_WIDTH - GAME_VIEW_WIDTH)/2,
@ -707,9 +711,12 @@ run_game_render(void)
actiontextbuilder_render(gCamera); actiontextbuilder_render(gCamera);
gui_render_event_message(gGui, gCamera); gui_render_event_message(gGui, gCamera);
SDL_RenderSetViewport(gRenderer, &rightGuiViewport); SDL_RenderSetViewport(gRenderer, &statsGuiViewport);
gui_render_panel(gGui, gCamera); gui_render_panel(gGui, gCamera);
SDL_RenderSetViewport(gRenderer, &minimapViewport);
gui_render_minimap(gGui, gMap, gCamera);
SDL_RenderSetViewport(gRenderer, &skillBarViewport); SDL_RenderSetViewport(gRenderer, &skillBarViewport);
skillbar_render(gSkillBar, gPlayer, gCamera); skillbar_render(gSkillBar, gPlayer, gCamera);

View File

@ -27,8 +27,8 @@
#include "update_data.h" #include "update_data.h"
#include "trap.h" #include "trap.h"
static static Room*
Room* create_room(void) create_room(void)
{ {
int i, j; int i, j;
Room *room; Room *room;
@ -40,6 +40,7 @@ Room* create_room(void)
room->tiles[i][j] = NULL; room->tiles[i][j] = NULL;
room->decorations[i][j] = NULL; room->decorations[i][j] = NULL;
room->traps[i][j] = NULL; room->traps[i][j] = NULL;
room->visited = false;
} }
} }
return room; return room;
@ -388,6 +389,8 @@ void map_set_current_room(Map *map, Position *pos)
map->currentRoom.x = MAP_H_ROOM_COUNT - 1; map->currentRoom.x = MAP_H_ROOM_COUNT - 1;
if (map->currentRoom.y >= MAP_V_ROOM_COUNT) if (map->currentRoom.y >= MAP_V_ROOM_COUNT)
map->currentRoom.y = MAP_V_ROOM_COUNT - 1; map->currentRoom.y = MAP_V_ROOM_COUNT - 1;
map->rooms[map->currentRoom.x][map->currentRoom.y]->visited = true;
} }
static static

View File

@ -51,6 +51,7 @@ typedef struct Room_t {
MapTile* decorations[MAP_ROOM_WIDTH][MAP_ROOM_HEIGHT]; MapTile* decorations[MAP_ROOM_WIDTH][MAP_ROOM_HEIGHT];
Trap* traps[MAP_ROOM_WIDTH][MAP_ROOM_HEIGHT]; Trap* traps[MAP_ROOM_WIDTH][MAP_ROOM_HEIGHT];
RoomModifierData modifier; RoomModifierData modifier;
bool visited;
} Room; } Room;
typedef struct Map_t { typedef struct Map_t {