Merge remote-tracking branch 'origin/quinten' into willem
This commit is contained in:
commit
9c72e54ac3
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@ -11,7 +11,9 @@
|
|||||||
"render.h": "c",
|
"render.h": "c",
|
||||||
"math.h": "c",
|
"math.h": "c",
|
||||||
"mlx42_int.h": "c",
|
"mlx42_int.h": "c",
|
||||||
"glad.h": "c"
|
"glad.h": "c",
|
||||||
|
"game_menu.h": "c",
|
||||||
|
"game_manager.h": "c"
|
||||||
},
|
},
|
||||||
"cmake.ignoreCMakeListsMissing": true
|
"cmake.ignoreCMakeListsMissing": true
|
||||||
}
|
}
|
||||||
12
Makefile
12
Makefile
@ -1,12 +1,12 @@
|
|||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
# #
|
# #
|
||||||
# :::::::: #
|
# ::: :::::::: #
|
||||||
# Makefile :+: :+: #
|
# Makefile :+: :+: :+: #
|
||||||
# +:+ #
|
# +:+ +:+ +:+ #
|
||||||
# By: qmennen <qmennen@student.codam.nl> +#+ #
|
# By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ #
|
||||||
# +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2024/10/15 11:48:46 by whaffman #+# #+# #
|
# Created: 2024/10/15 11:48:46 by whaffman #+# #+# #
|
||||||
# Updated: 2025/05/23 11:22:47 by whaffman ######## odam.nl #
|
# Updated: 2025/05/27 17:00:58 by qmennen ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|||||||
10
README.md
10
README.md
@ -1,14 +1,16 @@
|
|||||||
# Cub3d (by Quinten & Willem)
|
# Cub3d (by Quinten & Willem)
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
- [ ] **Config Parsing:** support inclusion of sprites in the format (-{type: c, s} {identifier} {path})
|
- [x] **Config Parsing:** support inclusion of sprites in the format (-{type: c, s} {identifier} {path})
|
||||||
- [ ] **Map Parsing:** Keep in mind the possible addition of sprites / collectibles
|
- [x] **Map Parsing:** Keep in mind the possible addition of sprites / collectibles
|
||||||
- [ ] **Gameplay:** Allow sprites to be collected (stopping them from being rendered)
|
- [x] **Gameplay:** Allow sprites to be collected (stopping them from being rendered)
|
||||||
- [ ] **Rendering:** Allow for either floor/ceiling textures *or* colors.
|
- [ ] **Rendering:** Allow for either floor/ceiling textures *or* colors.
|
||||||
- [ ] **Gameplay:** Implement doors/exits
|
- [ ] **Gameplay:** Implement doors/exits
|
||||||
- [ ] **UX:** Allow user to capture moues and use it for looking. Also allow capture release.
|
- [ ] **UX:** Allow user to capture moues and use it for looking. Also allow capture release.
|
||||||
- [ ] **UX:** Title / end screen
|
- [x] **UX:** Title / end screen
|
||||||
- [ ] **Map Design:** Design a map for captivating gameplay.
|
- [ ] **Map Design:** Design a map for captivating gameplay.
|
||||||
|
- [ ] **Map Parsing:** When unidentified character appears, seg fault does too
|
||||||
|
- [ ] **Map Parsing:** Able to run the game with no player
|
||||||
|
|
||||||
## Gameplay
|
## Gameplay
|
||||||
- Your on surveillance and you need
|
- Your on surveillance and you need
|
||||||
|
|||||||
BIN
assets/menu.xcf
Normal file
BIN
assets/menu.xcf
Normal file
Binary file not shown.
BIN
assets/menu_background.png
Normal file
BIN
assets/menu_background.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.5 MiB |
@ -8,6 +8,18 @@ uniform sampler2D Texture0;
|
|||||||
uniform sampler2D Texture1;
|
uniform sampler2D Texture1;
|
||||||
uniform sampler2D Texture2;
|
uniform sampler2D Texture2;
|
||||||
uniform sampler2D Texture3;
|
uniform sampler2D Texture3;
|
||||||
|
uniform sampler2D Texture4;
|
||||||
|
uniform sampler2D Texture5;
|
||||||
|
uniform sampler2D Texture6;
|
||||||
|
uniform sampler2D Texture7;
|
||||||
|
uniform sampler2D Texture8;
|
||||||
|
uniform sampler2D Texture9;
|
||||||
|
uniform sampler2D Texture10;
|
||||||
|
uniform sampler2D Texture11;
|
||||||
|
uniform sampler2D Texture12;
|
||||||
|
uniform sampler2D Texture13;
|
||||||
|
uniform sampler2D Texture14;
|
||||||
|
uniform sampler2D Texture15;
|
||||||
|
|
||||||
uniform float u_time;
|
uniform float u_time;
|
||||||
uniform float u_battery;
|
uniform float u_battery;
|
||||||
@ -31,7 +43,19 @@ void main()
|
|||||||
case 1: texColor = texture(Texture1, TexCoord); break;
|
case 1: texColor = texture(Texture1, TexCoord); break;
|
||||||
case 2: texColor = texture(Texture2, TexCoord); break;
|
case 2: texColor = texture(Texture2, TexCoord); break;
|
||||||
case 3: texColor = texture(Texture3, TexCoord); break;
|
case 3: texColor = texture(Texture3, TexCoord); break;
|
||||||
default: texColor = vec4(0.0, 0.0, 0.0, 0.0); break;
|
case 4: texColor = texture(Texture4, TexCoord); break;
|
||||||
|
case 5: texColor = texture(Texture5, TexCoord); break;
|
||||||
|
case 6: texColor = texture(Texture6, TexCoord); break;
|
||||||
|
case 7: texColor = texture(Texture7, TexCoord); break;
|
||||||
|
case 8: texColor = texture(Texture8, TexCoord); break;
|
||||||
|
case 9: texColor = texture(Texture9, TexCoord); break;
|
||||||
|
case 10: texColor = texture(Texture10, TexCoord); break;
|
||||||
|
case 11: texColor = texture(Texture11, TexCoord); break;
|
||||||
|
case 12: texColor = texture(Texture12, TexCoord); break;
|
||||||
|
case 13: texColor = texture(Texture13, TexCoord); break;
|
||||||
|
case 14: texColor = texture(Texture14, TexCoord); break;
|
||||||
|
case 15: texColor = texture(Texture15, TexCoord); break;
|
||||||
|
default: texColor = vec4(1.0, 0.0, 0.0, 1.0); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TexIndex == 1) {
|
if (TexIndex == 1) {
|
||||||
|
|||||||
89
big.cub
Normal file
89
big.cub
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
|
||||||
|
|
||||||
|
NO ./assets/tiles256.png
|
||||||
|
|
||||||
|
WE ./assets/bricks2.png
|
||||||
|
|
||||||
|
SO ./assets/stonewall256.png
|
||||||
|
EA ./assets/bricksx64.png
|
||||||
|
|
||||||
|
F 90,30,30
|
||||||
|
|
||||||
|
|
||||||
|
C 100,100,200
|
||||||
|
|
||||||
|
FT ./assets/tiles3.png
|
||||||
|
CT ./assets/ceiling64x64.png
|
||||||
|
|
||||||
|
-s a ./assets/lamp.png
|
||||||
|
-c b ./assets/accu.png
|
||||||
|
-s p ./assets/plant.png
|
||||||
|
-s m ./assets/broken_mirror.png
|
||||||
|
-s t ./assets/test.png
|
||||||
|
|
||||||
|
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
10000000000N0000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||||
|
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
|
||||||
20
inc/cub3d.h
20
inc/cub3d.h
@ -1,12 +1,12 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* :::::::: */
|
/* ::: :::::::: */
|
||||||
/* cub3d.h :+: :+: */
|
/* cub3d.h :+: :+: :+: */
|
||||||
/* +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/15 12:22:29 by qmennen #+# #+# */
|
/* Created: 2025/04/15 12:22:29 by qmennen #+# #+# */
|
||||||
/* Updated: 2025/05/23 11:34:52 by whaffman ######## odam.nl */
|
/* Updated: 2025/05/27 18:14:06 by qmennen ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -34,9 +34,13 @@
|
|||||||
# define CYAN "\033[0;36m"
|
# define CYAN "\033[0;36m"
|
||||||
# define WHITE "\033[0;37m"
|
# define WHITE "\033[0;37m"
|
||||||
|
|
||||||
# define NUM_KEYS 256
|
# define NUM_KEYS 300
|
||||||
# define TILE_SIZE 8
|
# define TILE_SIZE 8
|
||||||
# define MINIMAP_SIZE 300
|
# define MINIMAP_SIZE 300
|
||||||
|
# define MAX_MENU_OPTIONS 3
|
||||||
|
# define MENU_OPTION_START 0
|
||||||
|
# define MENU_OPTION_SCOREBOARD 1
|
||||||
|
# define MENU_OPTION_EXIT 2
|
||||||
|
|
||||||
# include "MLX42.h"
|
# include "MLX42.h"
|
||||||
# include "allowed.h"
|
# include "allowed.h"
|
||||||
@ -54,6 +58,8 @@
|
|||||||
# include "collision.h"
|
# include "collision.h"
|
||||||
# include "parser.h"
|
# include "parser.h"
|
||||||
# include "texture.h"
|
# include "texture.h"
|
||||||
|
# include "game_manager.h"
|
||||||
|
# include "game_menu.h"
|
||||||
|
|
||||||
int initialize_cub3d(t_game **game, const char *mapfile);
|
int initialize_cub3d(t_game **game, const char *mapfile);
|
||||||
int shader_init(t_game **game);
|
int shader_init(t_game **game);
|
||||||
|
|||||||
13
inc/game.h
13
inc/game.h
@ -1,12 +1,12 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* :::::::: */
|
/* ::: :::::::: */
|
||||||
/* game.h :+: :+: */
|
/* game.h :+: :+: :+: */
|
||||||
/* +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/15 15:46:16 by qmennen #+# #+# */
|
/* Created: 2025/04/15 15:46:16 by qmennen #+# #+# */
|
||||||
/* Updated: 2025/05/25 21:01:17 by whaffman ######## odam.nl */
|
/* Updated: 2025/05/27 13:58:21 by qmennen ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -21,5 +21,6 @@ void game_free(t_game *game);
|
|||||||
void game_terminate(t_game *game);
|
void game_terminate(t_game *game);
|
||||||
void free_game(t_game **game);
|
void free_game(t_game **game);
|
||||||
void print_scores(t_game *game);
|
void print_scores(t_game *game);
|
||||||
|
void game_run(t_game *game);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
25
inc/game_manager.h
Normal file
25
inc/game_manager.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* game_manager.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/05/27 13:40:20 by qmennen #+# #+# */
|
||||||
|
/* Updated: 2025/05/27 18:34:07 by qmennen ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef GAME_MANAGER_H
|
||||||
|
# define GAME_MANAGER_H
|
||||||
|
|
||||||
|
# include "cub3d.h"
|
||||||
|
|
||||||
|
t_game_manager *game_manager_create(t_game *game);
|
||||||
|
void game_manager_display(t_game_manager *manager);
|
||||||
|
void game_manager_update(void *param);
|
||||||
|
void game_manager_select(t_game_manager *manager);
|
||||||
|
void game_manager_handle_input(t_game_manager *manager);
|
||||||
|
void game_manager_destroy(t_game_manager *manager);
|
||||||
|
|
||||||
|
#endif
|
||||||
23
inc/game_menu.h
Normal file
23
inc/game_menu.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* game_menu.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/05/27 15:07:48 by qmennen #+# #+# */
|
||||||
|
/* Updated: 2025/05/27 18:41:31 by qmennen ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef GAME_MENU_H
|
||||||
|
# define GAME_MENU_H
|
||||||
|
|
||||||
|
# include "cub3d.h"
|
||||||
|
|
||||||
|
void menu_display(t_menu *menu, t_screen *screen);
|
||||||
|
t_menu *menu_create(t_game_manager *manager, char *background_path, const char *options[]);
|
||||||
|
void menu_free(t_menu *menu, t_screen *screen);
|
||||||
|
void menu_toggle(t_menu *menu, t_screen *screen);
|
||||||
|
|
||||||
|
#endif
|
||||||
40
inc/types.h
40
inc/types.h
@ -1,12 +1,12 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* :::::::: */
|
/* ::: :::::::: */
|
||||||
/* types.h :+: :+: */
|
/* types.h :+: :+: :+: */
|
||||||
/* +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/15 15:52:44 by qmennen #+# #+# */
|
/* Created: 2025/04/15 15:52:44 by qmennen #+# #+# */
|
||||||
/* Updated: 2025/05/25 13:37:39 by whaffman ######## odam.nl */
|
/* Updated: 2025/05/27 18:42:09 by qmennen ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -58,7 +58,6 @@ typedef struct s_player
|
|||||||
float battery;
|
float battery;
|
||||||
} t_player;
|
} t_player;
|
||||||
|
|
||||||
|
|
||||||
typedef struct s_sprite
|
typedef struct s_sprite
|
||||||
{
|
{
|
||||||
int n_frames;
|
int n_frames;
|
||||||
@ -120,6 +119,12 @@ typedef enum e_side
|
|||||||
SIDE_EAST,
|
SIDE_EAST,
|
||||||
} t_side;
|
} t_side;
|
||||||
|
|
||||||
|
typedef enum e_game_state
|
||||||
|
{
|
||||||
|
GAME_STATE_MENU,
|
||||||
|
GAME_STATE_PLAYING,
|
||||||
|
} t_game_state;
|
||||||
|
|
||||||
typedef struct s_render
|
typedef struct s_render
|
||||||
{
|
{
|
||||||
double perp_dist;
|
double perp_dist;
|
||||||
@ -142,6 +147,27 @@ typedef struct s_game
|
|||||||
t_keyboard *keyboard;
|
t_keyboard *keyboard;
|
||||||
int framecount;
|
int framecount;
|
||||||
int fps;
|
int fps;
|
||||||
|
t_game_state state;
|
||||||
} t_game;
|
} t_game;
|
||||||
|
|
||||||
|
typedef struct s_menu
|
||||||
|
{
|
||||||
|
int selected_option;
|
||||||
|
int num_options;
|
||||||
|
int hidden;
|
||||||
|
char *options[MAX_MENU_OPTIONS];
|
||||||
|
mlx_image_t *option_images[MAX_MENU_OPTIONS];
|
||||||
|
mlx_image_t *selector;
|
||||||
|
mlx_image_t *background_image;
|
||||||
|
|
||||||
|
} t_menu;
|
||||||
|
|
||||||
|
typedef struct s_game_manager
|
||||||
|
{
|
||||||
|
t_game *game;
|
||||||
|
t_menu *menu;
|
||||||
|
t_menu *end_screen;
|
||||||
|
t_menu **active_menu;
|
||||||
|
} t_game_manager;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
13
src/game.c
13
src/game.c
@ -6,7 +6,7 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/04/15 15:46:08 by qmennen #+# #+# */
|
/* Created: 2025/04/15 15:46:08 by qmennen #+# #+# */
|
||||||
/* Updated: 2025/05/28 11:42:24 by whaffman ######## odam.nl */
|
/* Updated: 2025/05/28 13:54:58 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -20,6 +20,7 @@ int game_create(t_game **game)
|
|||||||
if (!game)
|
if (!game)
|
||||||
return (FAILURE);
|
return (FAILURE);
|
||||||
memset(*game, 0, sizeof(t_game));
|
memset(*game, 0, sizeof(t_game));
|
||||||
|
(*game)->state = GAME_STATE_MENU;
|
||||||
(*game)->fps = 20;
|
(*game)->fps = 20;
|
||||||
return (SUCCESS);
|
return (SUCCESS);
|
||||||
}
|
}
|
||||||
@ -129,12 +130,10 @@ void handle_record(t_game *game)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void game_loop(void *param)
|
void game_run(t_game *game)
|
||||||
{
|
{
|
||||||
t_game *game;
|
|
||||||
static int fps = 0;
|
static int fps = 0;
|
||||||
|
|
||||||
game = (t_game *)param;
|
|
||||||
game->framecount++;
|
game->framecount++;
|
||||||
fps += (int)(1.f / game->screen->mlx->delta_time);
|
fps += (int)(1.f / game->screen->mlx->delta_time);
|
||||||
set_uniforms(game);
|
set_uniforms(game);
|
||||||
@ -147,7 +146,6 @@ void game_loop(void *param)
|
|||||||
player_update(game, game->screen->mlx->delta_time);
|
player_update(game, game->screen->mlx->delta_time);
|
||||||
cast_rays(game);
|
cast_rays(game);
|
||||||
render_map(game);
|
render_map(game);
|
||||||
keyboard_update(game);
|
|
||||||
if (game->player->is_moving)
|
if (game->player->is_moving)
|
||||||
{
|
{
|
||||||
game->screen->img->instances[0].x = sin(game->framecount / 6.0) * 20;
|
game->screen->img->instances[0].x = sin(game->framecount / 6.0) * 20;
|
||||||
@ -159,6 +157,11 @@ void game_loop(void *param)
|
|||||||
|
|
||||||
void game_free(t_game *game)
|
void game_free(t_game *game)
|
||||||
{
|
{
|
||||||
|
if (game->screen->hud)
|
||||||
|
{
|
||||||
|
mlx_delete_image(game->screen->mlx, game->screen->hud);
|
||||||
|
game->screen->hud = NULL;
|
||||||
|
}
|
||||||
if (game->screen)
|
if (game->screen)
|
||||||
{
|
{
|
||||||
mlx_delete_image(game->screen->mlx, game->screen->img);
|
mlx_delete_image(game->screen->mlx, game->screen->img);
|
||||||
|
|||||||
14
src/main.c
14
src/main.c
@ -6,15 +6,15 @@
|
|||||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/04/15 16:01:29 by qmennen #+# #+# */
|
/* Created: 2025/04/15 16:01:29 by qmennen #+# #+# */
|
||||||
/* Updated: 2025/05/28 11:40:58 by whaffman ######## odam.nl */
|
/* Updated: 2025/05/28 13:56:56 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "cub3d.h"
|
#include "cub3d.h"
|
||||||
#include "glad.h"
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
t_game_manager *manager;
|
||||||
t_game *game;
|
t_game *game;
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
@ -28,7 +28,15 @@ int main(int argc, char **argv)
|
|||||||
game_free(game);
|
game_free(game);
|
||||||
return (EXIT_FAILURE);
|
return (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
manager = game_manager_create(game);
|
||||||
|
manager->menu = menu_create(manager, "./assets/menu_background.png",
|
||||||
|
(const char *[]){"Start Game", "Scoreboard", "Exit", NULL});
|
||||||
|
manager->end_screen = menu_create(manager, "./assets/menu_background.png",
|
||||||
|
(const char *[]){"Game Over", "Exit", NULL});
|
||||||
|
manager->active_menu = &manager->end_screen;
|
||||||
|
mlx_key_hook(game->screen->mlx, keyhandle, game);
|
||||||
|
mlx_loop_hook(game->screen->mlx, game_manager_update, manager);
|
||||||
mlx_loop(game->screen->mlx);
|
mlx_loop(game->screen->mlx);
|
||||||
game_terminate(game);
|
game_manager_destroy(manager);
|
||||||
return (EXIT_SUCCESS);
|
return (EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|||||||
68
src/manager/game_manager.c
Normal file
68
src/manager/game_manager.c
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* game_manager.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/05/27 13:48:18 by qmennen #+# #+# */
|
||||||
|
/* Updated: 2025/05/27 18:39:36 by qmennen ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "game_manager.h"
|
||||||
|
|
||||||
|
t_game_manager *game_manager_create(t_game *game)
|
||||||
|
{
|
||||||
|
t_game_manager *manager;
|
||||||
|
manager = malloc(sizeof(t_game_manager));
|
||||||
|
if (!manager)
|
||||||
|
return (NULL);
|
||||||
|
manager->game = game;
|
||||||
|
manager->menu = NULL;
|
||||||
|
return (manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
void game_manager_display(t_game_manager *manager)
|
||||||
|
{
|
||||||
|
t_game *game;
|
||||||
|
|
||||||
|
if (!manager || !manager->game)
|
||||||
|
return;
|
||||||
|
game = manager->game;
|
||||||
|
if (game->state == GAME_STATE_MENU)
|
||||||
|
{
|
||||||
|
menu_display(*(manager->active_menu), game->screen);
|
||||||
|
}
|
||||||
|
else if (game->state == GAME_STATE_PLAYING)
|
||||||
|
{
|
||||||
|
game_run(game);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void game_manager_update(void *param)
|
||||||
|
{
|
||||||
|
t_game_manager *manager;
|
||||||
|
|
||||||
|
manager = (t_game_manager *)param;
|
||||||
|
game_manager_handle_input(manager);
|
||||||
|
game_manager_display(manager);
|
||||||
|
keyboard_update(manager->game);
|
||||||
|
}
|
||||||
|
|
||||||
|
void game_manager_destroy(t_game_manager *manager)
|
||||||
|
{
|
||||||
|
if (!manager)
|
||||||
|
return;
|
||||||
|
if (manager->menu)
|
||||||
|
menu_free(manager->menu, manager->game->screen);
|
||||||
|
if (manager->end_screen)
|
||||||
|
menu_free(manager->end_screen, manager->game->screen);
|
||||||
|
print_scores(manager->game);
|
||||||
|
if (manager->game)
|
||||||
|
{
|
||||||
|
game_free(manager->game);
|
||||||
|
}
|
||||||
|
free(manager);
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
68
src/manager/game_manager_utils.c
Normal file
68
src/manager/game_manager_utils.c
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* game_manager_utils.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/05/27 15:22:15 by qmennen #+# #+# */
|
||||||
|
/* Updated: 2025/05/27 18:40:45 by qmennen ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "game_manager.h"
|
||||||
|
|
||||||
|
static void game_start(t_game *game)
|
||||||
|
{
|
||||||
|
t_screen *screen;
|
||||||
|
|
||||||
|
screen = game->screen;
|
||||||
|
if (mlx_image_to_window(screen->mlx, screen->minimap, 175, 575) < 0)
|
||||||
|
{
|
||||||
|
printf(RED "Failed to display buffer image\n" RESET);
|
||||||
|
game_terminate(game);
|
||||||
|
}
|
||||||
|
if (mlx_image_to_window(screen->mlx, screen->hud, 0, 0) < 0)
|
||||||
|
{
|
||||||
|
printf(RED "Failed to display buffer image\n" RESET);
|
||||||
|
game_terminate(game);
|
||||||
|
}
|
||||||
|
game->state = GAME_STATE_PLAYING;
|
||||||
|
}
|
||||||
|
|
||||||
|
void game_manager_select(t_game_manager *manager)
|
||||||
|
{
|
||||||
|
int selected_option;
|
||||||
|
int menu_screen;
|
||||||
|
|
||||||
|
menu_screen = manager->game->state == GAME_STATE_MENU;
|
||||||
|
selected_option = (*manager->active_menu)->selected_option;
|
||||||
|
if (menu_screen && selected_option == 0)
|
||||||
|
{
|
||||||
|
menu_toggle(*(manager->active_menu), manager->game->screen);
|
||||||
|
game_start(manager->game);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void game_manager_handle_input(t_game_manager *manager)
|
||||||
|
{
|
||||||
|
if (get_key_down(manager->game, MLX_KEY_ENTER))
|
||||||
|
{
|
||||||
|
game_manager_select(manager);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
if (get_key_up(manager->game, MLX_KEY_DOWN))
|
||||||
|
{
|
||||||
|
(*manager->active_menu)->selected_option++;
|
||||||
|
if ((*manager->active_menu)->selected_option >= (*manager->active_menu)->num_options)
|
||||||
|
(*manager->active_menu)->selected_option = 0;
|
||||||
|
}
|
||||||
|
if (get_key_up(manager->game, MLX_KEY_UP))
|
||||||
|
{
|
||||||
|
(*manager->active_menu)->selected_option--;
|
||||||
|
if (manager->menu->selected_option < 0)
|
||||||
|
manager->menu->selected_option = manager->menu->num_options - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
135
src/menu/menu.c
Normal file
135
src/menu/menu.c
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* menu.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/05/27 14:31:53 by qmennen #+# #+# */
|
||||||
|
/* Updated: 2025/05/27 18:37:03 by qmennen ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
# include "game_menu.h"
|
||||||
|
|
||||||
|
static mlx_image_t *menu_load_background(mlx_t *mlx, char *background_path)
|
||||||
|
{
|
||||||
|
mlx_texture_t *background_texture;
|
||||||
|
mlx_image_t *background_image;
|
||||||
|
|
||||||
|
if (!background_path)
|
||||||
|
return (NULL);
|
||||||
|
background_texture = mlx_load_png(background_path);
|
||||||
|
if (!background_texture)
|
||||||
|
{
|
||||||
|
printf("Failed to load background texture from %s\n", background_path);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
background_image = mlx_texture_to_image(mlx, background_texture);
|
||||||
|
return (mlx_delete_texture(background_texture), background_image);
|
||||||
|
}
|
||||||
|
|
||||||
|
t_menu *menu_create(t_game_manager *manager, char *background_path, const char *options[])
|
||||||
|
{
|
||||||
|
t_menu *menu;
|
||||||
|
int i;
|
||||||
|
menu = malloc(sizeof(t_menu));
|
||||||
|
if (!menu)
|
||||||
|
return (NULL);
|
||||||
|
menu->background_image = menu_load_background(manager->game->screen->mlx, background_path);
|
||||||
|
if (mlx_image_to_window(manager->game->screen->mlx, menu->background_image, 0, 0) < 0)
|
||||||
|
{
|
||||||
|
printf("Failed to display background image\n");
|
||||||
|
mlx_delete_image(manager->game->screen->mlx, menu->background_image);
|
||||||
|
return (free(menu), NULL);
|
||||||
|
}
|
||||||
|
menu->background_image->instances[0].enabled = false;
|
||||||
|
ft_memset(menu->option_images, 0, sizeof(menu->option_images));
|
||||||
|
menu->selector = 0;
|
||||||
|
menu->selected_option = 0;
|
||||||
|
menu->num_options = 0;
|
||||||
|
menu->hidden = 1;
|
||||||
|
i = -1;
|
||||||
|
while (options[++i] != NULL)
|
||||||
|
{
|
||||||
|
menu->options[i] = (char *)options[i];
|
||||||
|
menu->num_options++;
|
||||||
|
}
|
||||||
|
return (menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
void menu_display(t_menu *menu, t_screen *screen)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (menu->hidden)
|
||||||
|
{
|
||||||
|
menu_toggle(menu, screen);
|
||||||
|
}
|
||||||
|
if (menu->selector == 0)
|
||||||
|
{
|
||||||
|
menu->selector = mlx_put_string(screen->mlx, ">", screen->width / 2 - 100, 0);
|
||||||
|
}
|
||||||
|
i = 0;
|
||||||
|
while (i < menu->num_options)
|
||||||
|
{
|
||||||
|
if (i == menu->selected_option && menu->selector)
|
||||||
|
{
|
||||||
|
menu->selector->instances[0].y = (screen->height - 100) / 2 + i * 50;
|
||||||
|
}
|
||||||
|
if (menu->option_images[i] == 0)
|
||||||
|
{
|
||||||
|
menu->option_images[i] = mlx_put_string(screen->mlx, menu->options[i],
|
||||||
|
(screen->width - ft_strlen(menu->options[i]) * 10) / 2,
|
||||||
|
(screen->height - 100) / 2 + i * 50);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void menu_toggle(t_menu *menu, t_screen *screen)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (!menu)
|
||||||
|
return;
|
||||||
|
menu->hidden = !menu->hidden;
|
||||||
|
if (menu->selector)
|
||||||
|
{
|
||||||
|
menu->selector->instances[0].enabled = !menu->hidden;
|
||||||
|
}
|
||||||
|
if (menu->background_image)
|
||||||
|
{
|
||||||
|
menu->background_image->instances[0].enabled = !menu->hidden;
|
||||||
|
}
|
||||||
|
i = -1;
|
||||||
|
while (i++ < menu->num_options)
|
||||||
|
{
|
||||||
|
if (menu->option_images[i])
|
||||||
|
{
|
||||||
|
menu->option_images[i]->instances[0].enabled = !menu->hidden;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void menu_free(t_menu *menu, t_screen *screen)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (!menu)
|
||||||
|
return;
|
||||||
|
while (i < menu->num_options)
|
||||||
|
{
|
||||||
|
if (menu->option_images[i])
|
||||||
|
{
|
||||||
|
mlx_delete_image(screen->mlx, menu->option_images[i]);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (menu->selector)
|
||||||
|
mlx_delete_image(screen->mlx, menu->selector);
|
||||||
|
if (menu->background_image)
|
||||||
|
mlx_delete_image(screen->mlx, menu->background_image);
|
||||||
|
free(menu);
|
||||||
|
}
|
||||||
23
src/screen.c
23
src/screen.c
@ -1,12 +1,12 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* :::::::: */
|
/* ::: :::::::: */
|
||||||
/* screen.c :+: :+: */
|
/* screen.c :+: :+: :+: */
|
||||||
/* +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/15 15:30:27 by qmennen #+# #+# */
|
/* Created: 2025/04/15 15:30:27 by qmennen #+# #+# */
|
||||||
/* Updated: 2025/05/23 15:17:59 by whaffman ######## odam.nl */
|
/* Updated: 2025/05/27 16:59:17 by qmennen ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -23,6 +23,7 @@ int screen_create(t_game **game)
|
|||||||
screen->width = WIDTH;
|
screen->width = WIDTH;
|
||||||
screen->height = HEIGHT;
|
screen->height = HEIGHT;
|
||||||
mlx_set_setting(MLX_FULLSCREEN, 0);
|
mlx_set_setting(MLX_FULLSCREEN, 0);
|
||||||
|
mlx_set_setting(MLX_STRETCH_IMAGE, 1);
|
||||||
mlx = mlx_init(WIDTH, HEIGHT, TITLE, true);
|
mlx = mlx_init(WIDTH, HEIGHT, TITLE, true);
|
||||||
if (!mlx)
|
if (!mlx)
|
||||||
return (FAILURE);
|
return (FAILURE);
|
||||||
@ -89,16 +90,6 @@ int screen_display(t_screen *screen)
|
|||||||
printf(RED"Failed to display buffer image\n"RESET);
|
printf(RED"Failed to display buffer image\n"RESET);
|
||||||
return (FAILURE);
|
return (FAILURE);
|
||||||
}
|
}
|
||||||
if (mlx_image_to_window(screen->mlx, screen->minimap, 175, 575) < 0)
|
|
||||||
{
|
|
||||||
printf(RED"Failed to display buffer image\n"RESET);
|
|
||||||
return (FAILURE);
|
|
||||||
}
|
|
||||||
if (mlx_image_to_window(screen->mlx, screen->hud, 0, 0) < 0)
|
|
||||||
{
|
|
||||||
printf(RED"Failed to display buffer image\n"RESET);
|
|
||||||
return (FAILURE);
|
|
||||||
}
|
|
||||||
if (!center_window(screen))
|
if (!center_window(screen))
|
||||||
return (FAILURE);
|
return (FAILURE);
|
||||||
return (SUCCESS);
|
return (SUCCESS);
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* :::::::: */
|
/* ::: :::::::: */
|
||||||
/* shaders.c :+: :+: */
|
/* shaders.c :+: :+: :+: */
|
||||||
/* +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/05/08 18:27:59 by qmennen #+# #+# */
|
/* Created: 2025/05/08 18:27:59 by qmennen #+# #+# */
|
||||||
/* Updated: 2025/05/24 13:52:26 by whaffman ######## odam.nl */
|
/* Updated: 2025/05/27 18:45:57 by qmennen ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,9 +14,6 @@
|
|||||||
#include "glad.h"
|
#include "glad.h"
|
||||||
#include "MLX42_Int.h"
|
#include "MLX42_Int.h"
|
||||||
|
|
||||||
// extern char *vert_shader;
|
|
||||||
// extern char *frag_shader;
|
|
||||||
|
|
||||||
void set_uniforms(t_game *game)
|
void set_uniforms(t_game *game)
|
||||||
{
|
{
|
||||||
mlx_ctx_t *ctx;
|
mlx_ctx_t *ctx;
|
||||||
@ -44,27 +41,20 @@ const char *read_shader(int type)
|
|||||||
fd = open(target, O_RDONLY);
|
fd = open(target, O_RDONLY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
{
|
{
|
||||||
perror("Error opening shader file");
|
return (perror("Error opening shader file"), NULL);
|
||||||
return (NULL);
|
|
||||||
}
|
}
|
||||||
shader = malloc(4096);
|
shader = malloc(4096);
|
||||||
if (!shader)
|
if (!shader)
|
||||||
{
|
{
|
||||||
perror("Error allocating memory for shader");
|
return (perror("Error allocating memory for shader"), close(fd), NULL);
|
||||||
close(fd);
|
|
||||||
return (NULL);
|
|
||||||
}
|
}
|
||||||
bytes_read = read(fd, shader, 4096);
|
bytes_read = read(fd, shader, 4096);
|
||||||
if (bytes_read < 0)
|
if (bytes_read < 0)
|
||||||
{
|
{
|
||||||
perror("Error reading shader file");
|
return (perror("Error reading shader file"), free(shader), close(fd), NULL);
|
||||||
free(shader);
|
|
||||||
close(fd);
|
|
||||||
return (NULL);
|
|
||||||
}
|
}
|
||||||
shader[bytes_read] = '\0';
|
shader[bytes_read] = '\0';
|
||||||
close(fd);
|
return (close(fd), shader);
|
||||||
return (shader);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int shader_init(t_game **game)
|
int shader_init(t_game **game)
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* :::::::: */
|
/* ::: :::::::: */
|
||||||
/* initialize.c :+: :+: */
|
/* initialize.c :+: :+: :+: */
|
||||||
/* +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/22 17:08:26 by qmennen #+# #+# */
|
/* Created: 2025/04/22 17:08:26 by qmennen #+# #+# */
|
||||||
/* Updated: 2025/05/26 12:30:34 by whaffman ######## odam.nl */
|
/* Updated: 2025/05/27 15:12:33 by qmennen ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -55,8 +55,12 @@ static int init_temp(t_game **game)
|
|||||||
// sprites[8] = make_sprite("./assets/broken_mirror.png", 42.5, 4.5, 0);
|
// sprites[8] = make_sprite("./assets/broken_mirror.png", 42.5, 4.5, 0);
|
||||||
// sprites[9] = make_sprite("./assets/lamp.png", 9.5, 10.5, 0);
|
// sprites[9] = make_sprite("./assets/lamp.png", 9.5, 10.5, 0);
|
||||||
// (*game)->map->n_sprites = 10;
|
// (*game)->map->n_sprites = 10;
|
||||||
|
mlx_texture_t *hud_texture;
|
||||||
|
|
||||||
|
hud_texture = mlx_load_png("./assets/overlay2.png");
|
||||||
(*game)->screen->hud = mlx_texture_to_image((*game)->screen->mlx,
|
(*game)->screen->hud = mlx_texture_to_image((*game)->screen->mlx,
|
||||||
mlx_load_png("./assets/overlay2.png"));
|
hud_texture);
|
||||||
|
mlx_delete_texture(hud_texture);
|
||||||
return (SUCCESS);
|
return (SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +82,5 @@ int initialize_cub3d(t_game **game, const char *mapfile)
|
|||||||
return (FAILURE);
|
return (FAILURE);
|
||||||
if (!screen_display((*game)->screen))
|
if (!screen_display((*game)->screen))
|
||||||
return (FAILURE);
|
return (FAILURE);
|
||||||
mlx_key_hook((*game)->screen->mlx, keyhandle, *game);
|
|
||||||
mlx_loop_hook((*game)->screen->mlx, game_loop, *game);
|
|
||||||
return (SUCCESS);
|
return (SUCCESS);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* :::::::: */
|
/* ::: :::::::: */
|
||||||
/* keyboard.c :+: :+: */
|
/* keyboard.c :+: :+: :+: */
|
||||||
/* +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/17 19:29:29 by qmennen #+# #+# */
|
/* Created: 2025/04/17 19:29:29 by qmennen #+# #+# */
|
||||||
/* Updated: 2025/05/14 20:01:04 by whaffman ######## odam.nl */
|
/* Updated: 2025/05/27 15:19:38 by qmennen ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -55,5 +55,6 @@ int get_key_down(t_game *game, int k)
|
|||||||
|
|
||||||
int get_key_up(t_game *game, int k)
|
int get_key_up(t_game *game, int k)
|
||||||
{
|
{
|
||||||
|
// printf("get_key_up: %d, last_keys %d\n", k, game->keyboard->last_keys[k]);
|
||||||
return (!get_key(game, k) && game->keyboard->last_keys[k]);
|
return (!get_key(game, k) && game->keyboard->last_keys[k]);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user