Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified assets/Extras/Controller.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions data/maproombuilder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
66 changes: 53 additions & 13 deletions src/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -196,17 +197,18 @@
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;

Expand Down Expand Up @@ -472,54 +474,69 @@
}

void
gui_update_minimap(Gui *gui, Camera *cam, RoomMatrix *rm)
{
SDL_SetRenderTarget(cam->renderer, gui->miniMap->textures[0]->texture);

for (size_t i = 0; i < MAP_ROOM_WIDTH; ++i) {
for (size_t j = 0; j < MAP_ROOM_HEIGHT; ++j) {
const RoomSpace* space = &rm->spaces[i][j];
const float x = (float)(i + rm->roomPos.x * MAP_ROOM_WIDTH);
const float y = (float)(j + rm->roomPos.y * MAP_ROOM_HEIGHT);

SDL_Color c = {0, 0, 0, SDL_ALPHA_OPAQUE };
if (SPACE_IS_LETHAL(space)) {
c.a = SDL_ALPHA_TRANSPARENT;
} else if (space->trap) {
c.r = 255;
} else if (space->door) {
c.r = 0; c.g = 0; c.b = 255;
} else if (space->tile && space->tile->levelExit) {
c.r = 0; c.g = 255; c.b = 0;
} 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 {
c.r = 200; c.g = 200; c.b = 200;
}

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);
}

void

Check notice on line 539 in src/gui.c

View check run for this annotation

codefactor.io / CodeFactor

src/gui.c#L477-L539

Complex Method
gui_render_minimap(Gui *gui, Camera *cam, RoomMatrix *rm)
{
sprite_render(gui->miniMap, cam);
Expand All @@ -532,6 +549,29 @@
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, ...)
{
Expand Down
8 changes: 8 additions & 0 deletions src/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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*);

Expand Down
5 changes: 4 additions & 1 deletion src/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
key = KEY_ENTER; break;
case SDLK_SPACE:
key = KEY_SPACE; break;
case SDLK_TAB:
key = KEY_TAB; break;
default:
key = 0; break;
}
Expand All @@ -91,42 +93,43 @@
}

static Uint64
get_event_button(SDL_Event *event)
{
Uint64 key;
switch (event->jbutton.button) {
case SDL_GAMEPAD_BUTTON_DPAD_UP :
key = KEY_UP; break;
case SDL_GAMEPAD_BUTTON_DPAD_DOWN :
key = KEY_DOWN; break;
case SDL_GAMEPAD_BUTTON_DPAD_LEFT :
key = KEY_LEFT; break;
case SDL_GAMEPAD_BUTTON_DPAD_RIGHT :
key = KEY_RIGHT; break;
case SDL_GAMEPAD_BUTTON_SOUTH :
key = KEY_NUM1 | KEY_ENTER; break;
case SDL_GAMEPAD_BUTTON_WEST :
key = KEY_NUM2; break;
case SDL_GAMEPAD_BUTTON_NORTH :
key = KEY_NUM3; break;
case SDL_GAMEPAD_BUTTON_EAST :
key = KEY_NUM4; break;
case SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER :
key = KEY_NUM5; break;
case SDL_GAMEPAD_BUTTON_START :
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;
}
return key;
}

static Uint64

Check notice on line 132 in src/input.c

View check run for this annotation

codefactor.io / CodeFactor

src/input.c#L96-L132

Complex Method
get_axis_motion(SDL_Event *event)
{
Uint64 key;
Expand Down
1 change: 1 addition & 0 deletions src/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -807,6 +808,9 @@ handle_main_input(void)
}

handle_settings_input();
if (input_key_is_pressed(&input, KEY_TAB)) {
gShowMap = !gShowMap;
}
}

static bool
Expand Down Expand Up @@ -907,7 +911,7 @@ check_next_level(void)
}
}

static void
static inline void
populateUpdateData(UpdateData *data, float deltatime)
{
data->player = gPlayer;
Expand Down Expand Up @@ -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) {
Expand Down
26 changes: 13 additions & 13 deletions src/texture.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions src/texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/tooltip.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions src/tooltip_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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", "",
Expand Down
Loading