Merge remote-tracking branch 'origin/quinten' into willem
This commit is contained in:
commit
ede0cd6f68
4
Makefile
4
Makefile
@ -6,7 +6,7 @@
|
||||
# By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/10/15 11:48:46 by whaffman #+# #+# #
|
||||
# Updated: 2025/05/27 17:00:58 by qmennen ### ########.fr #
|
||||
# Updated: 2025/05/28 17:48:28 by qmennen ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -53,7 +53,7 @@ debug_CFLAGS = -Wall -Werror -Werror -g3 -DDEBUG -DDBG='fprintf(stderr, RED "DEB
|
||||
asan_CFLAGS = -Wall -Werror -Werror -fsanitize=address,leak,undefined -g3
|
||||
tsan_CFLAGS = -Wall -Werror -Werror -fsanitize=thread -g3
|
||||
|
||||
RUN_ARGS=test.cub
|
||||
RUN_ARGS=monster.cub
|
||||
|
||||
# Targets for each build configuration
|
||||
define BUILD_TARGETS
|
||||
|
||||
BIN
assets/flying_eye.png
Normal file
BIN
assets/flying_eye.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.4 KiB |
BIN
assets/mushroom.png
Normal file
BIN
assets/mushroom.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.6 KiB |
@ -6,7 +6,7 @@
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/15 12:22:29 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/27 18:14:06 by qmennen ### ########.fr */
|
||||
/* Updated: 2025/05/28 17:30:51 by qmennen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -60,6 +60,7 @@
|
||||
# include "texture.h"
|
||||
# include "game_manager.h"
|
||||
# include "game_menu.h"
|
||||
# include "monster.h"
|
||||
|
||||
int initialize_cub3d(t_game **game, const char *mapfile);
|
||||
int shader_init(t_game **game);
|
||||
|
||||
@ -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
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* 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 */
|
||||
/* Updated: 2025/05/28 14:53:54 by qmennen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -15,9 +15,14 @@
|
||||
|
||||
# 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);
|
||||
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 *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);
|
||||
|
||||
#endif
|
||||
16
inc/map.h
16
inc/map.h
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* map.h :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/17 19:19:19 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/25 13:39:13 by whaffman ######## odam.nl */
|
||||
/* ::: :::::::: */
|
||||
/* map.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/17 19:19:19 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/28 17:07:28 by qmennen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -26,6 +26,6 @@ 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(mlx_texture_t *texture, double x, double y, int collectible);
|
||||
t_sprite make_sprite(t_sprite_lib *def, double x, double y);
|
||||
|
||||
#endif
|
||||
|
||||
20
inc/monster.h
Normal file
20
inc/monster.h
Normal file
@ -0,0 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* monster.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/28 17:16:29 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/28 17:16:43 by qmennen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MONSTER_H
|
||||
# define MONSTER_H
|
||||
|
||||
# include "cub3d.h"
|
||||
|
||||
void update_monsters(t_game *game);
|
||||
|
||||
#endif
|
||||
48
inc/types.h
48
inc/types.h
@ -6,7 +6,7 @@
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/15 15:52:44 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/27 18:42:09 by qmennen ### ########.fr */
|
||||
/* Updated: 2025/05/28 17:14:28 by qmennen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -24,6 +24,14 @@ typedef enum TILE
|
||||
TILE_PLAYER = 2,
|
||||
} t_tile;
|
||||
|
||||
typedef enum SPRITE_TYPE
|
||||
{
|
||||
SPRITE_TYPE_DEFAULT = 0,
|
||||
SPRITE_TYPE_COLLECTIBLE = 1,
|
||||
SPRITE_TYPE_COLLECTED = 2,
|
||||
SPRITE_TYPE_ENEMY = 3,
|
||||
} t_sprite_type;
|
||||
|
||||
typedef struct s_vec2
|
||||
{
|
||||
double x;
|
||||
@ -61,18 +69,19 @@ typedef struct s_player
|
||||
typedef struct s_sprite
|
||||
{
|
||||
int n_frames;
|
||||
int animation_speed;
|
||||
double dist;
|
||||
double cam_frac;
|
||||
int alpha;
|
||||
int visible;
|
||||
int collectible;
|
||||
mlx_texture_t *texture;
|
||||
t_sprite_type type;
|
||||
t_vec2 pos;
|
||||
} t_sprite;
|
||||
|
||||
typedef struct s_sprite_lib
|
||||
{
|
||||
mlx_texture_t *texture;
|
||||
t_sprite_type type;
|
||||
int collectible;
|
||||
} t_sprite_lib;
|
||||
|
||||
@ -145,29 +154,36 @@ typedef struct s_game
|
||||
t_player *player;
|
||||
t_screen *screen;
|
||||
t_keyboard *keyboard;
|
||||
int framecount;
|
||||
double elapsed_time;
|
||||
int fps;
|
||||
t_game_state state;
|
||||
} t_game;
|
||||
typedef struct s_game_manager
|
||||
{
|
||||
t_game_state state;
|
||||
t_game *game;
|
||||
struct s_menu *menu;
|
||||
struct s_menu *end_screen;
|
||||
struct s_menu **active_menu;
|
||||
} t_game_manager;
|
||||
|
||||
typedef struct s_menu_item
|
||||
{
|
||||
char *text;
|
||||
mlx_image_t *image;
|
||||
void (*act)(struct s_menu_item *item, t_game_manager *manager);
|
||||
} t_menu_item;
|
||||
|
||||
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];
|
||||
t_menu_item *items[MAX_MENU_OPTIONS];
|
||||
// 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;
|
||||
|
||||
typedef struct s_game_manager
|
||||
{
|
||||
t_game *game;
|
||||
t_menu *menu;
|
||||
t_menu *end_screen;
|
||||
t_menu **active_menu;
|
||||
} t_game_manager;
|
||||
|
||||
#endif
|
||||
|
||||
41
monster.cub
Normal file
41
monster.cub
Normal file
@ -0,0 +1,41 @@
|
||||
|
||||
|
||||
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/flying_eye.png
|
||||
-s b ./assets/mushroom.png
|
||||
|
||||
1111
|
||||
1a01
|
||||
1001
|
||||
10b1
|
||||
1001
|
||||
1001
|
||||
1001
|
||||
1001
|
||||
1001
|
||||
1001
|
||||
1001
|
||||
1001
|
||||
1001
|
||||
1001
|
||||
1001
|
||||
1001
|
||||
1001
|
||||
1001
|
||||
1001
|
||||
10N1
|
||||
1111
|
||||
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* collision.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/22 14:40:59 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/23 17:29:23 by whaffman ######## odam.nl */
|
||||
/* ::: :::::::: */
|
||||
/* collision.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/22 14:40:59 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/28 17:13:24 by qmennen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -28,12 +28,13 @@ int collision_sprite(t_map *map, t_player *player, double xa, double ya)
|
||||
i = 0;
|
||||
while (i < map->n_sprites)
|
||||
{
|
||||
if (sprites[i].visible && sprites[i].collectible)
|
||||
if (sprites[i].type == SPRITE_TYPE_COLLECTIBLE)
|
||||
{
|
||||
|
||||
if (fabs(player->pos.x + xa - sprites[i].pos.x) < 0.5
|
||||
&& fabs(player->pos.y + ya - sprites[i].pos.y) < 0.5)
|
||||
{
|
||||
sprites[i].visible = 0;
|
||||
sprites[i].type = SPRITE_TYPE_COLLECTED;
|
||||
collect(player);
|
||||
return (1);
|
||||
}
|
||||
|
||||
186
src/game.c
186
src/game.c
@ -1,186 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* game.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/15 15:46:08 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/28 13:54:58 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d.h"
|
||||
#include "glad.h"
|
||||
#include "MLX42_Int.h"
|
||||
|
||||
int game_create(t_game **game)
|
||||
{
|
||||
*game = malloc(sizeof(t_game));
|
||||
if (!game)
|
||||
return (FAILURE);
|
||||
memset(*game, 0, sizeof(t_game));
|
||||
(*game)->state = GAME_STATE_MENU;
|
||||
(*game)->fps = 20;
|
||||
return (SUCCESS);
|
||||
}
|
||||
|
||||
void free_game(t_game **game)
|
||||
{
|
||||
if (game && *game)
|
||||
{
|
||||
if ((*game)->screen)
|
||||
free((*game)->screen);
|
||||
if ((*game)->player)
|
||||
free((*game)->player);
|
||||
if ((*game)->map)
|
||||
free((*game)->map);
|
||||
free(*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;
|
||||
|
||||
game->framecount++;
|
||||
fps += (int)(1.f / game->screen->mlx->delta_time);
|
||||
set_uniforms(game);
|
||||
if (game->framecount % 20 == 0)
|
||||
{
|
||||
game->fps = (int)(fps / 20);
|
||||
fprintf(stderr, "FPS: %d\n", fps / 20);
|
||||
fps = 0;
|
||||
}
|
||||
player_update(game, game->screen->mlx->delta_time);
|
||||
cast_rays(game);
|
||||
render_map(game);
|
||||
if (game->player->is_moving)
|
||||
{
|
||||
game->screen->img->instances[0].x = sin(game->framecount / 6.0) * 20;
|
||||
game->screen->img->instances[0].y = cos(game->framecount / 3.0) * 10;
|
||||
}
|
||||
handle_battery(game);
|
||||
handle_record(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)
|
||||
{
|
||||
mlx_delete_image(game->screen->mlx, game->screen->img);
|
||||
mlx_close_window(game->screen->mlx);
|
||||
mlx_terminate(game->screen->mlx);
|
||||
free(game->screen);
|
||||
}
|
||||
if (game->player)
|
||||
free(game->player);
|
||||
if (game->map)
|
||||
map_free(game->map);
|
||||
if (game->keyboard)
|
||||
free(game->keyboard);
|
||||
free(game);
|
||||
}
|
||||
|
||||
void game_terminate(t_game *game)
|
||||
{
|
||||
print_scores(game);
|
||||
game_free(game);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
89
src/game/game.c
Normal file
89
src/game/game.c
Normal file
@ -0,0 +1,89 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* game.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/15 15:46:08 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/28 17:39:24 by qmennen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "game.h"
|
||||
// #include "glad.h"
|
||||
// #include "MLX42_Int.h"
|
||||
|
||||
int game_create(t_game **game)
|
||||
{
|
||||
*game = malloc(sizeof(t_game));
|
||||
if (!game)
|
||||
return (FAILURE);
|
||||
ft_memset(*game, 0, sizeof(t_game));
|
||||
(*game)->fps = 20;
|
||||
return (SUCCESS);
|
||||
}
|
||||
|
||||
void free_game(t_game **game)
|
||||
{
|
||||
if (game && *game)
|
||||
{
|
||||
if ((*game)->screen)
|
||||
free((*game)->screen);
|
||||
if ((*game)->player)
|
||||
free((*game)->player);
|
||||
if ((*game)->map)
|
||||
free((*game)->map);
|
||||
free(*game);
|
||||
}
|
||||
}
|
||||
|
||||
void game_run(t_game *game)
|
||||
{
|
||||
static int fps = 0;
|
||||
|
||||
game->elapsed_time += game->screen->mlx->delta_time;
|
||||
fps += (int)(1.f / game->screen->mlx->delta_time);
|
||||
set_uniforms(game);
|
||||
player_update(game, game->screen->mlx->delta_time);
|
||||
cast_rays(game);
|
||||
update_monsters(game);
|
||||
render_map(game);
|
||||
if (game->player->is_moving)
|
||||
{
|
||||
game->screen->img->instances[0].x = sin(game->elapsed_time * 10) * 20;
|
||||
game->screen->img->instances[0].y = cos(game->elapsed_time * 18) * 10;
|
||||
}
|
||||
handle_battery(game);
|
||||
handle_record(game);
|
||||
}
|
||||
|
||||
void game_free(t_game *game)
|
||||
{
|
||||
if (game->screen)
|
||||
{
|
||||
if (game->screen->hud)
|
||||
{
|
||||
mlx_delete_image(game->screen->mlx, game->screen->hud);
|
||||
game->screen->hud = NULL;
|
||||
}
|
||||
mlx_delete_image(game->screen->mlx, game->screen->img);
|
||||
mlx_close_window(game->screen->mlx);
|
||||
mlx_terminate(game->screen->mlx);
|
||||
free(game->screen);
|
||||
}
|
||||
if (game->player)
|
||||
free(game->player);
|
||||
if (game->map)
|
||||
map_free(game->map);
|
||||
if (game->keyboard)
|
||||
free(game->keyboard);
|
||||
free(game);
|
||||
}
|
||||
|
||||
void game_terminate(t_game *game)
|
||||
{
|
||||
print_scores(game);
|
||||
game_free(game);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
101
src/game/game_hud.c
Normal file
101
src/game/game_hud.c
Normal 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 17:01:42 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 = ((int) game->elapsed_time) % 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++;
|
||||
}
|
||||
}
|
||||
15
src/main.c
15
src/main.c
@ -3,10 +3,10 @@
|
||||
/* :::::::: */
|
||||
/* main.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/15 16:01:29 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/28 13:56:56 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/05/28 18:49:29 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,8 +14,8 @@
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
t_game_manager *manager;
|
||||
t_game *game;
|
||||
t_game_manager *manager;
|
||||
t_game *game;
|
||||
|
||||
errno = 0;
|
||||
game = NULL;
|
||||
@ -29,11 +29,8 @@ int main(int argc, char **argv)
|
||||
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;
|
||||
manager->menu = create_main_menu(manager);
|
||||
manager->active_menu = &manager->menu;
|
||||
mlx_key_hook(game->screen->mlx, keyhandle, game);
|
||||
mlx_loop_hook(game->screen->mlx, game_manager_update, manager);
|
||||
mlx_loop(game->screen->mlx);
|
||||
|
||||
@ -6,54 +6,52 @@
|
||||
/* 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 */
|
||||
/* Updated: 2025/05/28 15:07:38 by qmennen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "game_manager.h"
|
||||
|
||||
t_game_manager *game_manager_create(t_game *game)
|
||||
t_game_manager *game_manager_create(t_game *game)
|
||||
{
|
||||
t_game_manager *manager;
|
||||
t_game_manager *manager;
|
||||
|
||||
manager = malloc(sizeof(t_game_manager));
|
||||
if (!manager)
|
||||
return (NULL);
|
||||
manager->game = game;
|
||||
manager->menu = NULL;
|
||||
manager->state = GAME_STATE_MENU;
|
||||
return (manager);
|
||||
}
|
||||
|
||||
void game_manager_display(t_game_manager *manager)
|
||||
void game_manager_display(t_game_manager *manager)
|
||||
{
|
||||
t_game *game;
|
||||
t_game *game;
|
||||
|
||||
if (!manager || !manager->game)
|
||||
return;
|
||||
return ;
|
||||
game = manager->game;
|
||||
if (game->state == GAME_STATE_MENU)
|
||||
{
|
||||
if (manager->state == GAME_STATE_MENU)
|
||||
menu_display(*(manager->active_menu), game->screen);
|
||||
}
|
||||
else if (game->state == GAME_STATE_PLAYING)
|
||||
{
|
||||
else if (manager->state == GAME_STATE_PLAYING)
|
||||
game_run(game);
|
||||
}
|
||||
}
|
||||
|
||||
void game_manager_update(void *param)
|
||||
void game_manager_update(void *param)
|
||||
{
|
||||
t_game_manager *manager;
|
||||
|
||||
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)
|
||||
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)
|
||||
@ -61,8 +59,8 @@ void game_manager_destroy(t_game_manager *manager)
|
||||
print_scores(manager->game);
|
||||
if (manager->game)
|
||||
{
|
||||
game_free(manager->game);
|
||||
game_free(manager->game);
|
||||
}
|
||||
free(manager);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,47 +6,22 @@
|
||||
/* 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 */
|
||||
/* Updated: 2025/05/28 15:03:04 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;
|
||||
int selected_option;
|
||||
|
||||
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 ;
|
||||
}
|
||||
|
||||
(*manager->active_menu)->items[selected_option]->act(
|
||||
(*manager->active_menu)->items[selected_option], manager);
|
||||
}
|
||||
|
||||
void game_manager_handle_input(t_game_manager *manager)
|
||||
void game_manager_handle_input(t_game_manager *manager)
|
||||
{
|
||||
if (get_key_down(manager->game, MLX_KEY_ENTER))
|
||||
{
|
||||
@ -56,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))
|
||||
@ -65,4 +41,4 @@ void game_manager_handle_input(t_game_manager *manager)
|
||||
if (manager->menu->selected_option < 0)
|
||||
manager->menu->selected_option = manager->menu->num_options - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,16 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* grid_free.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/23 12:20:38 by whaffman #+# #+# */
|
||||
/* Updated: 2025/05/25 18:57:09 by whaffman ######## odam.nl */
|
||||
/* ::: :::::::: */
|
||||
/* grid_free.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/23 12:20:38 by whaffman #+# #+# */
|
||||
/* Updated: 2025/05/28 13:09:39 by qmennen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "cub3d.h"
|
||||
|
||||
void grid_free(t_tile **grid, int height)
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* map_create.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/23 12:21:13 by whaffman #+# #+# */
|
||||
/* Updated: 2025/05/25 13:58:34 by whaffman ######## odam.nl */
|
||||
/* ::: :::::::: */
|
||||
/* map_create.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/23 12:21:13 by whaffman #+# #+# */
|
||||
/* Updated: 2025/05/28 13:20:00 by qmennen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -20,7 +20,7 @@ static int map_allocate(t_game **game)
|
||||
perror("Error allocating memory for (*game)->map");
|
||||
return (FAILURE);
|
||||
}
|
||||
ft_memset((*game)->map, 0, sizeof((*game)->map));
|
||||
ft_memset((*game)->map, 0, sizeof(t_map));
|
||||
(*game)->map->sprite_lib = malloc(sizeof(t_sprite_lib) * 26);
|
||||
if (!(*game)->map->sprite_lib)
|
||||
{
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* map_free.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/23 12:22:28 by whaffman #+# #+# */
|
||||
/* Updated: 2025/05/25 18:56:27 by whaffman ######## odam.nl */
|
||||
/* ::: :::::::: */
|
||||
/* map_free.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/23 12:22:28 by whaffman #+# #+# */
|
||||
/* Updated: 2025/05/28 14:30:16 by qmennen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -15,15 +15,12 @@
|
||||
|
||||
void map_free(t_map *map)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
grid_free(map->grid, map->height);
|
||||
// free(map->north_texture);
|
||||
// free(map->south_texture);
|
||||
// free(map->west_texture);
|
||||
// free(map->east_texture);
|
||||
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)
|
||||
@ -41,6 +38,5 @@ void map_free(t_map *map)
|
||||
if (map->textures[i])
|
||||
mlx_delete_texture(map->textures[i]);
|
||||
}
|
||||
// free(map->textures);
|
||||
free(map);
|
||||
}
|
||||
|
||||
57
src/menu/main_menu.c
Normal file
57
src/menu/main_menu.c
Normal file
@ -0,0 +1,57 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main_menu.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/28 14:14:11 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/28 15:00:41 by qmennen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "game_menu.h"
|
||||
|
||||
static void game_exit(struct s_menu_item *item, t_game_manager *manager)
|
||||
{
|
||||
(void)item;
|
||||
game_manager_destroy(manager);
|
||||
}
|
||||
|
||||
static void game_start(struct s_menu_item *item, t_game_manager *manager)
|
||||
{
|
||||
t_game *game;
|
||||
t_screen *screen;
|
||||
|
||||
(void)item;
|
||||
game = manager->game;
|
||||
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);
|
||||
}
|
||||
menu_toggle(*(manager->active_menu), screen);
|
||||
manager->state = GAME_STATE_PLAYING;
|
||||
}
|
||||
|
||||
t_menu *create_main_menu(t_game_manager *manager)
|
||||
{
|
||||
const t_menu_item *menu_items[] = {
|
||||
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;
|
||||
|
||||
menu = menu_create(manager, "./assets/menu_background.png", menu_items);
|
||||
if (!menu)
|
||||
return (NULL);
|
||||
return (menu);
|
||||
}
|
||||
115
src/menu/menu.c
115
src/menu/menu.c
@ -6,130 +6,101 @@
|
||||
/* 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 */
|
||||
/* Updated: 2025/05/28 15:21:30 by qmennen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
# include "game_menu.h"
|
||||
#include "game_menu.h"
|
||||
|
||||
static mlx_image_t *menu_load_background(mlx_t *mlx, char *background_path)
|
||||
t_menu *menu_create(t_game_manager *manager, char *b_path,
|
||||
const t_menu_item *options[])
|
||||
{
|
||||
mlx_texture_t *background_texture;
|
||||
mlx_image_t *background_image;
|
||||
t_menu *menu;
|
||||
int i;
|
||||
|
||||
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)
|
||||
ft_memset(menu, 0, sizeof(t_menu));
|
||||
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;
|
||||
ft_memset(menu->option_images, 0, sizeof(menu->option_images));
|
||||
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] != NULL)
|
||||
{
|
||||
menu->options[i] = (char *)options[i];
|
||||
menu->num_options++;
|
||||
}
|
||||
while (options[++i])
|
||||
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)
|
||||
void menu_display(t_menu *menu, t_screen *screen)
|
||||
{
|
||||
int i;
|
||||
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, 0);
|
||||
}
|
||||
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->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);
|
||||
}
|
||||
menu->items[i]->image->instances[0].x = (screen->width
|
||||
- ft_strlen(menu->items[i]->text) * 10) / 2;
|
||||
menu->items[i]->image->instances[0].y = half_h + i * 50;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void menu_toggle(t_menu *menu, t_screen *screen)
|
||||
{
|
||||
int i;
|
||||
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)
|
||||
while (++i < menu->num_options)
|
||||
{
|
||||
if (menu->option_images[i])
|
||||
{
|
||||
menu->option_images[i]->instances[0].enabled = !menu->hidden;
|
||||
}
|
||||
menu->items[i]->image->instances[0].enabled = !menu->hidden;
|
||||
mlx_set_instance_depth(menu->items[i]->image->instances, 7);
|
||||
}
|
||||
}
|
||||
|
||||
void menu_free(t_menu *menu, t_screen *screen)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if (!menu)
|
||||
return;
|
||||
return ;
|
||||
while (i < menu->num_options)
|
||||
{
|
||||
if (menu->option_images[i])
|
||||
if (menu->items[i]->image)
|
||||
{
|
||||
mlx_delete_image(screen->mlx, menu->option_images[i]);
|
||||
mlx_delete_image(screen->mlx, menu->items[i]->image);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
29
src/menu/menu_item.c
Normal file
29
src/menu/menu_item.c
Normal file
@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* menu_item.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/28 13:50:14 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/28 15:12:45 by qmennen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "game_menu.h"
|
||||
|
||||
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;
|
||||
|
||||
item = malloc(sizeof(t_menu_item));
|
||||
if (!item)
|
||||
return (NULL);
|
||||
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
30
src/menu/menu_util.c
Normal 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);
|
||||
}
|
||||
38
src/monster/monster.c
Normal file
38
src/monster/monster.c
Normal file
@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* monster.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/28 17:15:52 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/28 17:45:37 by qmennen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
# include "cub3d.h"
|
||||
|
||||
void update_monsters(t_game *game)
|
||||
{
|
||||
int i;
|
||||
double dx;
|
||||
double dy;
|
||||
t_sprite *sprite;
|
||||
|
||||
i = -1;
|
||||
while (++i < game->map->n_sprites)
|
||||
{
|
||||
sprite = &game->map->sprites[i];
|
||||
if (sprite->type != SPRITE_TYPE_ENEMY)
|
||||
continue;
|
||||
dx = game->player->pos.x - sprite->pos.x;
|
||||
dy = game->player->pos.y - sprite->pos.y;
|
||||
double dist_squared = dx * dx + dy * dy;
|
||||
if (dist_squared > 0)
|
||||
{
|
||||
double inv_dist = 1.0 / sqrt(dist_squared);
|
||||
sprite->pos.x += dx * inv_dist * .05f;
|
||||
sprite->pos.y += dy * inv_dist * .05f;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* parse_config_line.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/22 13:10:06 by whaffman #+# #+# */
|
||||
/* Updated: 2025/05/25 11:13:53 by whaffman ######## odam.nl */
|
||||
/* ::: :::::::: */
|
||||
/* parse_config_line.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/22 13:10:06 by whaffman #+# #+# */
|
||||
/* Updated: 2025/05/28 17:32:08 by qmennen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -101,13 +101,19 @@ int handle_fc_texture(char *token, t_map *map)
|
||||
int handle_sprite(char *token, t_map *map)
|
||||
{
|
||||
t_sprite_lib sprite;
|
||||
char symbol;
|
||||
char symbol;
|
||||
char *texture_path;
|
||||
|
||||
|
||||
if (token[1] == 'c')
|
||||
{
|
||||
sprite.collectible = 1;
|
||||
else
|
||||
sprite.type = SPRITE_TYPE_COLLECTIBLE;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprite.collectible = 0;
|
||||
sprite.type = SPRITE_TYPE_ENEMY;
|
||||
}
|
||||
symbol = *ft_strtok(NULL, " ");
|
||||
if (symbol < 'a' || symbol > 'z')
|
||||
return (ft_putstr_fd("Error: Invalid sprite symbol\n", 2), FAILURE);
|
||||
@ -120,7 +126,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);
|
||||
}
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* parse_map.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/22 13:12:04 by whaffman #+# #+# */
|
||||
/* Updated: 2025/05/25 18:54:20 by whaffman ######## odam.nl */
|
||||
/* ::: :::::::: */
|
||||
/* parse_map.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/22 13:12:04 by whaffman #+# #+# */
|
||||
/* Updated: 2025/05/28 17:07:32 by qmennen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -74,7 +74,7 @@ int parse_map_line(char **lines, t_game *game, int y)
|
||||
return (SUCCESS);
|
||||
}
|
||||
|
||||
int count_sprites(char *line)
|
||||
int count_sprites(char *line)
|
||||
{
|
||||
int count;
|
||||
int i;
|
||||
@ -89,7 +89,8 @@ int count_sprites(char *line)
|
||||
}
|
||||
return (count);
|
||||
}
|
||||
int prepare_map(char **lines, t_game *game)
|
||||
|
||||
int prepare_map(char **lines, t_game *game)
|
||||
{
|
||||
int y;
|
||||
t_map *map;
|
||||
@ -113,14 +114,14 @@ 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);
|
||||
}
|
||||
|
||||
int parse_map_line_sprites(char *line, t_game *game, int y)
|
||||
int parse_map_line_sprites(char *line, t_game *game, int y)
|
||||
{
|
||||
int x;
|
||||
t_map *map;
|
||||
int x;
|
||||
t_map *map;
|
||||
t_sprite_lib *sprite_lib;
|
||||
|
||||
map = game->map;
|
||||
@ -136,15 +137,15 @@ int parse_map_line_sprites(char *line, t_game *game, int y)
|
||||
return (FAILURE);
|
||||
}
|
||||
map->sprites[map->n_sprites] = make_sprite(
|
||||
sprite_lib[line[x] - 'a'].texture,
|
||||
(double)x + 0.5f, (double)y + 0.5f,
|
||||
sprite_lib[line[x] - 'a'].collectible);
|
||||
&sprite_lib[line[x] - 'a'],
|
||||
(double)x + 0.5f, (double)y + 0.5f);
|
||||
map->n_sprites++;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
return (SUCCESS);
|
||||
}
|
||||
|
||||
int parse_map(char **lines, t_game *game)
|
||||
{
|
||||
int y;
|
||||
@ -152,7 +153,7 @@ int parse_map(char **lines, t_game *game)
|
||||
|
||||
map = game->map;
|
||||
if (!prepare_map(lines, game))
|
||||
return (FAILURE);
|
||||
return (FAILURE);
|
||||
y = 0;
|
||||
while (y < map->height)
|
||||
{
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* render_sprite.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/05/08 12:23:17 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/26 12:53:24 by whaffman ######## odam.nl */
|
||||
/* ::: :::::::: */
|
||||
/* render_sprite.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/08 12:23:17 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/28 17:13:59 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
|
||||
@ -59,7 +60,7 @@ static void draw_sprite_column(
|
||||
tex.y = (y - column.start.y) * sprite->texture->height;
|
||||
tex.y *= inv_range.y;
|
||||
color = sample_texture_color(sprite, tex,
|
||||
(int)(game->framecount / 20) % sprite->n_frames);
|
||||
(int)(game->elapsed_time * sprite->animation_speed) % sprite->n_frames);
|
||||
if (y > 0 && y < game->screen->height && (color & 0xFF) != 0)
|
||||
mlx_put_pixel(game->screen->img, column.x, y, color);
|
||||
y++;
|
||||
@ -99,7 +100,7 @@ void render_sprites(t_render *render, t_game *game)
|
||||
i = 0;
|
||||
while (i < game->map->n_sprites)
|
||||
{
|
||||
if (!game->map->sprites[i].visible)
|
||||
if (game->map->sprites[i].type == SPRITE_TYPE_COLLECTED)
|
||||
{
|
||||
i++;
|
||||
continue ;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/15 15:30:27 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/27 16:59:17 by qmennen ### ########.fr */
|
||||
/* Updated: 2025/05/28 14:24:41 by qmennen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -20,9 +20,9 @@ int screen_create(t_game **game)
|
||||
screen = malloc(sizeof(t_screen));
|
||||
if (!screen)
|
||||
return (FAILURE);
|
||||
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)
|
||||
|
||||
@ -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)
|
||||
{
|
||||
char *shader;
|
||||
char *target;
|
||||
int fd;
|
||||
size_t bytes_read;
|
||||
const char *target = "./assets/shaders/vert.glsl";
|
||||
char *shader;
|
||||
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);
|
||||
|
||||
@ -6,18 +6,18 @@
|
||||
/* 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 17:15:03 by qmennen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d.h"
|
||||
|
||||
t_sprite make_sprite(mlx_texture_t *texture, double x, double y, int collectible)
|
||||
t_sprite make_sprite(t_sprite_lib *def, double x, double y)
|
||||
{
|
||||
t_sprite sprite;
|
||||
|
||||
ft_memset(&sprite, 0, sizeof(t_sprite));
|
||||
sprite.texture = texture;
|
||||
sprite.texture = def->texture;
|
||||
// if (sprite.texture->width % 64 != 0)
|
||||
// {
|
||||
// ft_putstr_fd("Error: Texture width is not a multiple of 64\n", 2);
|
||||
@ -29,17 +29,17 @@ t_sprite make_sprite(mlx_texture_t *texture, double x, double y, int collectible
|
||||
// exit(EXIT_FAILURE);
|
||||
// }
|
||||
sprite.n_frames = sprite.texture->width / sprite.texture->height;
|
||||
sprite.animation_speed = 10;
|
||||
sprite.pos.x = x;
|
||||
sprite.pos.y = y;
|
||||
sprite.visible = 1;
|
||||
sprite.collectible = collectible;
|
||||
sprite.type = def->type;
|
||||
return (sprite);
|
||||
}
|
||||
|
||||
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);
|
||||
@ -54,9 +54,7 @@ static int init_temp(t_game **game)
|
||||
// sprites[7] = make_sprite("./assets/battery.png", 2.5, 7.5, 1);
|
||||
// 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;
|
||||
|
||||
// (*game)->map->n_sprites = 10;
|
||||
hud_texture = mlx_load_png("./assets/overlay2.png");
|
||||
(*game)->screen->hud = mlx_texture_to_image((*game)->screen->mlx,
|
||||
hud_texture);
|
||||
|
||||
@ -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]);
|
||||
}
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* score.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/05/25 20:54:23 by whaffman #+# #+# */
|
||||
/* Updated: 2025/05/25 21:00:49 by whaffman ######## odam.nl */
|
||||
/* ::: :::::::: */
|
||||
/* score.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/25 20:54:23 by whaffman #+# #+# */
|
||||
/* Updated: 2025/05/28 17:14:53 by qmennen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -40,10 +40,10 @@ int count_collected(t_game *game)
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
collected = 0;
|
||||
collected = 0;
|
||||
while (i < game->map->n_sprites)
|
||||
{
|
||||
if (game->map->sprites[i].collectible && !game->map->sprites[i].visible)
|
||||
if (game->map->sprites[i].type == SPRITE_TYPE_COLLECTED)
|
||||
collected++;
|
||||
i++;
|
||||
}
|
||||
@ -52,9 +52,9 @@ int count_collected(t_game *game)
|
||||
|
||||
void print_scores(t_game *game)
|
||||
{
|
||||
int empty;
|
||||
int visited;
|
||||
int collected;
|
||||
int empty;
|
||||
int visited;
|
||||
int collected;
|
||||
|
||||
empty = count_tiles(game->map, TILE_EMPTY);
|
||||
visited = count_tiles(game->map, TILE_VISITED);
|
||||
@ -62,4 +62,4 @@ void print_scores(t_game *game)
|
||||
printf("Score:\n");
|
||||
printf("Seen %d of %d tiles\n", visited, visited + empty);
|
||||
printf("Collected items: %d\n", collected);
|
||||
}
|
||||
}
|
||||
|
||||
3
test.cub
3
test.cub
@ -18,12 +18,13 @@ CT ./assets/ceiling64x64.png
|
||||
-s a ./assets/lamp.png
|
||||
-c b ./assets/accu.png
|
||||
-s p ./assets/plant.png
|
||||
-s g ./assets/mushroom.png
|
||||
-s m ./assets/broken_mirror.png
|
||||
-s t ./assets/test.png
|
||||
|
||||
1111111 111 1111 111111 1111111111 111111
|
||||
1000001110111001 100001 1000000001 10001
|
||||
10010000000b0001 100001 100000110111100011
|
||||
1001000g000b0001 100001 100000110111100011
|
||||
10b0001110000001110011111111 1100b0001000000001
|
||||
1000001 1000100a000010000001 10000000100b000001
|
||||
100m00111000100000b00000b00111110p00000100p00m001
|
||||
|
||||
Loading…
Reference in New Issue
Block a user