Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
vSKAH committed Oct 5, 2023
1 parent d3bba61 commit 17eba2d
Show file tree
Hide file tree
Showing 13 changed files with 376 additions and 217 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ SRCS = main.c \
player.c \
rectangle_check.c \
utils.c \
graphics_utils.c
graphics_utils.c \
location_utils.c

LIBFT_FLAGS = -L./libft -l:libft.a
OBJ_DIRECTORY = ./.obj/


CC = cc

FLAGS = -c -Wall -Wextra -Werror
FLAGS = -c -Wall -Wextra -Werror -g

INCLUDES = ./headers/so_long.h

Expand Down
82 changes: 46 additions & 36 deletions collectible_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,83 +6,93 @@
/* By: jbadaire <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/03 03:24:55 by jbadaire #+# #+# */
/* Updated: 2023/10/03 03:47:04 by jbadaire ### ########.fr */
/* Updated: 2023/10/05 16:31:17 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;
t_list *load_collectibles(t_world world) {
int pos_x;
int pos_y;
t_list **list;
t_collectible collectible;

pos_x = 0;
pos_y = 0;
list = malloc(sizeof (t_list));
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') {
while (world.map[pos_y]) {
while (world.map[pos_y] && pos_x < (int) ft_strlen(world.map[0])) {
if (world.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));
ft_lstadd_front(list, ft_lstnew(&collectible));
}
pos_x++;
}
pos_x = 0;
pos_y++;
}
return (list);
return (*list);

}


t_collectible *create_collectible(t_location location)
t_collectible create_collectible(t_location location)
{
t_collectible *collectible;
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;
collectible.location = location;
collectible.collected = 0;
return (collectible);
}

int count_collectibles(t_list *collectibles, t_boolean only_uncollected)
int count_collectibles(t_list *collectibles, t_boolean o_uncollected, t_boolean o_collected)
{
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++;
if (!collectibles)
return (0);

while (collectibles)
{
col = ((t_collectible*) collectibles->content);
if (col == NULL)
continue;
if(o_uncollected && !col->collected)
count++;
if(o_collected && col->collected)
count++;
collectibles = collectibles->next;
}
return (count);
}


t_collectible *get_collectible_at(t_world world, t_location location)
{
t_list *collectibles = world.player->collectibles;
t_collectible *collectible;

while (collectibles)
{
collectible = ((t_collectible*) collectibles->content);
if(loc_equals(location, collectible->location))
return collectible;
collectibles = collectibles->next;
}
return (NULL);
}

void update_collectible(t_list **collectibles, t_location location, t_boolean collected)
{
t_list *collectibles_copy;
Expand Down
16 changes: 8 additions & 8 deletions frees.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
/* By: jbadaire <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/03 10:21:10 by jbadaire #+# #+# */
/* Updated: 2023/10/03 10:54:19 by jbadaire ### ########.fr */
/* Updated: 2023/10/05 15:06:29 by jbadaire ### ########.fr */
/* */
/* ************************************************************************** */

#include "so_long.h"

void free_map(t_data data) {
size_t lenght_y;
void free_map(t_world world) {
int length_y;

lenght_y = 0;
while (data.lenght_y < lenght_y) {
free(data.map[lenght_y]);
lenght_y++;
length_y = 0;
while (world.length_y < length_y) {
free(world.map[length_y]);
length_y++;
}
free(data.map);
free(world.map);
}

void free_collectibles(t_list **collectibles) {
Expand Down
18 changes: 10 additions & 8 deletions graphics_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: jbadaire <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/03 12:56:12 by jbadaire #+# #+# */
/* Updated: 2023/10/03 15:33:57 by jbadaire ### ########.fr */
/* Updated: 2023/10/05 15:25:18 by jbadaire ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -24,20 +24,22 @@ void *load_texture(char *path, void *mlx) {
return (img);
}

void draw_type(void *mlx, void *mlx_window, void *texture, t_data data, char c)
void draw_type(void *mlx, void *mlx_window, void *texture, t_world world, char c)
{
size_t index_y;
size_t index_x;
int index_y;
int 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)

while (world.map[index_y]) {
while (index_x < (int) ft_strlen(world.map[index_y])) {
if (world.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_x = 0;
index_y++;
}
}
Expand Down
4 changes: 2 additions & 2 deletions libft/get_next_line.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*
* @param file_descriptor The file descriptor is an integer,
* value that represents an open file in the operating system. It
* is used to read or write data to/from the file. In this case,
* is used to read or write world to/from the file. In this case,
* the function `get_next_line` takes a file descriptor as a
* parameter to read data from a file.
* parameter to read world from a file.
*
* @return The function `get_next_line` is returning a pointer to,
* a string that contains the next line from the file
Expand Down
2 changes: 1 addition & 1 deletion libft/get_next_line_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ char *ft_str_join(char *r_line, char *buf, int nb_of_char, int len_line)
* It may be NULL if no line has been read yet.
*
* @param buffer The buffer parameter is a pointer to a character array
* that contains the data read from a file or input stream.
* that contains the world read from a file or input stream.
*
* @param chars_readed The parameter `chars_readed` is an integer that represents
* the number of characters read from a file
Expand Down
43 changes: 43 additions & 0 deletions location_utils.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* location_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jbadaire <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/05 15:30:50 by jbadaire #+# #+# */
/* Updated: 2023/10/05 15:36:04 by jbadaire ### ########.fr */
/* */
/* ************************************************************************** */

#include "so_long.h"

t_location create_location(int x, int y)
{
t_location location;

location.x = x;
location.y = y;
return (location);
}

t_location clone_location(t_location location)
{
t_location clone;

clone.x = location.x;
clone.y = location.y;
return (clone);
}

t_location edit_location(t_location location, int x, int y)
{
location.x += x;
location.y += y;
return (location);
}

t_boolean loc_equals(t_location loc_1, t_location loc_2)
{
return loc_1.x == loc_2.x && loc_1.y == loc_2.y;
}
Loading

0 comments on commit 17eba2d

Please sign in to comment.