aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRudy Bousset <rbousset@z2r4p3.le-101.fr>2020-02-17 17:21:29 +0100
committerRudy Bousset <rbousset@z2r4p3.le-101.fr>2020-02-17 17:21:29 +0100
commitfe33cb60b2355745237b49ecc969b86d2ea9101b (patch)
treedaf91b320d82d420e78a9e6f6475a161df082ca6
parentNorme (diff)
download42-cub3d-fe33cb60b2355745237b49ecc969b86d2ea9101b.tar.gz
42-cub3d-fe33cb60b2355745237b49ecc969b86d2ea9101b.tar.bz2
42-cub3d-fe33cb60b2355745237b49ecc969b86d2ea9101b.tar.xz
42-cub3d-fe33cb60b2355745237b49ecc969b86d2ea9101b.tar.zst
42-cub3d-fe33cb60b2355745237b49ecc969b86d2ea9101b.zip
Collision bav
-rw-r--r--map/map_one.cub30
-rw-r--r--src/ft_key_events.c22
-rw-r--r--src/ft_raycasting.c2
-rw-r--r--src/ft_tex_init.c10
4 files changed, 31 insertions, 33 deletions
diff --git a/map/map_one.cub b/map/map_one.cub
index b2635f8..80bb599 100644
--- a/map/map_one.cub
+++ b/map/map_one.cub
@@ -1,4 +1,4 @@
-R 1200 800
+R 1800 1100
NO ./map/img/crapaud.xpm
SO ./map/img/linus.xpm
@@ -9,17 +9,17 @@ S ./map/img/segfot.xpm
C 50,100,200
F 150,150,124
-11111111111111111 1
-1 00000000011000001
-1N0100000000000001
-101100000111000001
-111111111111111111
-100000000011000001
-111101111111110111
-111101111111110111
-11000 0001101010111
-100020000000000011
-100000000000000011
-1100000011010101 11
-111101111111010111
-111111111111111111
+1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
+1 E 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1
+1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1
+1 0 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 1
+1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1
+1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1
+1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1
+1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1
+1 1 0 0 0 0 0 0 1 1 0 1 0 1 0 1 1 1
+1 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 1 1
+1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1
+1 1 0 0 0 0 0 0 1 1 0 1 0 1 0 1 1 1
+1 1 1 1 0 1 1 1 1 1 1 1 0 1 0 1 1 1
+1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
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);
}