now mostly norminette compliant

This commit is contained in:
Quinten Mennen 2025-05-28 15:05:57 +02:00
parent 8521bfa7e4
commit dc8abaa9ab
21 changed files with 319 additions and 283 deletions

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 15:46:16 by qmennen #+# #+# */
/* Updated: 2025/05/27 13:58:21 by qmennen ### ########.fr */
/* Updated: 2025/05/28 14:28:02 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -22,5 +22,7 @@ void game_terminate(t_game *game);
void free_game(t_game **game);
void print_scores(t_game *game);
void game_run(t_game *game);
void handle_battery(t_game *game);
void handle_record(t_game *game);
#endif

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/27 15:07:48 by qmennen #+# #+# */
/* Updated: 2025/05/28 14:15:18 by qmennen ### ########.fr */
/* Updated: 2025/05/28 14:53:54 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,9 +16,11 @@
# include "cub3d.h"
void menu_display(t_menu *menu, t_screen *screen);
mlx_image_t *menu_load_background(mlx_t *mlx, char *background_path);
t_menu *create_main_menu(t_game_manager *manager);
t_menu *menu_create(t_game_manager *manager, char *background_path, const t_menu_item *options[]);
t_menu_item *menu_item_create(const char *text,
t_menu *menu_create(t_game_manager *manager, char *b_path,
const t_menu_item *options[]);
t_menu_item *menu_item_create(t_screen *screen, const char *text,
void (*act)(struct s_menu_item *item, t_game_manager *manager));
void menu_free(t_menu *menu, t_screen *screen);
void menu_toggle(t_menu *menu, t_screen *screen);

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 15:52:44 by qmennen #+# #+# */
/* Updated: 2025/05/28 14:17:55 by qmennen ### ########.fr */
/* Updated: 2025/05/28 14:40:50 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -173,7 +173,7 @@ typedef struct s_menu
// char *options[MAX_MENU_OPTIONS];
// mlx_image_t *option_images[MAX_MENU_OPTIONS];
mlx_image_t *selector;
mlx_image_t *background_image;
mlx_image_t *background;
} t_menu;

View File

@ -6,13 +6,13 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 15:46:08 by qmennen #+# #+# */
/* Updated: 2025/05/28 14:20:43 by qmennen ### ########.fr */
/* Updated: 2025/05/28 14:28:16 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
#include "glad.h"
#include "MLX42_Int.h"
#include "game.h"
// #include "glad.h"
// #include "MLX42_Int.h"
int game_create(t_game **game)
{
@ -20,7 +20,6 @@ int game_create(t_game **game)
if (!game)
return (FAILURE);
ft_memset(*game, 0, sizeof(t_game));
// (*game)->state = GAME_STATE_MENU;
(*game)->fps = 20;
return (SUCCESS);
}
@ -39,97 +38,6 @@ 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)
{
static mlx_image_t *bat_img = NULL;
game->player->battery -= game->screen->mlx->delta_time / 50;
if (game->player->battery < 0.20)
{
//if (bat_img == NULL)
bat_img = mlx_put_string(
game->screen->mlx, "Battery LOW!", 960, 512);
}
else
{
if (bat_img != NULL)
{
mlx_delete_image(game->screen->mlx, bat_img);
bat_img = NULL;
}
}
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_run(t_game *game)
{
static int fps = 0;

101
src/game/game_hud.c Normal file
View File

@ -0,0 +1,101 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* game_hud.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/28 14:26:29 by qmennen #+# #+# */
/* Updated: 2025/05/28 14:28:40 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
#include "game.h"
static int battery_color(float battery)
{
if (battery > 0.5f)
return (0x00FF0066);
else if (battery > 0.25f)
return (0xFFFF0066);
else
return (0xFF000066);
}
static 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)
{
static mlx_image_t *bat_img = NULL;
game->player->battery -= game->screen->mlx->delta_time / 50;
if (game->player->battery < 0.20)
{
bat_img = mlx_put_string(
game->screen->mlx, "Battery LOW!", 960, 512);
}
else
{
if (bat_img != NULL)
{
mlx_delete_image(game->screen->mlx, bat_img);
bat_img = NULL;
}
}
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++;
}
}

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 16:01:29 by qmennen #+# #+# */
/* Updated: 2025/05/28 14:15:30 by qmennen ### ########.fr */
/* Updated: 2025/05/28 14:24:29 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/27 13:48:18 by qmennen #+# #+# */
/* Updated: 2025/05/28 14:20:57 by qmennen ### ########.fr */
/* Updated: 2025/05/28 15:02:30 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,6 +15,7 @@
t_game_manager *game_manager_create(t_game *game)
{
t_game_manager *manager;
manager = malloc(sizeof(t_game_manager));
if (!manager)
return (NULL);
@ -29,7 +30,7 @@ void game_manager_display(t_game_manager *manager)
t_game *game;
if (!manager || !manager->game)
return;
return ;
game = manager->game;
if (manager->state == GAME_STATE_MENU)
{
@ -54,7 +55,7 @@ void game_manager_update(void *param)
void game_manager_destroy(t_game_manager *manager)
{
if (!manager)
return;
return ;
if (manager->menu)
menu_free(manager->menu, manager->game->screen);
if (manager->end_screen)

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/27 15:22:15 by qmennen #+# #+# */
/* Updated: 2025/05/28 14:23:14 by qmennen ### ########.fr */
/* Updated: 2025/05/28 15:03:04 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -31,7 +31,8 @@ void game_manager_handle_input(t_game_manager *manager)
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)
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))

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/23 12:22:28 by whaffman #+# #+# */
/* Updated: 2025/05/28 13:18:25 by qmennen ### ########.fr */
/* Updated: 2025/05/28 14:30:16 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,9 +18,9 @@ void map_free(t_map *map)
int i;
grid_free(map->grid, map->height);
if(map->texture_floor)
if (map->texture_floor)
mlx_delete_texture(map->texture_floor);
if(map->texture_ceiling)
if (map->texture_ceiling)
mlx_delete_texture(map->texture_ceiling);
i = 0;
while (i < 26)
@ -38,6 +38,5 @@ void map_free(t_map *map)
if (map->textures[i])
mlx_delete_texture(map->textures[i]);
}
// free(map->textures);
free(map);
}

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/28 14:14:11 by qmennen #+# #+# */
/* Updated: 2025/05/28 14:22:31 by qmennen ### ########.fr */
/* Updated: 2025/05/28 15:00:41 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -40,13 +40,12 @@ static void game_start(struct s_menu_item *item, t_game_manager *manager)
manager->state = GAME_STATE_PLAYING;
}
t_menu *create_main_menu(t_game_manager *manager)
{
const t_menu_item *menu_items[] = {
menu_item_create("Start Game", game_start),
menu_item_create("Scoreboard", NULL),
menu_item_create("Exit", game_exit),
menu_item_create(manager->game->screen, "Start Game", game_start),
menu_item_create(manager->game->screen, "Scoreboard", NULL),
menu_item_create(manager->game->screen, "Exit", game_exit),
NULL
};
t_menu *menu;

View File

@ -6,30 +6,14 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/27 14:31:53 by qmennen #+# #+# */
/* Updated: 2025/05/28 14:12:58 by qmennen ### ########.fr */
/* Updated: 2025/05/28 15:00:00 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
# include "game_menu.h"
#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 t_menu_item *options[])
t_menu *menu_create(t_game_manager *manager, char *b_path,
const t_menu_item *options[])
{
t_menu *menu;
int i;
@ -38,52 +22,45 @@ t_menu *menu_create(t_game_manager *manager, char *background_path, const t_menu
if (!menu)
return (NULL);
ft_memset(menu, 0, sizeof(t_menu));
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)
if (b_path)
menu->background = menu_load_background(
manager->game->screen->mlx, b_path);
if (mlx_image_to_window(
manager->game->screen->mlx, menu->background, 0, 0) < 0)
{
printf("Failed to display background image\n");
mlx_delete_image(manager->game->screen->mlx, menu->background_image);
mlx_delete_image(manager->game->screen->mlx, menu->background);
return (free(menu), NULL);
}
menu->background_image->instances[0].enabled = false;
menu->selector = 0;
menu->selected_option = 0;
menu->num_options = 0;
menu->background->instances[0].enabled = false;
menu->hidden = 1;
i = -1;
while (options[++i])
{
menu->items[i] = (t_menu_item *) options[i];
}
menu->num_options = 3;
menu->items[i] = (t_menu_item *)options[i];
menu->selector = mlx_put_string(manager->game->screen->mlx, ">", 0, 0);
menu->selector->instances[0].enabled = false;
menu->num_options = i;
return (menu);
}
void menu_display(t_menu *menu, t_screen *screen)
{
int i;
int half_w;
int half_h;
half_w = screen->width / 2;
half_h = screen->height / 2;
if (menu->hidden)
{
menu_toggle(menu, screen);
}
if (menu->selector == 0)
{
menu->selector = mlx_put_string(screen->mlx, ">", screen->width / 2 - 100, (screen->height - 100) / 2 + menu->selected_option * 50);
}
menu->selector->instances[0].x = half_w - 100;
menu->selector->instances[0].y = half_h + menu->selected_option * 50;
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->items[i]->image == 0)
{
menu->items[i]->image = mlx_put_string(screen->mlx, menu->items[i]->text,
menu->items[i]->image = mlx_put_string(
screen->mlx, menu->items[i]->text,
(screen->width - ft_strlen(menu->items[i]->text) * 10) / 2,
(screen->height - 100) / 2 + i * 50);
}
half_h + i * 50);
i++;
}
}
@ -93,24 +70,15 @@ void menu_toggle(t_menu *menu, t_screen *screen)
int i;
if (!menu)
return;
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;
}
if (menu->background)
menu->background->instances[0].enabled = !menu->hidden;
i = -1;
while (++i < menu->num_options)
{
if (menu->items[i]->image)
{
menu->items[i]->image->instances[0].enabled = !menu->hidden;
}
}
}
void menu_free(t_menu *menu, t_screen *screen)
@ -119,7 +87,7 @@ void menu_free(t_menu *menu, t_screen *screen)
i = 0;
if (!menu)
return;
return ;
while (i < menu->num_options)
{
if (menu->items[i]->image)
@ -130,7 +98,7 @@ void menu_free(t_menu *menu, t_screen *screen)
}
if (menu->selector)
mlx_delete_image(screen->mlx, menu->selector);
if (menu->background_image)
mlx_delete_image(screen->mlx, menu->background_image);
if (menu->background)
mlx_delete_image(screen->mlx, menu->background);
free(menu);
}

View File

@ -6,13 +6,13 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/28 13:50:14 by qmennen #+# #+# */
/* Updated: 2025/05/28 14:16:33 by qmennen ### ########.fr */
/* Updated: 2025/05/28 15:00:07 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
#include "game_menu.h"
t_menu_item *menu_item_create(const char *text,
t_menu_item *menu_item_create(t_screen *screen, const char *text,
void (*act)(struct s_menu_item *item, t_game_manager *manager))
{
t_menu_item *item;
@ -23,5 +23,7 @@ t_menu_item *menu_item_create(const char *text,
ft_memset(item, 0, sizeof(t_menu_item));
item->text = (char *)text;
item->act = act;
item->image = mlx_put_string(screen->mlx, text, 0, 0);
item->image->instances[0].enabled = false;
return (item);
}

30
src/menu/menu_util.c Normal file
View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* menu_util.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/28 14:45:59 by qmennen #+# #+# */
/* Updated: 2025/05/28 14:46:31 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
#include "game_menu.h"
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);
}

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* parse_config_line.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* ::: :::::::: */
/* parse_config_line.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/22 13:10:06 by whaffman #+# #+# */
/* Updated: 2025/05/25 11:13:53 by whaffman ######## odam.nl */
/* Updated: 2025/05/28 14:32:43 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -120,7 +120,8 @@ int handle_sprite(char *token, t_map *map)
if (sprite.texture == NULL)
return (FAILURE);
if (map->sprite_lib[symbol - 'a'].texture != NULL)
return (ft_putstr_fd("Error: Sprite already defined for this symbol\n", 2), FAILURE);
return (ft_putstr_fd(
"Error: Sprite already defined for this symbol\n", 2), FAILURE);
map->sprite_lib[symbol - 'a'] = sprite;
return (SUCCESS);
}

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* parse_map.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* ::: :::::::: */
/* parse_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/22 13:12:04 by whaffman #+# #+# */
/* Updated: 2025/05/25 18:54:20 by whaffman ######## odam.nl */
/* Updated: 2025/05/28 14:34:38 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -89,6 +89,7 @@ int count_sprites(char *line)
}
return (count);
}
int prepare_map(char **lines, t_game *game)
{
int y;
@ -113,7 +114,7 @@ int prepare_map(char **lines, t_game *game)
map->sprites = malloc(sizeof(t_sprite) * (map->n_sprites_max + 1));
if (!map->sprites)
return (FAILURE);
ft_memset(map->sprites, 0, sizeof(t_sprite) * (map->n_sprites_max+ 1));
ft_memset(map->sprites, 0, sizeof(t_sprite) * (map->n_sprites_max + 1));
return (SUCCESS);
}
@ -145,6 +146,7 @@ int parse_map_line_sprites(char *line, t_game *game, int y)
}
return (SUCCESS);
}
int parse_map(char **lines, t_game *game)
{
int y;

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* render_sprite.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* ::: :::::::: */
/* render_sprite.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/08 12:23:17 by qmennen #+# #+# */
/* Updated: 2025/05/26 12:53:24 by whaffman ######## odam.nl */
/* Updated: 2025/05/28 15:05:38 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,7 +17,8 @@ static void get_start_end(t_game *game,
{
double sprite_scale;
sprite_scale = game->screen->height / sprite->dist / sprite->texture->height;
sprite_scale = game->screen->height / sprite->dist
/ sprite->texture->height;
start->x = 0.5 * (game->screen->width * (1.0 + sprite->cam_frac)
- sprite->texture->width / sprite->n_frames * sprite_scale);
start->y = 0.5 * (game->screen->height

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 15:30:27 by qmennen #+# #+# */
/* Updated: 2025/05/28 13:04:33 by qmennen ### ########.fr */
/* Updated: 2025/05/28 14:24:41 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -23,7 +23,6 @@ int screen_create(t_game **game)
ft_memset(screen, 0, sizeof(t_screen));
screen->width = WIDTH;
screen->height = HEIGHT;
mlx_set_setting(MLX_FULLSCREEN, 0);
mlx_set_setting(MLX_STRETCH_IMAGE, 1);
mlx = mlx_init(WIDTH, HEIGHT, TITLE, true);
if (!mlx)

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/08 18:27:59 by qmennen #+# #+# */
/* Updated: 2025/05/27 18:45:57 by qmennen ### ########.fr */
/* Updated: 2025/05/28 14:37:33 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -27,17 +27,13 @@ void set_uniforms(t_game *game)
game->screen->width, game->screen->height);
}
const char *read_shader(int type)
static const char *read_vertex_shader(void)
{
const char *target = "./assets/shaders/vert.glsl";
char *shader;
char *target;
int fd;
size_t bytes_read;
if (type == 1)
target = "./assets/shaders/vert.glsl";
else
target = "./assets/shaders/frag.glsl";
fd = open(target, O_RDONLY);
if (fd < 0)
{
@ -51,7 +47,35 @@ const char *read_shader(int type)
bytes_read = read(fd, shader, 4096);
if (bytes_read < 0)
{
return (perror("Error reading shader file"), free(shader), close(fd), NULL);
return (perror("Error reading shader file"),
free(shader), close(fd), NULL);
}
shader[bytes_read] = '\0';
return (close(fd), shader);
}
static const char *read_fragment_shader(void)
{
const char *target = "./assets/shaders/frag.glsl";
char *shader;
int fd;
size_t bytes_read;
fd = open(target, O_RDONLY);
if (fd < 0)
{
return (perror("Error opening shader file"), NULL);
}
shader = malloc(4096);
if (!shader)
{
return (perror("Error allocating memory for shader"), close(fd), NULL);
}
bytes_read = read(fd, shader, 4096);
if (bytes_read < 0)
{
return (perror("Error reading shader file"),
free(shader), close(fd), NULL);
}
shader[bytes_read] = '\0';
return (close(fd), shader);
@ -59,10 +83,10 @@ const char *read_shader(int type)
int shader_init(t_game **game)
{
vert_shader = read_shader(1);
vert_shader = read_vertex_shader();
if (!vert_shader)
return (FAILURE);
frag_shader = read_shader(2);
frag_shader = read_fragment_shader();
if (!frag_shader)
return (FAILURE);
return (SUCCESS);

View File

@ -6,13 +6,14 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/22 17:08:26 by qmennen #+# #+# */
/* Updated: 2025/05/27 15:12:33 by qmennen ### ########.fr */
/* Updated: 2025/05/28 15:05:21 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
t_sprite make_sprite(mlx_texture_t *texture, double x, double y, int collectible)
t_sprite make_sprite(mlx_texture_t *texture, double x, double y,
int collectible)
{
t_sprite sprite;
@ -38,8 +39,8 @@ t_sprite make_sprite(mlx_texture_t *texture, double x, double y, int collectible
static int init_temp(t_game **game)
{
mlx_texture_t *hud_texture;
// t_sprite *sprites;
// (*game)->map->sprites = malloc(sizeof(t_sprite) * 10);
// if (!(*game)->map->sprites)
// return (FAILURE);
@ -55,8 +56,6 @@ static int init_temp(t_game **game)
// 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);
// (*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,
hud_texture);

View File

@ -6,13 +6,12 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/17 19:29:29 by qmennen #+# #+# */
/* Updated: 2025/05/27 15:19:38 by qmennen ### ########.fr */
/* Updated: 2025/05/28 15:04:21 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
#include "keyboard.h"
// TODO: Better
int keyboard_create(t_game **game)
{
t_keyboard *keyboard;
@ -22,11 +21,10 @@ int keyboard_create(t_game **game)
if (!keyboard)
return (FAILURE);
(*game)->keyboard = keyboard;
i = 0;
while (i < NUM_KEYS)
i = -1;
while (++i < NUM_KEYS)
{
(*game)->keyboard->keys[i] = 0;
i++;
}
return (SUCCESS);
}
@ -55,6 +53,5 @@ int get_key_down(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]);
}

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* score.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* ::: :::::::: */
/* score.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/25 20:54:23 by whaffman #+# #+# */
/* Updated: 2025/05/25 21:00:49 by whaffman ######## odam.nl */
/* Updated: 2025/05/28 15:03:53 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */