-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d3bba61
Showing
128 changed files
with
12,282 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# **************************************************************************** # | ||
# # | ||
# ::: :::::::: # | ||
# Makefile :+: :+: :+: # | ||
# +:+ +:+ +:+ # | ||
# By: jbadaire <[email protected]> +#+ +:+ +#+ # | ||
# +#+#+#+#+#+ +#+ # | ||
# Created: 2023/01/17 17:54:42 by jbadaire #+# #+# # | ||
# Updated: 2023/01/17 17:54:46 by jbadaire ### ########lyon.fr # | ||
# # | ||
# **************************************************************************** # | ||
|
||
NAME = so_long.out | ||
MAKE_LIBFT = make -C libft | ||
|
||
MLX = minilibx-linux/libmlx_Linux.a | ||
MAKE_MLX = make -C minilibx-linux | ||
|
||
MLX_FLAGS = -L./minilibx-linux -l:libmlx.a -L/usr/lib -Imlx_linux -lXext -lX11 -lm -lz | ||
|
||
SRCS = main.c \ | ||
collectible_utils.c \ | ||
frees.c \ | ||
maps_utils.c \ | ||
player.c \ | ||
rectangle_check.c \ | ||
utils.c \ | ||
graphics_utils.c | ||
|
||
LIBFT_FLAGS = -L./libft -l:libft.a | ||
OBJ_DIRECTORY = ./.obj/ | ||
|
||
|
||
CC = cc | ||
|
||
FLAGS = -c -Wall -Wextra -Werror | ||
|
||
INCLUDES = ./headers/so_long.h | ||
|
||
OBJS = $(addprefix $(OBJ_DIRECTORY), $(SRCS:.c=.o)) | ||
|
||
$(NAME): $(OBJ_DIRECTORY) $(OBJS) | ||
$(MAKE_MLX) | ||
$(MAKE_LIBFT) | ||
$(CC) $(OBJS) $(LIBFT_FLAGS) $(MLX_FLAGS) -o $(NAME) | ||
|
||
$(OBJ_DIRECTORY)%.o: %.c | ||
mkdir -p minilibx-linux | ||
$(CC) $(FLAGS) $< -o $@ | ||
|
||
$(OBJ_DIRECTORY): | ||
mkdir -p $(OBJ_DIRECTORY) | ||
|
||
all : $(NAME) | ||
|
||
clean : | ||
$(RM) $(NAME) | ||
rm -rf $(OBJ_DIRECTORY) | ||
|
||
fclean : clean | ||
rm -rf $(NAME) | ||
|
||
re : fclean all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* collectible_utils.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: jbadaire <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/10/03 03:24:55 by jbadaire #+# #+# */ | ||
/* Updated: 2023/10/03 03:47:04 by jbadaire ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "so_long.h" | ||
|
||
t_list *load_collectibles(t_data data) { | ||
size_t pos_x; | ||
size_t pos_y; | ||
t_list *list; | ||
t_collectible *collectible; | ||
|
||
pos_x = 0; | ||
pos_y = 0; | ||
list = malloc(sizeof (t_list)); | ||
if(!list) | ||
return (NULL); | ||
|
||
while (pos_y < data.lenght_y) { | ||
while (pos_x < ft_strlen(data.map[0])) { | ||
if (data.map[pos_y][pos_x] == 'C') { | ||
t_location location; | ||
location.x = ++pos_x; | ||
location.y = ++pos_y; | ||
collectible = create_collectible(location); | ||
if(!collectible) | ||
return (NULL); | ||
ft_lstadd_front(&list, ft_lstnew(collectible)); | ||
} | ||
pos_x++; | ||
} | ||
pos_x = 0; | ||
pos_y++; | ||
} | ||
return (list); | ||
|
||
} | ||
|
||
|
||
t_collectible *create_collectible(t_location location) | ||
{ | ||
t_collectible *collectible; | ||
|
||
collectible = malloc(sizeof(t_collectible *)); | ||
if(!collectible) | ||
return (NULL); | ||
collectible->location.x = location.x; | ||
collectible->location.y = location.y; | ||
collectible->collected = _false; | ||
return (collectible); | ||
} | ||
|
||
int count_collectibles(t_list *collectibles, t_boolean only_uncollected) | ||
{ | ||
t_list *collectibles_copy; | ||
t_collectible *col; | ||
int count; | ||
|
||
collectibles_copy = collectibles; | ||
count = 0; | ||
col = NULL; | ||
while (collectibles_copy->next != NULL) { | ||
collectibles_copy = collectibles_copy->next; | ||
|
||
if(only_uncollected) { | ||
col = ((t_collectible*) collectibles_copy->content); | ||
if(!col->collected) | ||
{ | ||
count++; | ||
continue; | ||
} | ||
} | ||
count++; | ||
} | ||
return (count); | ||
} | ||
|
||
void update_collectible(t_list **collectibles, t_location location, t_boolean collected) | ||
{ | ||
t_list *collectibles_copy; | ||
t_collectible *collectible; | ||
|
||
collectibles_copy = *collectibles; | ||
while (collectibles_copy->next) | ||
{ | ||
collectible = ((t_collectible*) collectibles_copy->content); | ||
if(collectible->location.x == location.x && collectible->location.y == location.y) { | ||
collectible->collected = collected; | ||
break; | ||
} | ||
collectibles_copy = collectibles_copy->next; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* frees.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: jbadaire <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/10/03 10:21:10 by jbadaire #+# #+# */ | ||
/* Updated: 2023/10/03 10:54:19 by jbadaire ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "so_long.h" | ||
|
||
void free_map(t_data data) { | ||
size_t lenght_y; | ||
|
||
lenght_y = 0; | ||
while (data.lenght_y < lenght_y) { | ||
free(data.map[lenght_y]); | ||
lenght_y++; | ||
} | ||
free(data.map); | ||
} | ||
|
||
void free_collectibles(t_list **collectibles) { | ||
|
||
t_list *list; | ||
t_list *copy; | ||
|
||
list = *collectibles; | ||
copy = list; | ||
while (copy->next) | ||
{ | ||
if(copy->next == NULL) { | ||
free(list->content); | ||
copy = list; | ||
} | ||
copy = copy->next; | ||
|
||
} | ||
free(list->content); | ||
free(list); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* graphics_utils.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: jbadaire <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/10/03 12:56:12 by jbadaire #+# #+# */ | ||
/* Updated: 2023/10/03 15:33:57 by jbadaire ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "so_long.h" | ||
#include "minilibx-linux/mlx.h" | ||
|
||
void *load_texture(char *path, void *mlx) { | ||
|
||
void *img; | ||
char *relative_path = path; | ||
int img_width; | ||
int img_height; | ||
|
||
img = mlx_xpm_file_to_image(mlx, relative_path, &img_width, &img_height); | ||
return (img); | ||
} | ||
|
||
void draw_type(void *mlx, void *mlx_window, void *texture, t_data data, char c) | ||
{ | ||
size_t index_y; | ||
size_t index_x; | ||
|
||
index_y = 0; | ||
index_x = 0; | ||
while (index_y < data.lenght_y) { | ||
while (index_x < ft_strlen(data.map[index_y])) { | ||
if (data.map[index_y][index_x] == c) | ||
mlx_put_image_to_window(mlx, mlx_window, texture, index_x * 128, index_y * 128); | ||
index_x++; | ||
} | ||
index_x=0; | ||
index_y++; | ||
} | ||
} | ||
|
||
void destroy_texture() { | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# **************************************************************************** # | ||
# # | ||
# ::: :::::::: # | ||
# Makefile :+: :+: :+: # | ||
# +:+ +:+ +:+ # | ||
# By: jbadaire <[email protected]> +#+ +:+ +#+ # | ||
# +#+#+#+#+#+ +#+ # | ||
# Created: 2023/01/17 17:54:42 by jbadaire #+# #+# # | ||
# Updated: 2023/01/17 17:54:46 by jbadaire ### ########lyon.fr # | ||
# # | ||
# **************************************************************************** # | ||
|
||
NAME = libft.a | ||
RM = rm -rf | ||
CC = cc | ||
FLAGS = -Wall -Wextra -Werror -g | ||
OBJ_DIRECTORY = ./.obj/ | ||
INCLUDE = libft.h | ||
|
||
SRCS = \ | ||
ft_bzero.c \ | ||
ft_isalnum.c \ | ||
ft_isalpha.c \ | ||
ft_isascii.c \ | ||
ft_isdigit.c \ | ||
ft_isprint.c \ | ||
ft_memset.c \ | ||
ft_strlen.c \ | ||
ft_strlcat.c \ | ||
ft_tolower.c \ | ||
ft_toupper.c \ | ||
ft_strrchr.c \ | ||
ft_strchr.c \ | ||
ft_strncmp.c \ | ||
ft_memchr.c \ | ||
ft_memcmp.c \ | ||
ft_strnstr.c \ | ||
ft_atoi.c \ | ||
ft_calloc.c \ | ||
ft_strdup.c \ | ||
ft_memcpy.c \ | ||
ft_memmove.c \ | ||
ft_strlcpy.c \ | ||
ft_substr.c \ | ||
ft_strjoin.c \ | ||
ft_strtrim.c \ | ||
ft_split.c \ | ||
ft_itoa.c \ | ||
ft_putchar_fd.c\ | ||
ft_putstr_fd.c \ | ||
ft_putendl_fd.c\ | ||
ft_striteri.c\ | ||
ft_strmapi.c\ | ||
ft_putnbr_fd.c \ | ||
ft_lstnew.c \ | ||
ft_lstadd_front.c\ | ||
ft_lstsize.c \ | ||
ft_lstlast.c \ | ||
ft_lstadd_back.c \ | ||
ft_lstdelone.c \ | ||
ft_lstclear.c \ | ||
ft_lstiter.c \ | ||
get_next_line.c \ | ||
get_next_line_utils.c \ | ||
|
||
all: $(NAME) | ||
|
||
so: $(all) | ||
|
||
OBJS = $(addprefix $(OBJ_DIRECTORY), $(SRCS:.c=.o)) | ||
|
||
$(NAME): $(OBJ_DIRECTORY) $(OBJS) $(INCLUDE) | ||
ar -rcs $(NAME) $(OBJS) | ||
|
||
$(OBJ_DIRECTORY)%.o:%.c $(INCLUDE) | ||
$(CC) $(FLAGS) -I. -c $< -o $@ | ||
|
||
$(OBJ_DIRECTORY): | ||
mkdir -p $(OBJ_DIRECTORY) | ||
|
||
clean: | ||
$(RM) $(OBJ_DIRECTORY) | ||
|
||
fclean: clean | ||
$(RM) $(NAME) *.out *.gch *.o .so | ||
|
||
re: fclean $(NAME) | ||
|
||
.PHONY: fclean clean all re |
Oops, something went wrong.