Skip to content

Commit

Permalink
Merge pull request #34 from Haliris/sprite_render
Browse files Browse the repository at this point in the history
Sprite render
  • Loading branch information
Haliris authored Sep 4, 2024
2 parents b378f6f + 340563c commit 4fb7866
Show file tree
Hide file tree
Showing 14 changed files with 158 additions and 346 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# By: tsuchen <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/08/15 12:02:08 by tsuchen #+# #+# #
# Updated: 2024/09/03 16:36:38 by tsuchen ### ########.fr #
# Updated: 2024/09/04 09:59:33 by tsuchen ### ########.fr #
# #
# **************************************************************************** #

Expand All @@ -32,7 +32,7 @@ SRCS_RC = raycasting.c render_wall.c render_utils.c

SRCS_VEC = vector.c vector_2.c vector_3.c

SRCS_FRM = lst_add_back.c lst_clear.c lst_last.c lst_new.c lst_size.c
SRCS_FRM = frame_lst_utils.c sprite.c

PATH_M = srcs/
PATH_PS = srcs/parser/
Expand Down
10 changes: 8 additions & 2 deletions includes/cub3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: tsuchen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/15 00:19:44 by tsuchen #+# #+# */
/* Updated: 2024/09/03 18:39:21 by tsuchen ### ########.fr */
/* Updated: 2024/09/04 12:28:56 by tsuchen ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -54,7 +54,7 @@
# define MINI_MAP_W 200
# define MINI_MAP_H 200
# define MINI_MAP_X 15
# define MINI_MAP_Y 15
# define MINI_MAP_Y 505
# define KEY_PRESS 2
# define MOUSE_PRESS 4
# define MOUSE_MOVE 6
Expand All @@ -77,10 +77,12 @@ typedef enum e_keys
ARROW_UP = 65362,
ARROW_DOWN = 65364,
ESC_KEY = 65307,
SPACE_KEY = 32,
W_KEY = 119,
A_KEY = 97,
S_KEY = 115,
D_KEY = 100,
R_KEY = 114,
M1 = 65307,
P_KEY = 112,
} t_keys;
Expand Down Expand Up @@ -142,6 +144,7 @@ int key_events(int keycode, t_data *data);
int mouse_move(int x, int y, t_data *data);
void move_check(t_vec *step, t_data *data, int add_or_sub);
int mouse_press(int button, int x, int y, t_data *data);
void interact_door(t_data *data);
/* color utils*/
int create_trgb(int t, int r, int g, int b);
int get_color(int trgb, char index);
Expand All @@ -157,5 +160,8 @@ void rc_mlx_pixel_put(t_image *image, int x, int y, int color);
void rc_stripe_pixel_put(t_data *data, int x, double ray_dist);
/* Mini Map */
void put_mini_map(t_data *data);
/* Sprite */
void play_sprite_forward(t_data *data, int map_x, int map_y);
void play_sprite_backward(t_data *data, int map_x, int map_y);

#endif
2 changes: 1 addition & 1 deletion srcs/color_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: tsuchen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/05 15:01:46 by tsuchen #+# #+# */
/* Updated: 2024/08/29 11:13:15 by tsuchen ### ########.fr */
/* Updated: 2024/09/04 09:28:05 by tsuchen ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
14 changes: 12 additions & 2 deletions srcs/events/key_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* key_events.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jteissie <jteissie@student.42.fr> +#+ +:+ +#+ */
/* By: tsuchen <tsuchen@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/27 18:40:50 by jteissie #+# #+# */
/* Updated: 2024/09/02 17:28:10 by jteissie ### ########.fr */
/* Updated: 2024/09/04 09:48:55 by tsuchen ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -54,6 +54,12 @@ static void key_move_camera(t_data *data, t_rot dir)
return ;
}

static void turn_around(t_data *data)
{
vec_mirror(&data->p_cam);
vec_mirror(&data->p_dir);
}

static void pause_game(t_data *data)
{
if (data->pause == TRUE)
Expand All @@ -78,6 +84,10 @@ int key_events(int keycode, t_data *data)
move_player(data, LEFT);
else if (keycode == D_KEY && data->pause == FALSE)
move_player(data, RIGHT);
else if (keycode == R_KEY && data->pause == FALSE)
turn_around(data);
else if (keycode == SPACE_KEY && data->pause == FALSE)
interact_door(data);
else if (keycode == ESC_KEY)
cleanup(data);
return (SUCCESS);
Expand Down
10 changes: 5 additions & 5 deletions srcs/events/mouse_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* mouse_events.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jteissie <jteissie@student.42.fr> +#+ +:+ +#+ */
/* By: tsuchen <tsuchen@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/02 11:59:13 by jteissie #+# #+# */
/* Updated: 2024/09/02 17:25:01 by jteissie ### ########.fr */
/* Updated: 2024/09/04 12:25:22 by tsuchen ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -46,12 +46,12 @@ static void change_door_state(t_data *data, t_vec *p_ray)
door_x = data->p_pos.x + p_ray->x;
door_y = data->p_pos.y + p_ray->y;
if (data->map[door_x][door_y] == 'D')
data->map[door_x][door_y] = 'O';
play_sprite_forward(data, door_x, door_y);
else if (data->map[door_x][door_y] == 'O')
data->map[door_x][door_y] = 'D';
play_sprite_backward(data, door_x, door_y);
}

static void interact_door(t_data *data)
void interact_door(t_data *data)
{
t_vec p_ray;
double dist;
Expand Down
73 changes: 57 additions & 16 deletions srcs/frames/lst_new.c → srcs/frames/frame_lst_utils.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lst_new.c :+: :+: :+: */
/* frame_lst_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tsuchen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/10 11:28:30 by tsuchen #+# #+# */
/* Updated: 2024/09/03 16:17:52 by tsuchen ### ########.fr */
/* Created: 2024/05/10 11:39:29 by tsuchen #+# #+# */
/* Updated: 2024/09/04 09:58:46 by tsuchen ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -23,17 +23,58 @@ t_frame *lst_new(void)
lst->prev = NULL;
return (lst);
}
/*
#include <stdio.h>
int main(void)

void lst_add_back(t_frame **lst, t_frame *new_node)
{
t_frame *tmp;

if (!new_node)
return ;
if (!(*lst))
{
*lst = new_node;
return ;
}
tmp = *lst;
while (tmp->next)
tmp = tmp->next;
new_node->prev = tmp;
tmp->next = new_node;
}

void lst_clear(t_frame **lst, void (*del)(void *))
{
int a = 7;
t_list *lst;
lst = ft_lstnew(&a);
printf("val_lst: %d, add_lst: %p\n", *((int *)(lst->content)), lst->content);
printf("val_a : %d, add_a : %p\n", a, &a);
printf("add of nex in lst: %p\n", lst->next);
free(lst);
return (0);
}*/
t_frame *tmp;

while (*lst)
{
tmp = *lst;
*lst = (*lst)->next;
del(tmp);
}
}

t_frame *lst_last(t_frame *lst)
{
t_frame *tmp;

tmp = lst;
while (tmp->next)
tmp = tmp->next;
return (tmp);
}

int lst_size(t_frame *lst)
{
int i;
t_frame *tmp;

tmp = lst;
i = 0;
while (tmp)
{
i++;
tmp = tmp->next;
}
return (i);
}
118 changes: 0 additions & 118 deletions srcs/frames/lst_add_back.c

This file was deleted.

Loading

0 comments on commit 4fb7866

Please sign in to comment.