Compare commits
8 Commits
7d7de10b7a
...
master
Author | SHA1 | Date | |
---|---|---|---|
42a0cfd5b6 | |||
595d220abd | |||
9a6d7b6ed7 | |||
b1170d5b5f | |||
d4f3a72f76 | |||
a241d049c4 | |||
d6117cfb8f | |||
8b200fb8ba |
14
Makefile
14
Makefile
@ -1,3 +1,15 @@
|
|||||||
|
# **************************************************************************** #
|
||||||
|
# #
|
||||||
|
# ::: :::::::: #
|
||||||
|
# Makefile :+: :+: :+: #
|
||||||
|
# +:+ +:+ +:+ #
|
||||||
|
# By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ #
|
||||||
|
# +#+#+#+#+#+ +#+ #
|
||||||
|
# Created: 2023/01/20 14:41:36 by cchauvet #+# #+# #
|
||||||
|
# Updated: 2023/01/20 14:41:42 by cchauvet ### ########.fr #
|
||||||
|
# #
|
||||||
|
# **************************************************************************** #
|
||||||
|
|
||||||
SRCS = mandatory/asset.c mandatory/draw.c mandatory/key.c mandatory/main.c mandatory/map.c mandatory/parsing2.c mandatory/parsing.c mandatory/xpm.c
|
SRCS = mandatory/asset.c mandatory/draw.c mandatory/key.c mandatory/main.c mandatory/map.c mandatory/parsing2.c mandatory/parsing.c mandatory/xpm.c
|
||||||
|
|
||||||
BSRCS = bonus/asset.c bonus/draw.c bonus/key.c bonus/main.c bonus/map.c bonus/parsing2.c bonus/parsing.c bonus/xpm.c
|
BSRCS = bonus/asset.c bonus/draw.c bonus/key.c bonus/main.c bonus/map.c bonus/parsing2.c bonus/parsing.c bonus/xpm.c
|
||||||
@ -12,7 +24,7 @@ LIBS = libftx/libftx.a minilibx-linux/libmlx.a
|
|||||||
|
|
||||||
CC = clang
|
CC = clang
|
||||||
|
|
||||||
FLAG = -Wall -Wextra -Werror -g
|
FLAG = -Wall -Wextra -Werror
|
||||||
|
|
||||||
%.o: %.c
|
%.o: %.c
|
||||||
${CC} ${FLAG} -c $< -o $@
|
${CC} ${FLAG} -c $< -o $@
|
||||||
|
53
README.md
Normal file
53
README.md
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
# Solong
|
||||||
|
|
||||||
|
This is my implementation of the Solong project for the 42 school.
|
||||||
|
## Description
|
||||||
|
|
||||||
|
Solong is a simple 2D game where the player has to collect all the items in a maze and reach the exit. The game is written in C using the minilibx library for the graphics.
|
||||||
|
|
||||||
|
The project is composed of three parts:
|
||||||
|
|
||||||
|
- The parsing of the map file in a format specified by the subject.
|
||||||
|
- The rendering of the game using the graphics library.
|
||||||
|
- The game loop and the handling of user input.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
To install this project clone this repo
|
||||||
|
``` bash
|
||||||
|
git clone https://git.chauvet.pro/starnakin/solong
|
||||||
|
```
|
||||||
|
### Mandatory
|
||||||
|
To compile the game, simply run make in the root directory of the project. This will generate an executable called solong.
|
||||||
|
``` bash
|
||||||
|
make
|
||||||
|
```
|
||||||
|
### Bonus
|
||||||
|
To compile the game, simply run make bonus in the root directory of the project. This will generate an executable called solong.
|
||||||
|
``` bash
|
||||||
|
make bonus
|
||||||
|
```
|
||||||
|
## Launch
|
||||||
|
|
||||||
|
To run the game, you need to provide a valid map file as an argument. For example:
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
./solong maps/map.ber
|
||||||
|
```
|
||||||
|
The game requires the minilibx library to be installed on your system. If you're using macOS, the library should be already installed. If you're using Linux, you may need to install it manually.
|
||||||
|
## Controls
|
||||||
|
|
||||||
|
The player can be moved using the arrow keys or the WASD keys. Pressing the ESC key or closing the window will exit the game.
|
||||||
|
## Screenshots
|
||||||
|
|
||||||
|
Here are some screenshots of the game:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Resources
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
## Author
|
||||||
|
|
||||||
|
This project was created by Camille Chauvet. If you have any questions or suggestions, feel free to contact me.
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/01/06 14:23:00 by cchauvet #+# #+# */
|
/* Created: 2023/01/06 14:23:00 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/01/13 16:03:54 by cchauvet ### ########.fr */
|
/* Updated: 2023/01/19 13:32:14 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -30,12 +30,35 @@ static void *ft_gen_asset(char *color, size_t case_size, t_data *data)
|
|||||||
return (img);
|
return (img);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char **ft_color_gen(void)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
char **tab;
|
||||||
|
|
||||||
|
tab = ft_calloc(NB_COLORS + 1, sizeof(char *));
|
||||||
|
if (tab == NULL)
|
||||||
|
return (NULL);
|
||||||
|
i = 0;
|
||||||
|
while (i < NB_COLORS)
|
||||||
|
{
|
||||||
|
tab[i] = ft_ultoa_base(((1 << 23) * i) / NB_COLORS, HEX);
|
||||||
|
if (tab[i] == NULL)
|
||||||
|
{
|
||||||
|
ft_cancel(tab, i);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
tab[i] = NULL;
|
||||||
|
return (tab);
|
||||||
|
}
|
||||||
|
|
||||||
int ft_gen_assets(t_data *data)
|
int ft_gen_assets(t_data *data)
|
||||||
{
|
{
|
||||||
char **colors;
|
char **colors;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
colors = ft_split(COLORS, '|');
|
colors = ft_color_gen();
|
||||||
if (colors == NULL)
|
if (colors == NULL)
|
||||||
return (1);
|
return (1);
|
||||||
i = 0;
|
i = 0;
|
||||||
@ -43,9 +66,14 @@ int ft_gen_assets(t_data *data)
|
|||||||
{
|
{
|
||||||
data->assets[i] = ft_gen_asset(colors[i], CASE_SIZE, data);
|
data->assets[i] = ft_gen_asset(colors[i], CASE_SIZE, data);
|
||||||
if (data->assets[i] == NULL)
|
if (data->assets[i] == NULL)
|
||||||
|
{
|
||||||
|
ft_freer_tab_ultimate(1, colors);
|
||||||
return (1);
|
return (1);
|
||||||
|
}
|
||||||
data->assets[i + NB_COLORS] = ft_gen_asset(colors[i],
|
data->assets[i + NB_COLORS] = ft_gen_asset(colors[i],
|
||||||
WINDOW_SIZE, data);
|
(RENDER_DISTANCE * 2 + 1) * CASE_SIZE, data);
|
||||||
|
if (data->assets[i + NB_COLORS] == NULL)
|
||||||
|
ft_freer_tab_ultimate(1, colors);
|
||||||
if (data->assets[i + NB_COLORS] == NULL)
|
if (data->assets[i + NB_COLORS] == NULL)
|
||||||
return (1);
|
return (1);
|
||||||
i++;
|
i++;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/12/13 15:49:23 by cchauvet #+# #+# */
|
/* Created: 2022/12/13 15:49:23 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/01/16 18:46:55 by cchauvet ### ########.fr */
|
/* Updated: 2023/01/19 15:20:56 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -56,11 +56,12 @@ int ft_draw_map(t_data *data)
|
|||||||
void *img;
|
void *img;
|
||||||
|
|
||||||
ft_fill_pos(data->map);
|
ft_fill_pos(data->map);
|
||||||
data->nb_swaps = ++data->nb_swaps % NB_COLORS;
|
data->nb_swaps = ft_random_generator(0, NB_COLORS - 6);
|
||||||
patern = ft_get_player_map(*data->map);
|
patern = ft_get_player_map(*data->map);
|
||||||
if (patern == NULL)
|
if (patern == NULL)
|
||||||
return (1);
|
return (1);
|
||||||
ft_draw_img(data, data->assets[data->nb_swaps + NB_COLORS], 0, 0);
|
ft_draw_img(data, data->assets[data->nb_swaps % NB_COLORS + NB_COLORS], 0,
|
||||||
|
0);
|
||||||
tab[1] = -1;
|
tab[1] = -1;
|
||||||
while (patern[++tab[1]] != NULL)
|
while (patern[++tab[1]] != NULL)
|
||||||
{
|
{
|
||||||
|
11
bonus/main.c
11
bonus/main.c
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/12/12 17:20:17 by cchauvet #+# #+# */
|
/* Created: 2022/12/12 17:20:17 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/01/16 18:47:20 by cchauvet ### ########.fr */
|
/* Updated: 2023/01/19 16:54:42 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -24,12 +24,15 @@ int ft_initialised(char *path, t_data *data)
|
|||||||
}
|
}
|
||||||
data->mlx = mlx_init();
|
data->mlx = mlx_init();
|
||||||
ft_printf("Generating assets ...");
|
ft_printf("Generating assets ...");
|
||||||
ft_gen_assets(data);
|
if (ft_gen_assets(data))
|
||||||
|
ft_exit(data);
|
||||||
ft_printf("\rGenerating assets [FINISHED]\n");
|
ft_printf("\rGenerating assets [FINISHED]\n");
|
||||||
data->map = map;
|
data->map = map;
|
||||||
data->window = mlx_new_window(data->mlx, WINDOW_SIZE, WINDOW_SIZE, "long");
|
data->window = mlx_new_window(data->mlx,
|
||||||
|
(RENDER_DISTANCE * 2 + 1) * CASE_SIZE,
|
||||||
|
(RENDER_DISTANCE * 2 + 1) * CASE_SIZE, "long");
|
||||||
data->nb_foots = 0;
|
data->nb_foots = 0;
|
||||||
data->nb_swaps = ft_random_generator(0, NB_COLORS);
|
data->nb_swaps = ft_random_generator(0, NB_COLORS - 6);
|
||||||
ft_draw_map(data);
|
ft_draw_map(data);
|
||||||
mlx_hook(data->window, 17, (0L), ft_exit, data);
|
mlx_hook(data->window, 17, (0L), ft_exit, data);
|
||||||
mlx_hook(data->window, 2, (1L << 0), ft_key, data);
|
mlx_hook(data->window, 2, (1L << 0), ft_key, data);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/01/04 16:20:03 by cchauvet #+# #+# */
|
/* Created: 2023/01/04 16:20:03 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/01/16 18:47:59 by cchauvet ### ########.fr */
|
/* Updated: 2023/01/19 13:40:52 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -17,20 +17,19 @@
|
|||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include <fcntl.h>
|
# include <fcntl.h>
|
||||||
# include "../minilibx-linux/mlx.h"
|
# include "../minilibx-linux/mlx.h"
|
||||||
# define CASE_SIZE 64
|
# define CASE_SIZE 128
|
||||||
# define XPM_HEADER "\nstatic char * XFACE[] = {\""
|
# define XPM_HEADER "\nstatic char * XFACE[] = {\""
|
||||||
# define COLORS "silver|gray|white|maroon|red|purple|fuchsia|green|lime|olive|yellow|navy|blue|teal|aqua|aliceblue|antiquewhite|aqua|aquamarine|azure|beige|bisque|black|blanchedalmond|blue|blueviolet|brown|burlywood|cadetblue|chartreuse|chocolate|coral|cornflowerblue|cornsilk|crimson|cyan|darkblue|darkcyan|darkgoldenrod|darkgray|darkgreen|darkgrey|darkkhaki|darkmagenta|darkolivegreen|darkorange|darkorchid|darkred|darksalmon|darkseagreen|darkslateblue|darkslategray|darkslategrey|darkturquoise|darkviolet|deeppink|deepskyblue|dimgray|dimgrey|dodgerblue|firebrick|floralwhite|forestgreen|fuchsia|gainsboro|ghostwhite|gold|goldenrod|gray|green|greenyellow|grey|honeydew|hotpink|indianred|indigo|ivory|khaki|lavender|lavenderblush|lawngreen|lemonchiffon|lightblue|lightcoral|lightcyan|lightgoldenrodyellow|lightgray|lightgreen|lightgrey|lightpink|lightsalmon|lightseagreen|lightskyblue|lightslategray|lightslategrey|lightsteelblue|lightyellow|lime|limegreen|linen|magenta|maroon|mediumaquamarine|mediumblue|mediumorchid|mediumpurple|mediumseagreen|mediumslateblue|mediumspringgreen|mediumturquoise|mediumvioletred|midnightblue|mintcream|mistyrose|moccasin|navajowhite|navy|oldlace|olive|olivedrab|orange|orangered|orchid|palegoldenrod|palegreen|paleturquoise|palevioletred|papayawhip|peachpuff|peru|pink|plum|powderblue|purple|red|rosybrown|royalblue|saddlebrown|salmon|sandybrown|seagreen|seashell|sienna|silver|skyblue|slateblue|slategray|slategrey|snow|springgreen|steelblue|tan|teal|thistle|tomato|turquoise|violet|wheat|white|whitesmoke|yellow|yellowgreen"
|
# define RENDER_DISTANCE 4
|
||||||
# define NB_COLORS 93
|
# define NB_COLORS 100
|
||||||
# define RENDER_DISTANCE 5
|
# define HEX "0123456789abcdef"
|
||||||
# define WINDOW_SIZE (RENDER_DISTANCE * 2 + 1) * CASE_SIZE
|
|
||||||
|
|
||||||
typedef struct s_square
|
typedef struct s_square
|
||||||
{
|
{
|
||||||
char *color;
|
char *color;
|
||||||
size_t size;
|
size_t size;
|
||||||
} t_square;
|
} t_square;
|
||||||
|
|
||||||
typedef struct s_map
|
typedef struct s_map
|
||||||
{
|
{
|
||||||
size_t x_len;
|
size_t x_len;
|
||||||
size_t y_len;
|
size_t y_len;
|
||||||
@ -38,9 +37,9 @@ typedef struct s_map
|
|||||||
char **patern;
|
char **patern;
|
||||||
size_t player_pos[2];
|
size_t player_pos[2];
|
||||||
size_t exit_pos[2];
|
size_t exit_pos[2];
|
||||||
} t_map;
|
} t_map;
|
||||||
|
|
||||||
typedef struct s_data
|
typedef struct s_data
|
||||||
{
|
{
|
||||||
void *mlx;
|
void *mlx;
|
||||||
void *window;
|
void *window;
|
||||||
@ -48,7 +47,7 @@ typedef struct s_data
|
|||||||
t_map *map;
|
t_map *map;
|
||||||
size_t nb_swaps;
|
size_t nb_swaps;
|
||||||
size_t nb_foots;
|
size_t nb_foots;
|
||||||
} t_data;
|
} t_data;
|
||||||
|
|
||||||
int ft_test_map_is_finishable(t_map *map);
|
int ft_test_map_is_finishable(t_map *map);
|
||||||
int ft_exit(t_data *data);
|
int ft_exit(t_data *data);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/01/04 13:53:03 by cchauvet #+# #+# */
|
/* Created: 2023/01/04 13:53:03 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/01/11 16:53:45 by cchauvet ### ########.fr */
|
/* Updated: 2023/01/19 12:34:40 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ static char *ft_gen_xpm_content(t_square square)
|
|||||||
free(temp);
|
free(temp);
|
||||||
if (content == NULL)
|
if (content == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
temp = ft_strmerger(5, "/* XPM */", content, "a c ", square.color, "\",\n");
|
temp = ft_strmerger(5, "/* XPM */", content, "a c #", square.color, "\",\n");
|
||||||
free(content);
|
free(content);
|
||||||
if (temp == NULL)
|
if (temp == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
@ -6,13 +6,13 @@
|
|||||||
# By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ #
|
# By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2022/09/27 08:39:27 by cchauvet #+# #+# #
|
# Created: 2022/09/27 08:39:27 by cchauvet #+# #+# #
|
||||||
# Updated: 2023/01/12 16:31:55 by cchauvet ### ########.fr #
|
# Updated: 2023/01/19 12:55:43 by cchauvet ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
CC = clang
|
CC = clang
|
||||||
|
|
||||||
SRCS = ft_contain_only.c ft_freer.c ft_is_in.c ft_random_generator.c ft_strchri.c ft_strcmp.c ft_strfjoin.c ft_strgen.c ft_strmerger.c ft_strndup.c ft_tabrealloc.c
|
SRCS = ft_contain_only.c ft_freer.c ft_is_in.c ft_random_generator.c ft_strchri.c ft_strcmp.c ft_strfjoin.c ft_strgen.c ft_strmerger.c ft_strndup.c ft_tabrealloc.c ft_ultoa_base.c
|
||||||
|
|
||||||
OBJS = $(SRCS:.c=.o)
|
OBJS = $(SRCS:.c=.o)
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/01/04 14:03:10 by cchauvet #+# #+# */
|
/* Created: 2023/01/04 14:03:10 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/01/12 16:32:35 by cchauvet ### ########.fr */
|
/* Updated: 2023/01/19 17:37:25 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -18,6 +18,7 @@
|
|||||||
# include <fcntl.h>
|
# include <fcntl.h>
|
||||||
# include "../libft/libft.h"
|
# include "../libft/libft.h"
|
||||||
|
|
||||||
|
char *ft_ultoa_base(unsigned long long n, char *base);
|
||||||
char *get_next_line(int fd);
|
char *get_next_line(int fd);
|
||||||
size_t ft_random_generator(size_t start, size_t stop);
|
size_t ft_random_generator(size_t start, size_t stop);
|
||||||
void ft_freer_tab_ultimate(size_t len, ...);
|
void ft_freer_tab_ultimate(size_t len, ...);
|
||||||
|
0
libftx/extra/ft_tabrealloc-5f29f43f.o.tmp
Normal file
0
libftx/extra/ft_tabrealloc-5f29f43f.o.tmp
Normal file
BIN
libftx/extra/ft_ultoa.o
Normal file
BIN
libftx/extra/ft_ultoa.o
Normal file
Binary file not shown.
89
libftx/extra/ft_ultoa_base.c
Normal file
89
libftx/extra/ft_ultoa_base.c
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_ultoa_base.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/09/29 13:49:45 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/01/19 13:01:09 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "extra.h"
|
||||||
|
|
||||||
|
static size_t ft_str_size(unsigned long long n, size_t base_size)
|
||||||
|
{
|
||||||
|
size_t size;
|
||||||
|
|
||||||
|
size = 1;
|
||||||
|
if (n == 0)
|
||||||
|
return (2);
|
||||||
|
while (n != 0)
|
||||||
|
{
|
||||||
|
n = n / base_size;
|
||||||
|
size++;
|
||||||
|
}
|
||||||
|
return (size);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ft_isdup(char *str)
|
||||||
|
{
|
||||||
|
char c;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
while (*str != 0)
|
||||||
|
{
|
||||||
|
c = *str;
|
||||||
|
i = 1;
|
||||||
|
while (str[i] != 0)
|
||||||
|
{
|
||||||
|
if (str[i] == c)
|
||||||
|
return (1);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
str++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static size_t ft_base_size(char *base)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
if (ft_isdup(base))
|
||||||
|
return (0);
|
||||||
|
len = ft_strlen(base);
|
||||||
|
if (len < 2)
|
||||||
|
return (0);
|
||||||
|
return (len);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *ft_ultoa_base(unsigned long long n, char *base)
|
||||||
|
{
|
||||||
|
size_t base_size;
|
||||||
|
int str_size;
|
||||||
|
char *out;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if (base == NULL)
|
||||||
|
return (NULL);
|
||||||
|
base_size = ft_base_size(base);
|
||||||
|
if (base_size == 0)
|
||||||
|
return (NULL);
|
||||||
|
str_size = ft_str_size(n, base_size);
|
||||||
|
out = ft_calloc(str_size + 1, sizeof(char));
|
||||||
|
if (out == NULL)
|
||||||
|
return (NULL);
|
||||||
|
i = 0;
|
||||||
|
if (n == 0)
|
||||||
|
out[0] = base[0];
|
||||||
|
while (n != 0)
|
||||||
|
{
|
||||||
|
out[str_size - 2 - i] = base[n % base_size];
|
||||||
|
n /= base_size;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
out[str_size - 1] = '\0';
|
||||||
|
return (out);
|
||||||
|
}
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/09/26 14:47:54 by cchauvet #+# #+# */
|
/* Created: 2022/09/26 14:47:54 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/01/12 16:33:45 by cchauvet ### ########.fr */
|
/* Updated: 2023/01/18 19:21:40 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -16,6 +16,7 @@
|
|||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include <stdarg.h>
|
# include <stdarg.h>
|
||||||
|
|
||||||
|
char *ft_ultoa_base(unsigned long long n, char *base);
|
||||||
int ft_printf(const char *format, ...);
|
int ft_printf(const char *format, ...);
|
||||||
char *get_next_line(int fd);
|
char *get_next_line(int fd);
|
||||||
size_t ft_random_generator(size_t start, size_t stop);
|
size_t ft_random_generator(size_t start, size_t stop);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/01/06 14:23:00 by cchauvet #+# #+# */
|
/* Created: 2023/01/06 14:23:00 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/01/16 18:27:18 by cchauvet ### ########.fr */
|
/* Updated: 2023/01/18 17:32:05 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ int ft_gen_assets(t_data *data)
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
data->assets[NB_COLORS] = ft_gen_asset(colors[i],
|
data->assets[NB_COLORS] = ft_gen_asset(colors[i],
|
||||||
WINDOW_SIZE, data);
|
(RENDER_DISTANCE * 2 + 1) * CASE_SIZE, data);
|
||||||
if (data->assets[NB_COLORS] == NULL)
|
if (data->assets[NB_COLORS] == NULL)
|
||||||
return (1);
|
return (1);
|
||||||
ft_freer_tab_ultimate(1, colors);
|
ft_freer_tab_ultimate(1, colors);
|
||||||
|
@ -12,10 +12,11 @@
|
|||||||
|
|
||||||
#include "solong.h"
|
#include "solong.h"
|
||||||
|
|
||||||
static void ft_case_update(char *new_pos, char *player_pos)
|
static void ft_case_update(t_data *data, char *new_pos, char *player_pos)
|
||||||
{
|
{
|
||||||
*new_pos = 'P';
|
*new_pos = 'P';
|
||||||
*player_pos = '0';
|
*player_pos = '0';
|
||||||
|
ft_printf("\r%d", ++data->nb_foots);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ft_move(t_data *data, char direction)
|
static void ft_move(t_data *data, char direction)
|
||||||
@ -36,7 +37,8 @@ static void ft_move(t_data *data, char direction)
|
|||||||
if (*new_pos == 'C')
|
if (*new_pos == 'C')
|
||||||
data->map->nb_collectable--;
|
data->map->nb_collectable--;
|
||||||
if (*new_pos == '0' || *new_pos == 'C')
|
if (*new_pos == '0' || *new_pos == 'C')
|
||||||
ft_case_update(new_pos, &data->map->patern[tab[1]][tab[0]]);
|
ft_case_update(data, new_pos,
|
||||||
|
&data->map->patern[tab[1]][tab[0]]);
|
||||||
if (*new_pos == 'E')
|
if (*new_pos == 'E')
|
||||||
{
|
{
|
||||||
if (data->map->nb_collectable == 0)
|
if (data->map->nb_collectable == 0)
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/12/12 17:20:17 by cchauvet #+# #+# */
|
/* Created: 2022/12/12 17:20:17 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/01/16 18:23:34 by cchauvet ### ########.fr */
|
/* Updated: 2023/01/18 17:31:16 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -31,7 +31,9 @@ int ft_initialised(char *path, t_data *data)
|
|||||||
}
|
}
|
||||||
ft_printf("\rGenerating assets [FINISHED]\n");
|
ft_printf("\rGenerating assets [FINISHED]\n");
|
||||||
data->map = map;
|
data->map = map;
|
||||||
data->window = mlx_new_window(data->mlx, WINDOW_SIZE, WINDOW_SIZE, "long");
|
data->window = mlx_new_window(data->mlx,
|
||||||
|
(RENDER_DISTANCE * 2 + 1) * CASE_SIZE,
|
||||||
|
(RENDER_DISTANCE * 2 + 1) * CASE_SIZE, "long");
|
||||||
ft_draw_map(data);
|
ft_draw_map(data);
|
||||||
mlx_hook(data->window, 17, (0L), ft_exit, data);
|
mlx_hook(data->window, 17, (0L), ft_exit, data);
|
||||||
mlx_hook(data->window, 2, (1L << 0), ft_key, data);
|
mlx_hook(data->window, 2, (1L << 0), ft_key, data);
|
||||||
@ -74,6 +76,7 @@ int main(int ac, char **av)
|
|||||||
}
|
}
|
||||||
data.map = NULL;
|
data.map = NULL;
|
||||||
data.window = NULL;
|
data.window = NULL;
|
||||||
|
data.nb_foots = 0;
|
||||||
if (ft_initialised(av[1], &data))
|
if (ft_initialised(av[1], &data))
|
||||||
ft_printf("Memory error");
|
ft_printf("Memory error");
|
||||||
return (1);
|
return (1);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/01/04 16:20:03 by cchauvet #+# #+# */
|
/* Created: 2023/01/04 16:20:03 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/01/16 18:36:30 by cchauvet ### ########.fr */
|
/* Updated: 2023/01/18 17:29:43 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -22,15 +22,14 @@
|
|||||||
# define COLORS "gold|white|pink|red|gray"
|
# define COLORS "gold|white|pink|red|gray"
|
||||||
# define NB_COLORS 4
|
# define NB_COLORS 4
|
||||||
# define RENDER_DISTANCE 5
|
# define RENDER_DISTANCE 5
|
||||||
# define WINDOW_SIZE (RENDER_DISTANCE * 2 + 1) * CASE_SIZE
|
|
||||||
|
|
||||||
typedef struct s_square
|
typedef struct s_square
|
||||||
{
|
{
|
||||||
char *color;
|
char *color;
|
||||||
size_t size;
|
size_t size;
|
||||||
} t_square;
|
} t_square;
|
||||||
|
|
||||||
typedef struct s_map
|
typedef struct s_map
|
||||||
{
|
{
|
||||||
size_t x_len;
|
size_t x_len;
|
||||||
size_t y_len;
|
size_t y_len;
|
||||||
@ -38,17 +37,17 @@ typedef struct s_map
|
|||||||
char **patern;
|
char **patern;
|
||||||
size_t player_pos[2];
|
size_t player_pos[2];
|
||||||
size_t exit_pos[2];
|
size_t exit_pos[2];
|
||||||
} t_map;
|
} t_map;
|
||||||
|
|
||||||
typedef struct s_data
|
typedef struct s_data
|
||||||
{
|
{
|
||||||
void *mlx;
|
void *mlx;
|
||||||
void *window;
|
void *window;
|
||||||
void *assets[NB_COLORS + 1];
|
void *assets[NB_COLORS + 1];
|
||||||
|
size_t nb_foots;
|
||||||
t_map *map;
|
t_map *map;
|
||||||
} t_data;
|
} t_data;
|
||||||
|
|
||||||
//void ft_ultimate_image_destroyer(t_data *data);
|
|
||||||
int ft_test_map_is_finishable(t_map *map);
|
int ft_test_map_is_finishable(t_map *map);
|
||||||
int ft_exit(t_data *data);
|
int ft_exit(t_data *data);
|
||||||
int ft_test_map_content2(char **patern);
|
int ft_test_map_content2(char **patern);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
1111111111111
|
1111111111111
|
||||||
10010000000C1
|
10010000000C1
|
||||||
1000011111001
|
1000011111B01
|
||||||
1P0011E0000C1
|
1P0011E0000C1
|
||||||
1111111111111
|
1111111111111
|
||||||
|
BIN
subject.pdf
Normal file
BIN
subject.pdf
Normal file
Binary file not shown.
Reference in New Issue
Block a user