started movement
This commit is contained in:
3
Makefile
3
Makefile
@ -6,7 +6,7 @@
|
||||
# By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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 \
|
||||
get_map.c \
|
||||
ft_move_character.c \
|
||||
print_map.c
|
||||
|
||||
OBJS = $(SRCS:.c=.o)
|
||||
|
@ -6,30 +6,42 @@
|
||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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"
|
||||
|
||||
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)
|
||||
|
BIN
ft_move_character.o
Normal file
BIN
ft_move_character.o
Normal file
Binary file not shown.
@ -6,7 +6,7 @@
|
||||
# By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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 #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
BIN
get_next_line/get_next_line.a
Normal file
BIN
get_next_line/get_next_line.a
Normal file
Binary file not shown.
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 *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);
|
||||
|
||||
#endif
|
BIN
get_next_line/get_next_line.o
Normal file
BIN
get_next_line/get_next_line.o
Normal file
Binary file not shown.
@ -6,13 +6,13 @@
|
||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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"
|
||||
|
||||
size_t ft_strlen_gnl(char *s)
|
||||
size_t ft_strl_g(char *s)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@ -32,7 +32,7 @@ char *ft_strjoin_gnl(char *s1, char *s2)
|
||||
j = 0;
|
||||
if (!s2)
|
||||
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)
|
||||
return (NULL);
|
||||
while (s1[i])
|
||||
|
BIN
get_next_line/get_next_line_utils.o
Normal file
BIN
get_next_line/get_next_line_utils.o
Normal file
Binary file not shown.
6
main.c
6
main.c
@ -6,12 +6,11 @@
|
||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 "libft/libft.h"
|
||||
#include "so_long.h"
|
||||
|
||||
int key_close(int key, void *param)
|
||||
@ -35,6 +34,7 @@ int win_close(int event, void *param)
|
||||
int x;
|
||||
|
||||
win = (t_window *)param;
|
||||
ft_move_character(key, void *param)
|
||||
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_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);
|
||||
ft_printmap(map, win);
|
||||
mlx_loop(win->mlx);
|
||||
|
15
print_map.c
15
print_map.c
@ -6,13 +6,14 @@
|
||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 "libft/libft.h"
|
||||
#include "so_long.h"
|
||||
#include <stddef.h>
|
||||
|
||||
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_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_putchar_fd('\n', 1);
|
||||
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);
|
||||
}
|
||||
|
||||
int ft_printmap(char **map, void *param)
|
||||
void ft_printmap(char **map, t_window *win)
|
||||
{
|
||||
size_t x;
|
||||
size_t y;
|
||||
t_window *win;
|
||||
|
||||
y = 0;
|
||||
win = (t_window *)param;
|
||||
while (map[y])
|
||||
{
|
||||
x = 0;
|
||||
@ -54,5 +60,4 @@ int ft_printmap(char **map, void *param)
|
||||
}
|
||||
y++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
BIN
print_map.o
BIN
print_map.o
Binary file not shown.
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 "libft/libft.h"
|
||||
# include "get_next_line/get_next_line.h"
|
||||
# include <stddef.h>
|
||||
# include <unistd.h>
|
||||
# include <fcntl.h>
|
||||
# include <stdlib.h>
|
||||
@ -27,6 +28,8 @@ typedef struct s_window
|
||||
void *mlx;
|
||||
void *win;
|
||||
void *img;
|
||||
int *player_x;
|
||||
int *player_y;
|
||||
} t_window;
|
||||
|
||||
int ft_move_character(int key, void *param);
|
||||
@ -35,6 +38,7 @@ int key_close(int key, void *param);
|
||||
int ft_countline_fd(int fd);
|
||||
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
|
Reference in New Issue
Block a user