Archived
1
0

started movement

This commit is contained in:
Adam Joly
2024-01-10 15:14:24 +01:00
parent ce760239b8
commit 904013801a
15 changed files with 50 additions and 28 deletions

View File

@ -6,7 +6,7 @@
# By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ # # By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2023/11/01 11:03:22 by adjoly #+# #+# # # Created: 2023/11/01 11:03:22 by adjoly #+# #+# #
# Updated: 2024/01/09 15:54:39 by adjoly ### ########.fr # # Updated: 2024/01/10 15:08:43 by adjoly ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -16,6 +16,7 @@ CC = cc
SRCS = main.c \ SRCS = main.c \
get_map.c \ get_map.c \
ft_move_character.c \
print_map.c print_map.c
OBJS = $(SRCS:.c=.o) OBJS = $(SRCS:.c=.o)

View File

@ -6,30 +6,42 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/07 19:13:01 by adjoly #+# #+# */ /* Created: 2024/01/07 19:13:01 by adjoly #+# #+# */
/* Updated: 2024/01/08 13:24:49 by adjoly ### ########.fr */ /* Updated: 2024/01/10 15:10:58 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "so_long.h" #include "so_long.h"
int ft_move_up(void *param) void ft_move_up(void *param)
{ {
t_window *win;
win = (t_window *)param;
ft_putimg(*win->player_x, *win->player_y - 1, win, "assets/player.png");
} }
int ft_move_down(void *param) void ft_move_down(void *param)
{ {
t_window *win;
win = (t_window *)param;
ft_putimg(*win->player_x, *win->player_y + 1, win, "assets/player.png");
} }
int ft_move_left(void *param) void ft_move_left(void *param)
{ {
t_window *win;
win = (t_window *)param;
ft_putimg(*win->player_x - 1, *win->player_y, win, "assets/player.png");
} }
int ft_move_right(void *param) void ft_move_right(void *param)
{ {
t_window *win;
win = (t_window *)param;
ft_putimg(*win->player_x + 1, *win->player_y, win, "assets/player.png");
} }
int ft_move_character(int key, void *param) int ft_move_character(int key, void *param)

BIN
ft_move_character.o Normal file

Binary file not shown.

View File

@ -6,7 +6,7 @@
# By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ # # By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2023/11/01 11:03:22 by adjoly #+# #+# # # Created: 2023/11/01 11:03:22 by adjoly #+# #+# #
# Updated: 2024/01/08 14:31:46 by adjoly ### ########.fr # # Updated: 2024/01/10 14:58:45 by adjoly ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/01 17:12:00 by adjoly #+# #+# */ /* Created: 2023/12/01 17:12:00 by adjoly #+# #+# */
/* Updated: 2024/01/08 21:47:06 by adjoly ### ########.fr */ /* Updated: 2024/01/10 15:03:00 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -22,7 +22,7 @@
char *get_next_line(int fd); char *get_next_line(int fd);
char *ft_strjoin_gnl(char *s1, char *s2); char *ft_strjoin_gnl(char *s1, char *s2);
size_t ft_strlen_gnl(char *s); size_t ft_strl_g(char *s);
void *ft_calloc_gnl(size_t nmemb, size_t size); void *ft_calloc_gnl(size_t nmemb, size_t size);
#endif #endif

Binary file not shown.

View File

@ -6,13 +6,13 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/01 17:12:02 by adjoly #+# #+# */ /* Created: 2023/12/01 17:12:02 by adjoly #+# #+# */
/* Updated: 2024/01/08 21:48:30 by adjoly ### ########.fr */ /* Updated: 2024/01/10 15:03:07 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "get_next_line.h" #include "get_next_line.h"
size_t ft_strlen_gnl(char *s) size_t ft_strl_g(char *s)
{ {
size_t i; size_t i;
@ -32,7 +32,7 @@ char *ft_strjoin_gnl(char *s1, char *s2)
j = 0; j = 0;
if (!s2) if (!s2)
return (NULL); return (NULL);
result = ft_calloc_gnl((ft_strlen_gnl(s1) + ft_strlen_gnl(s2) + 1), sizeof(char)); result = ft_calloc_gnl((ft_strl_g(s1) + ft_strl_g(s2) + 1), sizeof(char));
if (result == NULL) if (result == NULL)
return (NULL); return (NULL);
while (s1[i]) while (s1[i])

Binary file not shown.

6
main.c
View File

@ -6,12 +6,11 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/06 16:18:56 by adjoly #+# #+# */ /* Created: 2024/01/06 16:18:56 by adjoly #+# #+# */
/* Updated: 2024/01/09 16:13:17 by adjoly ### ########.fr */ /* Updated: 2024/01/10 15:08:11 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "MacroLibX/includes/mlx.h" #include "MacroLibX/includes/mlx.h"
#include "libft/libft.h"
#include "so_long.h" #include "so_long.h"
int key_close(int key, void *param) int key_close(int key, void *param)
@ -35,6 +34,7 @@ int win_close(int event, void *param)
int x; int x;
win = (t_window *)param; win = (t_window *)param;
ft_move_character(key, void *param)
return (0); return (0);
}*/ }*/
@ -51,7 +51,7 @@ int main(int ac, char **av)
mlx_on_event(win->mlx, win->win, MLX_KEYDOWN, key_close, win->mlx); mlx_on_event(win->mlx, win->win, MLX_KEYDOWN, key_close, win->mlx);
mlx_on_event(win->mlx, win->win, MLX_WINDOW_EVENT, win_close, win->mlx); mlx_on_event(win->mlx, win->win, MLX_WINDOW_EVENT, win_close, win->mlx);
// mlx_on_event(win->mlx, win->win, MLX_KEYDOWN, ft_move_character, win->mlx); mlx_on_event(win->mlx, win->win, MLX_KEYDOWN, ft_move_character, win);
// mlx_loop_hook(win->mlx, win_update, win); // mlx_loop_hook(win->mlx, win_update, win);
ft_printmap(map, win); ft_printmap(map, win);
mlx_loop(win->mlx); mlx_loop(win->mlx);

