diff --git a/assets/overlay2.png b/assets/overlay2.png index 9334045..7e3977d 100644 Binary files a/assets/overlay2.png and b/assets/overlay2.png differ diff --git a/assets/shaders/frag.glsl b/assets/shaders/frag.glsl index 750b2b3..36d4016 100644 --- a/assets/shaders/frag.glsl +++ b/assets/shaders/frag.glsl @@ -51,16 +51,19 @@ void main() noise3 *= 0.9 + 0.1 * sin(uv.y * 400.0); float offset = 0.001 / (u_battery * u_battery + 0.001 ); + offset = offset > .05 ? .05 : offset; float r = texture(Texture1, TexCoord + vec2(offset * 5, 0.0)).r; float g = texture(Texture1, TexCoord + vec2(0.0, offset * 2.0)).g; float b = texture(Texture1, TexCoord - vec2(offset, 0.0)).b; vec3 color = vec3(r, g, b); - vec3 noisyColor = mix(color.rgb, vec3(noise, noise2, noise3), strength / 2); + vec3 noisyColor = mix(color.rgb, vec3(noise, noise2, noise3), (strength / 2 + .2)); // float flicker = 0.75 + sin(u_time * 6.0 + sin(u_time * 3)) * 0.25; - float flicker = 0.75 + 0.25 * sin(u_time + sin(u_time * 7.0)); + float flicker = (1 - strength * 0.5) + 0.25 * (strength * sin(u_time + sin(u_time * 7.0) + 1)); + + float dim = u_battery < 0.1 ? u_battery * 10.0 : 1; + FragColor = vec4(noisyColor, texColor.a * flicker * dim); - FragColor = vec4(noisyColor, texColor.a * flicker); } else { FragColor = texColor; } diff --git a/src/collision.c b/src/collision.c index 6b6396f..b7f70c7 100644 --- a/src/collision.c +++ b/src/collision.c @@ -6,7 +6,7 @@ /* By: qmennen +#+ */ /* +#+ */ /* Created: 2025/04/22 14:40:59 by qmennen #+# #+# */ -/* Updated: 2025/05/23 15:23:14 by whaffman ######## odam.nl */ +/* Updated: 2025/05/23 17:29:23 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -19,7 +19,7 @@ void collect(t_player *player) player->battery = 1.f; } -int collision_sprite(t_map *map, t_player *player, double xa, double ya) +int collision_sprite(t_map *map, t_player *player, double xa, double ya) { t_sprite *sprites; int i; diff --git a/src/game.c b/src/game.c index a7d0c91..9dc22e8 100644 --- a/src/game.c +++ b/src/game.c @@ -6,7 +6,7 @@ /* By: qmennen +#+ */ /* +#+ */ /* Created: 2025/04/15 15:46:08 by qmennen #+# #+# */ -/* Updated: 2025/05/23 15:58:12 by whaffman ######## odam.nl */ +/* Updated: 2025/05/23 17:20:34 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -38,6 +38,81 @@ void free_game(t_game **game) } } +int battery_color(float battery) +{ + if (battery > 0.5f) + return (0x00FF0066); + else if (battery > 0.25f) + return (0xFFFF0066); + else + return (0xFF000066); +} + +void draw_battery(mlx_image_t *img, float battery) +{ + int x; + int y; + + x = 1340; + while (x < 1350) + { + y = 265; + while (y < 285) + { + mlx_put_pixel(img, x, y, battery_color(battery)); + y++; + } + x++; + } + x = 1350; + while (x < 1450) + { + y = 250; + while (y < 300) + { + mlx_put_pixel(img, x, y, battery_color(battery)); + y++; + } + x++; + } +} + +void handle_battery(t_game *game) +{ + game->player->battery -= game->screen->mlx->delta_time / 50; + if (game->player->battery < 0) + game->player->battery = 0.001f; + draw_battery(game->screen->minimap, game->player->battery); +} + +void handle_record(t_game *game) +{ + static int flash = 0; + int x; + int y; + + flash = (game->framecount / 30) % 2; + y = -15; + while (y <= 15) + { + x = -15; + while (x <= 15) + { + if (x * x + y * y <= 225) + { + if (flash) + mlx_put_pixel( + game->screen->hud, 1530 + x, 212 + y, 0xFF000055); + else + mlx_put_pixel( + game->screen->hud, 1530 + x, 212 + y, 0x00000066); + } + x++; + } + y++; + } +} + void game_loop(void *param) { t_game *game; @@ -50,7 +125,7 @@ void game_loop(void *param) if (game->framecount % 20 == 0) { game->fps = (int)(fps / 20); - fprintf(stderr, "battery: %f FPS: %d\n",game->player->battery, fps / 20); + fprintf(stderr, "FPS: %d\n", fps / 20); fps = 0; } player_update(game, game->screen->mlx->delta_time); @@ -62,9 +137,8 @@ void game_loop(void *param) game->screen->img->instances[0].x = sin(game->framecount / 6.0) * 20; game->screen->img->instances[0].y = cos(game->framecount / 3.0) * 10; } - game->player->battery -= game->screen->mlx->delta_time / 10; - if (game->player->battery < 0) - game->player->battery = 0.001f; + handle_battery(game); + handle_record(game); } void game_free(t_game *game) diff --git a/src/parser/parse_config_line.c b/src/parser/parse_config_line.c index 68ad987..481f6df 100644 --- a/src/parser/parse_config_line.c +++ b/src/parser/parse_config_line.c @@ -6,13 +6,12 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/04/22 13:10:06 by whaffman #+# #+# */ -/* Updated: 2025/05/23 14:56:02 by whaffman ######## odam.nl */ +/* Updated: 2025/05/23 17:29:05 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ #include "cub3d.h" - mlx_texture_t *load_texture(const char *path) { mlx_texture_t *texture; @@ -127,7 +126,6 @@ t_token_handler handle_config_token(const char *token, t_map *map) return (NULL); } - int parse_config_line(char *line, t_map *map) { char *token; diff --git a/src/render/render_floor.c b/src/render/render_floor.c index af9943c..2ad94ca 100644 --- a/src/render/render_floor.c +++ b/src/render/render_floor.c @@ -6,7 +6,7 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/05/14 13:06:39 by whaffman #+# #+# */ -/* Updated: 2025/05/23 14:49:45 by whaffman ######## odam.nl */ +/* Updated: 2025/05/23 17:27:52 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -30,7 +30,7 @@ static void draw_floor_ceiling_pixel(t_game *game, int color; if (game->map->texture_floor == NULL) - color = game->map->floor_color << 8 | (int)(1.0 / row_dist * 255) ; + color = game->map->floor_color << 8 | (int)(1.0 / row_dist * 255); else color = get_texture_color(game->map->texture_floor, (t_render){row_dist, 0, 0}, tex); diff --git a/src/texture/texutre_load.c b/src/texture/texutre_load.c index baffec4..bdc860a 100644 --- a/src/texture/texutre_load.c +++ b/src/texture/texutre_load.c @@ -6,7 +6,7 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/05/06 15:45:58 by qmennen #+# #+# */ -/* Updated: 2025/05/23 14:11:39 by whaffman ######## odam.nl */ +/* Updated: 2025/05/23 17:29:13 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -37,12 +37,6 @@ void texture_delete(t_game *game) int texture_load(t_game *game) { - // game->map->textures[SIDE_NORTH] = mlx_load_png(game->map->north_texture); - // game->map->textures[SIDE_EAST] = mlx_load_png(game->map->east_texture); - // game->map->textures[SIDE_SOUTH] = mlx_load_png(game->map->south_texture); - // game->map->textures[SIDE_WEST] = mlx_load_png(game->map->west_texture); - // game->map->texture_floor = mlx_load_png("./assets/floor.png"); - // game->map->texture_ceiling = mlx_load_png("./assets/ceiling64x64.png"); if (!game->map->textures[SIDE_NORTH] || !game->map->textures[SIDE_EAST] || !game->map->textures[SIDE_SOUTH] || !game->map->textures[SIDE_WEST]) { diff --git a/src/util/initialize.c b/src/util/initialize.c index 07fc31e..3f8cff5 100644 --- a/src/util/initialize.c +++ b/src/util/initialize.c @@ -6,7 +6,7 @@ /* By: qmennen +#+ */ /* +#+ */ /* Created: 2025/04/22 17:08:26 by qmennen #+# #+# */ -/* Updated: 2025/05/23 15:05:50 by whaffman ######## odam.nl */ +/* Updated: 2025/05/23 17:28:36 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -23,9 +23,9 @@ static t_sprite make_sprite(char *path, double x, double y, int collectible) fprintf(stderr, "Error loading texture: %s\n", path); exit(EXIT_FAILURE); } - if (sprite.texture->width % 64 != 0) + if (sprite.texture->width % 64 != 0) { - fprintf(stderr, "Error: Texture %s width is not a multiple of 64\n", path); + fprintf(stderr, "Error: Texture %s width not a multiple of 64\n", path); exit(EXIT_FAILURE); } if (sprite.texture->height != 64)