diff --git a/assets/Extras/Controller.png b/assets/Extras/Controller.png index d40f97a6..7c6f256f 100644 Binary files a/assets/Extras/Controller.png and b/assets/Extras/Controller.png differ diff --git a/data/maproombuilder.lua b/data/maproombuilder.lua index 6841703c..d6799b15 100644 --- a/data/maproombuilder.lua +++ b/data/maproombuilder.lua @@ -436,7 +436,7 @@ local function build_normal_room(room) room.modifier.type = "FIRE" room.modifier.arg = "" elseif ((not pitsAdded and not crumbling and (CURRENT_LEVEL > 1 or QUICK_MODE)) or CURRENT_LEVEL > 3) and random(8) == 1 then - directions = { "LEFT", "RIGHT", "UP", "DOWN" } + local directions = { "LEFT", "RIGHT", "UP", "DOWN" } room.modifier.type = "WINDY" room.modifier.arg = directions[random(#directions)] end @@ -466,7 +466,7 @@ function module.is_tile_avilable(room, rx, ry) end function module.create_empty_room() - room = { + local room = { exits = {}, active = false, goal = false, diff --git a/src/gui.c b/src/gui.c index aef2a1a3..7a0398ad 100644 --- a/src/gui.c +++ b/src/gui.c @@ -26,14 +26,15 @@ #include "SDL3/SDL_blendmode.h" #include "SDL3/SDL_pixels.h" #include "SDL3/SDL_render.h" +#include "SDL3/SDL_surface.h" #include "defines.h" +#include "map_room_modifiers.h" #include "roommatrix.h" #include "texture.h" #include "util.h" #include "map.h" #include "texturecache.h" #include "gui_util.h" -#include "tooltip.h" #define DEFAULT_LOG { NULL, LOG_LINES_COUNT, 0, 200 } #define DEFAULT_EVENT_MESSAGES { NULL, 5, 0, 200 } @@ -196,17 +197,18 @@ init_sprites(Gui *gui, Camera *cam) Texture *texture = texture_create(); texture->dim = (Dimension) { RIGHT_GUI_WIDTH, - MINIMAP_GUI_HEIGHT + MINIMAP_GUI_HEIGHT - 8 }; minimap->textures[0] = texture; minimap->destroyTextures = true; minimap->pos = (Position) { 0, 4 }; - minimap->dim = (Dimension) { RIGHT_GUI_WIDTH, MINIMAP_GUI_HEIGHT }; + minimap->dim = (Dimension) { RIGHT_GUI_WIDTH, MINIMAP_GUI_HEIGHT - 8 }; minimap->fixed = true; texture_create_blank(texture, SDL_TEXTUREACCESS_TARGET, cam->renderer); texture_set_blend_mode(texture, SDL_BLENDMODE_BLEND); + texture_set_scale_mode(texture, SDL_SCALEMODE_NEAREST); gui->miniMap = minimap; @@ -494,7 +496,7 @@ gui_update_minimap(Gui *gui, Camera *cam, RoomMatrix *rm) } else if (space->wall || SPACE_IS_OCCUPIED(space)) { c.r = 200; c.g = 200; c.b = 200; } else if (space->tile == NULL) { - c.r = 0; c.g = 0; c.b = 0; + c.a = SDL_ALPHA_TRANSPARENT; } else if (SPACE_IS_WALKABLE(space)) { c.r = 94; c.g = 77; c.b = 179; } else { @@ -503,19 +505,34 @@ gui_update_minimap(Gui *gui, Camera *cam, RoomMatrix *rm) SDL_SetRenderDrawColor(cam->renderer, c.r, c.g, c.b, c.a); SDL_RenderPoint(cam->renderer, x, y); + } } - SDL_SetRenderTarget(cam->renderer, NULL); -} + if (rm->modifier && rm->modifier->type != RMOD_TYPE_NONE) { + const SDL_FRect mod_box = { + (float) rm->roomPos.x * MAP_ROOM_WIDTH, + (float) rm->roomPos.y * MAP_ROOM_HEIGHT, + (float) MAP_ROOM_WIDTH, + (float) MAP_ROOM_HEIGHT, + }; + switch (rm->modifier->type) { + case RMOD_TYPE_WINDY: + SDL_SetRenderDrawColor(cam->renderer, 0, 0, 255, 100); + break; + case RMOD_TYPE_FIRE: + SDL_SetRenderDrawColor(cam->renderer, 255, 0, 0, 100); + break; + case RMOD_TYPE_CRUMBLING: + SDL_SetRenderDrawColor(cam->renderer, 247, 151, 67, 100); + break; + default: + assert(false); + + } + SDL_RenderFillRect(cam->renderer, &mod_box); + } -void -gui_reset(Gui *gui, Camera *cam) -{ - // Clear the minimap - SDL_SetRenderTarget(cam->renderer, gui->miniMap->textures[0]->texture); - SDL_SetRenderDrawColor(cam->renderer, 0, 0, 0, SDL_ALPHA_TRANSPARENT); - SDL_RenderClear(cam->renderer); SDL_SetRenderTarget(cam->renderer, NULL); } @@ -532,6 +549,29 @@ gui_render_minimap(Gui *gui, Camera *cam, RoomMatrix *rm) SDL_RenderRect(cam->renderer, &r); } +void +gui_render_minimap_overlay(Gui *gui, Camera *cam) +{ + static SDL_Rect target_box = { + 50, 50, GAME_VIEW_WIDTH - 100, GAME_VIEW_HEIGHT - 100 + }; + + Texture *texture = gui->miniMap->textures[0]; + texture_set_alpha(texture, 200); + texture_render_clip_ex(texture, &target_box, NULL, 0.0, NULL, SDL_FLIP_NONE, cam); + texture_set_alpha(texture, SDL_ALPHA_OPAQUE); +} + +void +gui_reset(Gui *gui, Camera *cam) +{ + // Clear the minimap + SDL_SetRenderTarget(cam->renderer, gui->miniMap->textures[0]->texture); + SDL_SetRenderDrawColor(cam->renderer, 0, 0, 0, SDL_ALPHA_TRANSPARENT); + SDL_RenderClear(cam->renderer); + SDL_SetRenderTarget(cam->renderer, NULL); +} + void gui_log(const char *fmt, ...) { diff --git a/src/gui.h b/src/gui.h index ddc16f4d..c2422597 100644 --- a/src/gui.h +++ b/src/gui.h @@ -95,6 +95,14 @@ gui_reset(Gui *gui, Camera *cam); void gui_render_minimap(Gui *gui, Camera *cam, RoomMatrix *rm); +/** + * \brief Render the large minimap overlay + * \param[in] gui The gui + * \param[in] cam The camera + */ +void +gui_render_minimap_overlay(Gui *gui, Camera *cam); + void gui_render_log(Gui*, Camera*); diff --git a/src/input.c b/src/input.c index d9e529da..b124136e 100644 --- a/src/input.c +++ b/src/input.c @@ -84,6 +84,8 @@ get_event_key(SDL_Event *event) key = KEY_ENTER; break; case SDLK_SPACE: key = KEY_SPACE; break; + case SDLK_TAB: + key = KEY_TAB; break; default: key = 0; break; } @@ -117,8 +119,9 @@ get_event_button(SDL_Event *event) key = KEY_ENTER; break; case SDL_GAMEPAD_BUTTON_BACK : key = KEY_ESC; break; - case SDL_GAMEPAD_BUTTON_LEFT_STICK : case SDL_GAMEPAD_BUTTON_RIGHT_STICK : + key = KEY_TAB; break; + case SDL_GAMEPAD_BUTTON_LEFT_STICK : key = KEY_SPACE; break; default: key = 0; break; diff --git a/src/input.h b/src/input.h index eec925cc..1997cc6b 100644 --- a/src/input.h +++ b/src/input.h @@ -39,6 +39,7 @@ #define KEY_ESC 0x4000 #define KEY_ENTER 0x8000 #define KEY_SPACE 0x10000 +#define KEY_TAB 0x20000 #define KEY_CTRL_M 0x1 #define KEY_CTRL_S 0x2 diff --git a/src/main.c b/src/main.c index 3af4a30d..89ddc5fc 100644 --- a/src/main.c +++ b/src/main.c @@ -117,6 +117,7 @@ static bool is_player_dead(void); static void initGamepads(void); static SDL_Surface *window_icon = NULL; +static bool gShowMap = false; static bool initSDL(void) @@ -807,6 +808,9 @@ handle_main_input(void) } handle_settings_input(); + if (input_key_is_pressed(&input, KEY_TAB)) { + gShowMap = !gShowMap; + } } static bool @@ -907,7 +911,7 @@ check_next_level(void) } } -static void +static inline void populateUpdateData(UpdateData *data, float deltatime) { data->player = gPlayer; @@ -1071,6 +1075,9 @@ run_game_render(void) SDL_SetRenderViewport(gRenderer, &mainViewport); particle_engine_render_global(gCamera); + if (gShowMap) { + gui_render_minimap_overlay(gGui, gCamera); + } gui_render_tooltip(gGui, gCamera); if (gGameState == IN_GAME_MENU) { diff --git a/src/texture.c b/src/texture.c index b51b0e11..ff7d7041 100644 --- a/src/texture.c +++ b/src/texture.c @@ -283,8 +283,8 @@ texture_render_clip(Texture *texture, SDL_Rect *box, SDL_Rect *clip, Camera *cam } void -texture_render_clip_ex(Texture *texture, SDL_Rect *box, SDL_Rect *clip, double angle, SDL_Point *point, - SDL_FlipMode flipType, Camera *cam) +texture_render_clip_ex(Texture *texture, SDL_Rect *dst, SDL_Rect *src, double angle, SDL_Point *rotation_point, + SDL_FlipMode flip_mode, Camera *cam) { if (!texture->texture) return; @@ -294,22 +294,22 @@ texture_render_clip_ex(Texture *texture, SDL_Rect *box, SDL_Rect *clip, double a SDL_FRect fclip; SDL_FPoint fpoint; - if (box) - SDL_RectToFRect(box, &fbox); - if (clip) - SDL_RectToFRect(clip, &fclip); - if (point) { - fpoint.x = (float) point->x; - fpoint.y = (float) point->y; + if (dst) + SDL_RectToFRect(dst, &fbox); + if (src) + SDL_RectToFRect(src, &fclip); + if (rotation_point) { + fpoint.x = (float) rotation_point->x; + fpoint.y = (float) rotation_point->y; } SDL_RenderTextureRotated(cam->renderer, texture->texture, - clip ? &fclip : NULL, - box ? &fbox : NULL, + src ? &fclip : NULL, + dst ? &fbox : NULL, angle, - point ? &fpoint : NULL, - flipType); + rotation_point ? &fpoint : NULL, + flip_mode); texture->lastAccess = SDL_GetTicks(); } diff --git a/src/texture.h b/src/texture.h index a6cb94f7..0a2ab37f 100644 --- a/src/texture.h +++ b/src/texture.h @@ -95,8 +95,8 @@ void texture_render_clip(Texture*, SDL_Rect*, SDL_Rect*, Camera*); void -texture_render_clip_ex(Texture*, SDL_Rect*, SDL_Rect*, double angle, SDL_Point*, - SDL_FlipMode, Camera*); +texture_render_clip_ex(Texture *texture, SDL_Rect *dst, SDL_Rect *src, double angle, SDL_Point *rotation_point, + SDL_FlipMode flip_mode, Camera *cam); void texture_destroy(Texture *texture); diff --git a/src/tooltip.c b/src/tooltip.c index 9057bc77..bf3f9b3b 100644 --- a/src/tooltip.c +++ b/src/tooltip.c @@ -47,6 +47,8 @@ render_button_texture_for(const char *text, Position pos, Camera *cam, GamepadTy clip = CONTROLLER_OPT(32, controller_type); } else if (strcmp(text, "ENTER") == 0) { clip = CONTROLLER_OPT(0, controller_type); + } else if (strcmp(text, "TAB") == 0) { + clip = CLIP16(32, 80); } else if (strcmp(text, "SPACE") == 0) { clip = CLIP16(0, 80); } else { diff --git a/src/tooltip_manager.c b/src/tooltip_manager.c index 0d0dc94b..0fe57967 100644 --- a/src/tooltip_manager.c +++ b/src/tooltip_manager.c @@ -79,6 +79,8 @@ static char *how_to_play_tooltip[] = { "", " TOGGLE FULLSCREEN: CTRL + F", "", "", + " TOGGLE MAP: ", "TAB", "", + "", " TOGGLE MENU: ", "ESC", "", "", " Your stats and inventory are listed in the right panel", "",