BIN
main.o

Binary file not shown.

View File

@ -6,13 +6,14 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/09 15:30:06 by adjoly #+# #+# */ /* Created: 2024/01/09 15:30:06 by adjoly #+# #+# */
/* Updated: 2024/01/10 10:40:19 by adjoly ### ########.fr */ /* Updated: 2024/01/10 14:57:51 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "MacroLibX/includes/mlx.h" #include "MacroLibX/includes/mlx.h"
#include "libft/libft.h" #include "libft/libft.h"
#include "so_long.h" #include "so_long.h"
#include <stddef.h>
void ft_putimg(int x, int y, t_window *win, char *file_path) void ft_putimg(int x, int y, t_window *win, char *file_path)
{ {
@ -21,20 +22,25 @@ void ft_putimg(int x, int y, t_window *win, char *file_path)
img_x = 0; img_x = 0;
img_y = 0; img_y = 0;
if (file_path[7] == 'p')
{
win->player_y = ft_calloc(sizeof(int), 1);
win->player_y = &y;
win->player_x = ft_calloc(sizeof(int), 1);
win->player_x = &x;
}
ft_putstr_fd(file_path, 1); ft_putstr_fd(file_path, 1);
ft_putchar_fd('\n', 1); ft_putchar_fd('\n', 1);
win->img = mlx_png_file_to_image(win->mlx, file_path, &img_x, &img_y); win->img = mlx_png_file_to_image(win->mlx, file_path, &img_x, &img_y);
mlx_put_image_to_window(win->mlx, win->win, win->img, x * img_x, y * img_y); mlx_put_image_to_window(win->mlx, win->win, win->img, x * img_x, y * img_y);
} }
int ft_printmap(char **map, void *param) void ft_printmap(char **map, t_window *win)
{ {
size_t x; size_t x;
size_t y; size_t y;
t_window *win;
y = 0; y = 0;
win = (t_window *)param;
while (map[y]) while (map[y])
{ {
x = 0; x = 0;
@ -54,5 +60,4 @@ int ft_printmap(char **map, void *param)
} }
y++; y++;
} }
return (0);
} }

Binary file not shown.

BIN
so_long

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/06 16:19:42 by adjoly #+# #+# */ /* Created: 2024/01/06 16:19:42 by adjoly #+# #+# */
/* Updated: 2024/01/09 16:17:27 by adjoly ### ########.fr */ /* Updated: 2024/01/10 14:50:43 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,6 +16,7 @@
# include "MacroLibX/includes/mlx.h" # include "MacroLibX/includes/mlx.h"
# include "libft/libft.h" # include "libft/libft.h"
# include "get_next_line/get_next_line.h" # include "get_next_line/get_next_line.h"
# include <stddef.h>
# include <unistd.h> # include <unistd.h>
# include <fcntl.h> # include <fcntl.h>
# include <stdlib.h> # include <stdlib.h>
@ -27,7 +28,9 @@ typedef struct s_window
void *mlx; void *mlx;
void *win; void *win;
void *img; void *img;
} t_window; int *player_x;
int *player_y;
} t_window;
int ft_move_character(int key, void *param); int ft_move_character(int key, void *param);
int key_close(int key, void *param); int key_close(int key, void *param);
@ -35,6 +38,7 @@ int key_close(int key, void *param);
int ft_countline_fd(int fd); int ft_countline_fd(int fd);
char **ft_read_map(char *file_name); char **ft_read_map(char *file_name);
int ft_printmap(char **map, void *param); void ft_printmap(char **map, t_window *win);
void ft_putimg(int x, int y, t_window *win, char *file_path);
#endif #endif