-
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
Showing
13 changed files
with
376 additions
and
217 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -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; | ||
|
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 |
---|---|---|
|
@@ -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) { | ||
|
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 |
---|---|---|
|
@@ -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 */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -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++; | ||
} | ||
} | ||
|
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
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
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,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; | ||
} |
Oops, something went wrong.