diff --git a/assets/shaders/frag.glsl b/assets/shaders/frag.glsl index fce6ff3..57d9f32 100644 --- a/assets/shaders/frag.glsl +++ b/assets/shaders/frag.glsl @@ -39,6 +39,8 @@ float hash(vec2 p) { void main() { vec4 texColor; + vec4 noiseColor; + switch (TexIndex) { case 0: texColor = texture(Texture0, TexCoord); break; case 1: texColor = texture(Texture1, TexCoord); break; @@ -58,12 +60,6 @@ void main() case 15: texColor = texture(Texture15, TexCoord); break; default: texColor = vec4(1.0, 0.0, 0.0, 1.0); break; } - //generate a red flash - // if (u_hit_timer > 0.0) { - // float flash = sin(u_hit_timer * 10.0) * 0.5 + 0.5; - // FragColor = vec4(1.0, flash * 0.2, flash * 0.2, texColor.a); - // return; - // } if (TexIndex == 1) { vec2 uv = gl_FragCoord.xy / u_resolution.xy; uv.x *= u_resolution.x / u_resolution.y; @@ -92,8 +88,16 @@ void main() 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); - + noiseColor = vec4(noisyColor, texColor.a * flicker * dim); + if (u_hit_timer > 0.0) { + vec2 uv = gl_FragCoord.xy / u_resolution.xy; + uv *= 1.0 - uv.yx; + float vig = uv.x*uv.y * 15.0; + vig = pow(vig, 0.25); + float inv_hit = 1.0 - u_hit_timer; + noiseColor *= vec4(vig) * vec4(1.0, inv_hit, inv_hit, 1.0); + } + FragColor = noiseColor; } else { FragColor = texColor; } diff --git a/inc/cub3d.h b/inc/cub3d.h index 8cdb116..f871021 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -6,7 +6,7 @@ /* By: qmennen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/15 12:22:29 by qmennen #+# #+# */ -/* Updated: 2025/05/28 17:30:51 by qmennen ### ########.fr */ +/* Updated: 2025/06/03 15:50:37 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -48,7 +48,6 @@ # include "types.h" # include "errors.h" # include "vec_math.h" -# include "map.h" # include "game.h" # include "screen.h" # include "keyboard.h" diff --git a/inc/map.h b/inc/map.h deleted file mode 100644 index c829674..0000000 --- a/inc/map.h +++ /dev/null @@ -1,31 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* map.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: qmennen +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2025/04/17 19:19:19 by qmennen #+# #+# */ -/* Updated: 2025/05/28 17:07:28 by qmennen ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef MAP_H -# define MAP_H - -# include "cub3d.h" - -int map_create(t_game **game, const char *mapfile); -void map_free(t_map *map); -void print_map(t_map *map); -t_tile get_tile(t_map *map, int x, int y); -int enclosed_map(t_map *map); -void grid_free(t_tile **grid, int height); -t_tile **copy_map(t_tile **grid, int width, int height); -int parse_args(const char *mapfile, t_game *game); -t_tile **create_grid(int width, int height); -int find_player_or_empty(t_map *map, int *x, int *y); -int floodfill(t_map *map, int x, int y); -t_sprite make_sprite(t_sprite_lib *def, double x, double y); - -#endif diff --git a/inc/parser.h b/inc/parser.h index 23c5935..fb03149 100644 --- a/inc/parser.h +++ b/inc/parser.h @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ -/* :::::::: */ -/* parser.h :+: :+: */ -/* +:+ */ -/* By: whaffman +#+ */ -/* +#+ */ -/* Created: 2025/04/19 14:41:55 by whaffman #+# #+# */ -/* Updated: 2025/06/03 14:43:25 by whaffman ######## odam.nl */ +/* ::: :::::::: */ +/* parser.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/04/19 14:41:55 by whaffman #+# #+# */ +/* Updated: 2025/06/03 15:49:59 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,5 +36,17 @@ int handle_fc_color(char *token, t_map *map); int handle_fc_texture(char *token, t_map *map); int handle_sprite(char *token, t_map *map); mlx_texture_t *load_texture(const char *path); +int map_create(t_game **game, const char *mapfile); +void map_free(t_map *map); +void print_map(t_map *map); +t_tile get_tile(t_map *map, int x, int y); +int enclosed_map(t_map *map); +void grid_free(t_tile **grid, int height); +t_tile **copy_map(t_tile **grid, int width, int height); +int parse_args(const char *mapfile, t_game *game); +t_tile **create_grid(int width, int height); +int find_player_or_empty(t_map *map, int *x, int *y); +int floodfill(t_map *map, int x, int y); +t_sprite make_sprite(t_sprite_lib *def, double x, double y); #endif \ No newline at end of file diff --git a/src/collision.c b/src/collision.c index 25ea450..4dfd304 100644 --- a/src/collision.c +++ b/src/collision.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ -/* :::::::: */ -/* collision.c :+: :+: */ -/* +:+ */ -/* By: qmennen +#+ */ -/* +#+ */ -/* Created: 2025/04/22 14:40:59 by qmennen #+# #+# */ -/* Updated: 2025/06/03 13:42:51 by whaffman ######## odam.nl */ +/* ::: :::::::: */ +/* collision.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/04/22 14:40:59 by qmennen #+# #+# */ +/* Updated: 2025/06/03 15:18:54 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,7 +34,10 @@ int collision_sprite(t_map *map, t_player *player, double xa, double ya) && fabs(player->pos.y + ya - sprites[i].pos.y) < 0.5)) { if (sprites[i].type == SPRITE_TYPE_ENEMY) + { player->battery -= 0.0001; + player->hit_timer = .65f; + } else { sprites[i].type = SPRITE_TYPE_COLLECTED; diff --git a/src/moves.c b/src/moves.c index 890eec8..e62c000 100644 --- a/src/moves.c +++ b/src/moves.c @@ -6,7 +6,7 @@ /* By: qmennen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/14 20:08:27 by whaffman #+# #+# */ -/* Updated: 2025/06/03 14:54:45 by qmennen ### ########.fr */ +/* Updated: 2025/06/03 15:10:49 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -97,7 +97,5 @@ void player_update(t_game *game, double delta_time) game->player->battery -= 0.1f; } if (game->player->hit_timer > 0) - { - game->player->hit_timer -= 1; - } + game->player->hit_timer -= .1f; } diff --git a/src/map/copy_map.c b/src/parser/copy_map.c similarity index 100% rename from src/map/copy_map.c rename to src/parser/copy_map.c diff --git a/src/map/create_grid.c b/src/parser/create_grid.c similarity index 100% rename from src/map/create_grid.c rename to src/parser/create_grid.c diff --git a/src/map/enclosed_map.c b/src/parser/enclosed_map.c similarity index 100% rename from src/map/enclosed_map.c rename to src/parser/enclosed_map.c diff --git a/src/map/find_player_or_empty.c b/src/parser/find_player_or_empty.c similarity index 100% rename from src/map/find_player_or_empty.c rename to src/parser/find_player_or_empty.c diff --git a/src/map/floodfill.c b/src/parser/floodfill.c similarity index 100% rename from src/map/floodfill.c rename to src/parser/floodfill.c diff --git a/src/map/get_tile.c b/src/parser/get_tile.c similarity index 100% rename from src/map/get_tile.c rename to src/parser/get_tile.c diff --git a/src/map/grid_free.c b/src/parser/grid_free.c similarity index 100% rename from src/map/grid_free.c rename to src/parser/grid_free.c diff --git a/src/map/map_create.c b/src/parser/map_create.c similarity index 100% rename from src/map/map_create.c rename to src/parser/map_create.c diff --git a/src/map/map_entries_present.c b/src/parser/map_entries_present.c similarity index 100% rename from src/map/map_entries_present.c rename to src/parser/map_entries_present.c diff --git a/src/map/map_free.c b/src/parser/map_free.c similarity index 100% rename from src/map/map_free.c rename to src/parser/map_free.c diff --git a/src/map/parse_args.c b/src/parser/parse_args.c similarity index 100% rename from src/map/parse_args.c rename to src/parser/parse_args.c diff --git a/src/map/print_map.c b/src/parser/print_map.c similarity index 100% rename from src/map/print_map.c rename to src/parser/print_map.c diff --git a/src/player.c b/src/player.c index ee421c1..5c26e52 100644 --- a/src/player.c +++ b/src/player.c @@ -6,7 +6,7 @@ /* By: qmennen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/15 18:53:19 by qmennen #+# #+# */ -/* Updated: 2025/06/03 14:55:17 by qmennen ### ########.fr */ +/* Updated: 2025/06/03 15:18:22 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,7 +24,7 @@ int player_create(t_game **game) player->pos.y = -1; player->speed = 3.f; player->battery = .5f; - player->hit_timer = 10.0f; + player->hit_timer = 0.f; (*game)->player = player; return (SUCCESS); } diff --git a/src/render/render_sprite.c b/src/render/render_sprite.c index dbef997..8e84db0 100644 --- a/src/render/render_sprite.c +++ b/src/render/render_sprite.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ -/* :::::::: */ -/* render_sprite.c :+: :+: */ -/* +:+ */ -/* By: whaffman +#+ */ -/* +#+ */ -/* Created: 2025/05/08 12:23:17 by qmennen #+# #+# */ -/* Updated: 2025/06/03 14:47:08 by whaffman ######## odam.nl */ +/* ::: :::::::: */ +/* render_sprite.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/05/08 12:23:17 by qmennen #+# #+# */ +/* Updated: 2025/06/03 15:00:43 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/screen.c b/src/screen.c index 48d21a8..ec053aa 100644 --- a/src/screen.c +++ b/src/screen.c @@ -6,7 +6,7 @@ /* By: qmennen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/15 15:30:27 by qmennen #+# #+# */ -/* Updated: 2025/05/28 14:24:41 by qmennen ### ########.fr */ +/* Updated: 2025/06/03 15:47:36 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,7 +23,7 @@ int screen_create(t_game **game) ft_memset(screen, 0, sizeof(t_screen)); screen->width = WIDTH; screen->height = HEIGHT; - mlx_set_setting(MLX_STRETCH_IMAGE, 1); + mlx_set_setting(MLX_FULLSCREEN, 1); mlx = mlx_init(WIDTH, HEIGHT, TITLE, true); if (!mlx) return (FAILURE);