aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/ft_key_events.c22
-rw-r--r--src/ft_raycasting.c2
-rw-r--r--src/ft_tex_init.c10
3 files changed, 16 insertions, 18 deletions
diff --git a/src/ft_key_events.c b/src/ft_key_events.c
index 395761e..ba7a537 100644
--- a/src/ft_key_events.c
+++ b/src/ft_key_events.c
@@ -37,12 +37,20 @@ static uint16_t
}
static void
- ft_secure_player_pos(t_player *pl, t_map *ml)
+ ft_collision(float old_y, float old_x, t_player *pl, t_map *ml)
{
- (pl->pos_y < 1) ? (pl->pos_y = 1.1) : 0;
- (pl->pos_x < 1) ? (pl->pos_x = 1.1) : 0;
- (pl->pos_y > ml->map_h - 1.4) ? (pl->pos_y = ml->map_h - 1.4) : 0;
- (pl->pos_x > ml->map_w - 1.4) ? (pl->pos_x = ml->map_w - 1.4) : 0;
+ const size_t x = pl->pos_x;
+ const size_t y = pl->pos_y;
+
+ if (ml->map[y][x] == '1')
+ {
+ pl->pos_y = old_y;
+ pl->pos_x = old_x;
+ }
+ /* (pl->pos_y < 1) ? (pl->pos_y = 1.1) : 0; */
+ /* (pl->pos_x < 1) ? (pl->pos_x = 1.1) : 0; */
+ /* (pl->pos_y > ml->map_h - 1.4) ? (pl->pos_y = ml->map_h - 1.4) : 0; */
+ /* (pl->pos_x > ml->map_w - 1.4) ? (pl->pos_x = ml->map_w - 1.4) : 0; */
}
int
@@ -50,6 +58,8 @@ int
{
int (*fun_ptr[6])(t_cub*);
const uint16_t tmp_code = keycode;
+ const float old_y = clist->plist->pos_y;
+ const float old_x = clist->plist->pos_x;
fun_ptr[0] = ft_w_key;
fun_ptr[1] = ft_a_key;
@@ -61,7 +71,7 @@ int
if (keycode <= 5)
{
(*fun_ptr[keycode])(clist);
- ft_secure_player_pos(clist->plist, clist->mlist);
+ ft_collision(old_y, old_x, clist->plist, clist->mlist);
ft_draw_scene(clist);
return (0);
}
diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c
index 98f1c81..e1d3223 100644
--- a/src/ft_raycasting.c
+++ b/src/ft_raycasting.c
@@ -12,7 +12,6 @@
#include <cub3d.h>
#include <stdint.h>
-#include <stdio.h>
void
ft_calc_tex(t_cub *clist)
@@ -71,7 +70,6 @@ void
cl->rlist.wall_b = wl->y_size - 1;
ft_choose_tex(cl);
ft_calc_tex(cl);
- printf("%f\n", cl->rlist.wall_hit_x);
ft_draw_verline(cl, i, cl->rlist.wall_t - 1, cl->rlist.wall_b);
i++;
}
diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c
index 166f431..724877f 100644
--- a/src/ft_tex_init.c
+++ b/src/ft_tex_init.c
@@ -23,15 +23,6 @@
** 4 : sprite
*/
-void ft_puttex(t_cub *cl)
-{
- int i;
-
- i = 0;
- while (i < cl->tlist[0].img_w)
- i += 4;
-}
-
void ft_wall_tex_init(t_cub *cl)
{
cl->tlist[0].img = mlx_xpm_file_to_image(cl->wlist->wlx,
@@ -54,5 +45,4 @@ void ft_wall_tex_init(t_cub *cl)
cl->mlist->sprite_path, &cl->tlist[4].img_w, &cl->tlist[4].img_h);
cl->tlist[4].ptr = mlx_get_data_addr(cl->tlist[4].img,
&cl->tlist[4].bpp, &cl->tlist[4].sizeline, &cl->tlist[4].endian);
- ft_puttex(cl);
}