aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ft_basic_keys.c20
-rw-r--r--src/ft_can_it_shoot.c121
-rw-r--r--src/ft_castray_loop.c26
-rw-r--r--src/ft_collision.c16
-rw-r--r--src/ft_damage_bad_boy.c6
-rw-r--r--src/ft_detect.c38
-rw-r--r--src/ft_draw_sprite.c4
-rw-r--r--src/ft_draw_sprite_extra.c37
-rw-r--r--src/ft_draw_textures.c10
-rw-r--r--src/ft_extra_keys.c18
-rw-r--r--src/ft_find_item.c24
-rw-r--r--src/ft_floor_cast_inits.c10
-rw-r--r--src/ft_get_player_spawn.c34
-rw-r--r--src/ft_init_lists.c4
-rw-r--r--src/ft_init_s_ray.c6
-rw-r--r--src/ft_key_loop.c1
-rw-r--r--src/ft_select_bad_boy_action.c64
-rw-r--r--src/ft_sfx_pain.c6
-rw-r--r--src/ft_shoot.c37
19 files changed, 304 insertions, 178 deletions
diff --git a/src/ft_basic_keys.c b/src/ft_basic_keys.c
index 471038b..48a1305 100644
--- a/src/ft_basic_keys.c
+++ b/src/ft_basic_keys.c
@@ -20,30 +20,30 @@ int
const float move_speed = FT_MOVE_SPEED;
pl = &clist->plist;
- pl->pos_y += move_speed * pl->dir_x;
- pl->pos_x += move_speed * pl->dir_y;
+ pl->pos_y += move_speed * -pl->dir_y;
+ pl->pos_x += move_speed * pl->dir_x;
clist->moves = 1;
return (0);
}
int
- ft_a_key(t_cub *clist)
+ ft_s_key(t_cub *clist)
{
t_player *pl;
- const float move_speed = FT_STRAFE_SPEED;
+ const float move_speed = FT_MOVE_SPEED;
pl = &clist->plist;
- pl->pos_y += move_speed * -pl->dir_y;
- pl->pos_x += move_speed * pl->dir_x;
+ pl->pos_y += move_speed * pl->dir_y;
+ pl->pos_x += move_speed * -pl->dir_x;
clist->moves = 1;
return (0);
}
int
- ft_s_key(t_cub *clist)
+ ft_a_key(t_cub *clist)
{
t_player *pl;
- const float move_speed = FT_MOVE_SPEED;
+ const float move_speed = FT_STRAFE_SPEED;
pl = &clist->plist;
pl->pos_y += move_speed * -pl->dir_x;
@@ -59,8 +59,8 @@ int
const float move_speed = FT_STRAFE_SPEED;
pl = &clist->plist;
- pl->pos_y += move_speed * pl->dir_y;
- pl->pos_x += move_speed * -pl->dir_x;
+ pl->pos_y += move_speed * pl->dir_x;
+ pl->pos_x += move_speed * pl->dir_y;
clist->moves = 1;
return (0);
}
diff --git a/src/ft_can_it_shoot.c b/src/ft_can_it_shoot.c
new file mode 100644
index 0000000..0c76f3d
--- /dev/null
+++ b/src/ft_can_it_shoot.c
@@ -0,0 +1,121 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_can_it_shoot.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:28:51 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:28:51 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <cub3d.h>
+#include <stdlib.h>
+#include <math.h>
+
+static double
+ ft_get_a_big(int8_t id, double d, t_cub *cl)
+{
+ double a_big;
+
+ a_big = 0;
+ if (cl->sprites[13][id].s_pos_y > cl->plist.pos_y)
+ {
+ while (a_big < cl->sprites[13][id].s_pos_y - cl->plist.pos_y)
+ a_big += 0.001;
+ }
+ else if (cl->sprites[13][id].s_pos_y < cl->plist.pos_y)
+ {
+ while (a_big < cl->plist.pos_y - cl->sprites[13][id].s_pos_y)
+ a_big += 0.001;
+ }
+ else
+ a_big = d;
+ return (a_big);
+}
+
+static double
+ ft_get_b_big(int8_t id, t_cub *cl)
+{
+ double b_big;
+
+ b_big = 0;
+ if (cl->sprites[13][id].s_pos_x > cl->plist.pos_x)
+ {
+ while (b_big < cl->sprites[13][id].s_pos_x - cl->plist.pos_x)
+ b_big += 0.0001;
+ }
+ else if (cl->sprites[13][id].s_pos_x < cl->plist.pos_x)
+ {
+ while (b_big < cl->plist.pos_x - cl->sprites[13][id].s_pos_x)
+ b_big += 0.0001;
+ }
+ return (b_big);
+}
+
+static void
+ ft_init_ray_vars(int8_t id, double d, t_cub *cl)
+{
+ double a_big;
+ double b_big;
+ double teta;
+
+ a_big = ft_get_a_big(id, d, cl);
+ b_big = ft_get_b_big(id, cl);
+ if (a_big > b_big)
+ teta = acos(a_big / d);
+ else
+ teta = asin(b_big / d);
+ cl->rlist.y_ray_dir = 1 * cos(teta);
+ cl->rlist.x_ray_dir = 1 * sin(teta);
+ if (cl->plist.pos_y > cl->sprites[13][id].s_pos_y)
+ cl->rlist.y_ray_dir = -cl->rlist.y_ray_dir;
+ if (cl->plist.pos_x > cl->sprites[13][id].s_pos_x)
+ cl->rlist.x_ray_dir = -cl->rlist.x_ray_dir;
+ cl->rlist.y_ray_pos = cl->plist.pos_y;
+ cl->rlist.x_ray_pos = cl->plist.pos_x;
+ ft_detection_init_x(cl);
+ ft_detection_init_y(cl);
+}
+
+static int8_t
+ ft_shoot_cast_loop(int8_t id, double sqy, double sqx, t_cub *cl)
+{
+ uint8_t hit;
+
+ hit = 0;
+ while (hit == 0)
+ {
+ if (cl->rlist.x_side_dist < cl->rlist.y_side_dist)
+ {
+ cl->rlist.x_side_dist += cl->rlist.x_delta_dist;
+ sqy += cl->mlist.x_step * 0.01;
+ }
+ else
+ {
+ cl->rlist.y_side_dist += cl->rlist.y_delta_dist;
+ sqx += cl->mlist.y_step * 0.01;
+ }
+ if ((sqy >= cl->sprites[13][id].s_pos_y - 0.15 &&
+ sqy <= cl->sprites[13][id].s_pos_y + 0.15) &&
+ (sqx >= cl->sprites[13][id].s_pos_x - 0.15 &&
+ sqx <= cl->sprites[13][id].s_pos_x + 0.15))
+ break ;
+ if (cl->mlist.map[(uint64_t)(sqy + 0.5)][(uint64_t)(sqx + 0.5)] == '1')
+ hit = 1;
+ }
+ return ((hit == 1) ? (0) : (1));
+}
+
+int8_t
+ ft_can_it_shoot(int8_t id, double d, t_cub *cl)
+{
+ double sqx;
+ double sqy;
+
+ ft_init_ray_vars(id, d, cl);
+ sqy = cl->rlist.y_ray_pos;
+ sqx = cl->rlist.x_ray_pos;
+ return (ft_shoot_cast_loop(id, sqy, sqx, cl));
+}
diff --git a/src/ft_castray_loop.c b/src/ft_castray_loop.c
index 28277a7..00cb589 100644
--- a/src/ft_castray_loop.c
+++ b/src/ft_castray_loop.c
@@ -21,17 +21,17 @@ void
{
if (cl->rlist.side == 0)
cl->rlist.wall_hit_x = (cl->plist.pos_x) +
- cl->rlist.wall_dist * cl->rlist.y_ray_dir;
+ cl->rlist.wall_dist * cl->rlist.x_ray_dir;
else
cl->rlist.wall_hit_x = (cl->plist.pos_y) +
- cl->rlist.wall_dist * cl->rlist.x_ray_dir;
+ cl->rlist.wall_dist * cl->rlist.y_ray_dir;
cl->rlist.wall_hit_x -= floor(cl->rlist.wall_hit_x);
cl->tlist[cl->w_side].tex_x = (int)(cl->rlist.wall_hit_x *
(double)cl->tlist[cl->w_side].img_w);
- if (cl->rlist.side == 0 && cl->rlist.x_ray_dir > 0)
+ if (cl->rlist.side == 0 && cl->rlist.y_ray_dir > 0)
cl->tlist[cl->w_side].tex_x = cl->tlist[cl->w_side].img_w
- cl->tlist[cl->w_side].tex_x - 1;
- else if (cl->rlist.side == 1 && cl->rlist.y_ray_dir < 0)
+ else if (cl->rlist.side == 1 && cl->rlist.x_ray_dir < 0)
cl->tlist[cl->w_side].tex_x = cl->tlist[cl->w_side].img_w
- cl->tlist[cl->w_side].tex_x - 1;
}
@@ -45,24 +45,24 @@ void
wl = &cl->wlist;
pl = &cl->plist;
pl->cam_x = 2 * i / (float)(wl->x_size) - 1;
- cl->rlist.x_ray_pos = pl->pos_y;
- cl->rlist.y_ray_pos = pl->pos_x;
- cl->rlist.x_ray_dir = pl->dir_x + pl->plane_x *
+ cl->rlist.y_ray_pos = pl->pos_y;
+ cl->rlist.x_ray_pos = pl->pos_x;
+ cl->rlist.y_ray_dir = -pl->dir_y + pl->plane_x *
pl->cam_x;
- cl->rlist.y_ray_dir = pl->dir_y + pl->plane_y *
+ cl->rlist.x_ray_dir = pl->dir_x + pl->plane_y *
pl->cam_x;
- cl->rlist.sqx = (int16_t)cl->rlist.x_ray_pos;
cl->rlist.sqy = (int16_t)cl->rlist.y_ray_pos;
+ cl->rlist.sqx = (int16_t)cl->rlist.x_ray_pos;
ft_detect(cl);
if (cl->rlist.side == 0)
{
- cl->rlist.wall_dist = (cl->rlist.sqx - cl->rlist.x_ray_pos +
- (1 - cl->mlist.x_step) / 2) / cl->rlist.x_ray_dir;
+ cl->rlist.wall_dist = (cl->rlist.sqy - cl->rlist.y_ray_pos +
+ (1 - cl->mlist.x_step) / 2) / cl->rlist.y_ray_dir;
}
else
{
- cl->rlist.wall_dist = (cl->rlist.sqy - cl->rlist.y_ray_pos +
- (1 - cl->mlist.y_step) / 2) / cl->rlist.y_ray_dir;
+ cl->rlist.wall_dist = (cl->rlist.sqx - cl->rlist.x_ray_pos +
+ (1 - cl->mlist.y_step) / 2) / cl->rlist.x_ray_dir;
}
}
diff --git a/src/ft_collision.c b/src/ft_collision.c
index 00dab1f..385b2f7 100644
--- a/src/ft_collision.c
+++ b/src/ft_collision.c
@@ -21,13 +21,13 @@ static uint64_t
ft_find_x(int32_t key, const t_player *pl)
{
if (key == 0)
- return (pl->pos_x + (pl->dir_y * FT_COLL_MULT));
+ return (pl->pos_x + (pl->dir_x * FT_COLL_MULT));
else if (key == 1)
- return (pl->pos_x + (pl->dir_x * (FT_COLL_MULT / 2)));
+ return (pl->pos_x + (-pl->dir_y * (FT_COLL_MULT / 2)));
else if (key == 2)
- return (pl->pos_x - (pl->dir_y * FT_COLL_MULT));
+ return (pl->pos_x - (pl->dir_x * FT_COLL_MULT));
else if (key == 3)
- return (pl->pos_x - (pl->dir_x * (FT_COLL_MULT / 2)));
+ return (pl->pos_x - (-pl->dir_y * (FT_COLL_MULT / 2)));
return ((uint64_t)pl->pos_x);
}
@@ -35,13 +35,13 @@ static uint64_t
ft_find_y(int32_t key, const t_player *pl)
{
if (key == 0)
- return (pl->pos_y + (pl->dir_x * FT_COLL_MULT));
+ return (pl->pos_y + (-pl->dir_y * FT_COLL_MULT));
else if (key == 1)
- return (pl->pos_y - (pl->dir_y * (FT_COLL_MULT / 2)));
+ return (pl->pos_y - (pl->dir_x * (FT_COLL_MULT / 2)));
else if (key == 2)
- return (pl->pos_y - (pl->dir_x * FT_COLL_MULT));
+ return (pl->pos_y - (-pl->dir_y * FT_COLL_MULT));
else if (key == 3)
- return (pl->pos_y + (pl->dir_y * (FT_COLL_MULT / 2)));
+ return (pl->pos_y + (pl->dir_x * (FT_COLL_MULT / 2)));
return ((uint64_t)pl->pos_y);
}
diff --git a/src/ft_damage_bad_boy.c b/src/ft_damage_bad_boy.c
index 2d6bd58..8f896b0 100644
--- a/src/ft_damage_bad_boy.c
+++ b/src/ft_damage_bad_boy.c
@@ -22,8 +22,8 @@ static uint8_t
i = 0;
while (i < cl->mlist.sprite_nbr[13])
{
- if (lround(cl->sprites[13][i].s_pos_x) == (long)cl->rlist.sqy &&
- lround(cl->sprites[13][i].s_pos_y) == (long)cl->rlist.sqx)
+ if (lround(cl->sprites[13][i].s_pos_x) == (long)cl->rlist.sqx &&
+ lround(cl->sprites[13][i].s_pos_y) == (long)cl->rlist.sqy)
break ;
i++;
}
@@ -47,6 +47,8 @@ void
{
cl->sfx[13].sfx_play(cl->sfx);
cl->bad_boy[id].isdead = 1;
+ cl->mlist.map[lround(cl->sprites[13][id].s_pos_y)]
+ [lround(cl->sprites[13][id].s_pos_x)] = 'x';
}
else if (cl->bad_boy[id].does != 3)
cl->sfx[14].sfx_play(cl->sfx);
diff --git a/src/ft_detect.c b/src/ft_detect.c
index 0ef8831..c7bdcbb 100644
--- a/src/ft_detect.c
+++ b/src/ft_detect.c
@@ -17,40 +17,40 @@
void
ft_detection_init_y(t_cub *cl)
{
- cl->rlist.y_delta_dist = sqrt(1 + (cl->rlist.x_ray_dir *
- cl->rlist.x_ray_dir) / (cl->rlist.y_ray_dir *
- cl->rlist.y_ray_dir));
- if (cl->rlist.y_ray_dir < 0)
+ cl->rlist.y_delta_dist = sqrt(1 + (cl->rlist.y_ray_dir *
+ cl->rlist.y_ray_dir) / (cl->rlist.x_ray_dir *
+ cl->rlist.x_ray_dir));
+ if (cl->rlist.x_ray_dir < 0)
{
cl->mlist.y_step = -1;
- cl->rlist.y_side_dist = (cl->rlist.y_ray_pos -
- cl->rlist.sqy) * cl->rlist.y_delta_dist;
+ cl->rlist.y_side_dist = (cl->rlist.x_ray_pos -
+ cl->rlist.sqx) * cl->rlist.y_delta_dist;
}
else
{
cl->mlist.y_step = 1;
- cl->rlist.y_side_dist = (cl->rlist.sqy + 1.0 -
- cl->rlist.y_ray_pos) * cl->rlist.y_delta_dist;
+ cl->rlist.y_side_dist = (cl->rlist.sqx + 1.0 -
+ cl->rlist.x_ray_pos) * cl->rlist.y_delta_dist;
}
}
void
ft_detection_init_x(t_cub *cl)
{
- cl->rlist.x_delta_dist = sqrt(1 + (cl->rlist.y_ray_dir *
- cl->rlist.y_ray_dir) / (cl->rlist.x_ray_dir *
- cl->rlist.x_ray_dir));
- if (cl->rlist.x_ray_dir < 0)
+ cl->rlist.x_delta_dist = sqrt(1 + (cl->rlist.x_ray_dir *
+ cl->rlist.x_ray_dir) / (cl->rlist.y_ray_dir *
+ cl->rlist.y_ray_dir));
+ if (cl->rlist.y_ray_dir < 0)
{
cl->mlist.x_step = -1;
- cl->rlist.x_side_dist = (cl->rlist.x_ray_pos -
- cl->rlist.sqx) * cl->rlist.x_delta_dist;
+ cl->rlist.x_side_dist = (cl->rlist.y_ray_pos -
+ cl->rlist.sqy) * cl->rlist.x_delta_dist;
}
else
{
cl->mlist.x_step = 1;
- cl->rlist.x_side_dist = (cl->rlist.sqx + 1.0 -
- cl->rlist.x_ray_pos) * cl->rlist.x_delta_dist;
+ cl->rlist.x_side_dist = (cl->rlist.sqy + 1.0 -
+ cl->rlist.y_ray_pos) * cl->rlist.x_delta_dist;
}
}
@@ -65,17 +65,17 @@ void
if (cl->rlist.x_side_dist < cl->rlist.y_side_dist)
{
cl->rlist.x_side_dist += cl->rlist.x_delta_dist;
- cl->rlist.sqx += cl->mlist.x_step;
+ cl->rlist.sqy += cl->mlist.x_step;
cl->rlist.side = 0;
}
else
{
cl->rlist.y_side_dist += cl->rlist.y_delta_dist;
- cl->rlist.sqy += cl->mlist.y_step;
+ cl->rlist.sqx += cl->mlist.y_step;
cl->rlist.side = 1;
}
if (ft_ischarset(FT_CHRST_DETECT,
- cl->mlist.map[cl->rlist.sqx][cl->rlist.sqy]))
+ cl->mlist.map[cl->rlist.sqy][cl->rlist.sqx]))
cl->rlist.hit = 1;
}
}
diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c
index 6afac08..a127e31 100644
--- a/src/ft_draw_sprite.c
+++ b/src/ft_draw_sprite.c
@@ -97,10 +97,10 @@ void
d = sprite->y * 256 - cl->wlist.y_size * 128 +
sprite->spriteheight * 128;
sprite->tex_y = ((d * cl->tlist[sprite->current_sprite].img_h / 2) /
- sprite->spriteheight) / 128;
+ sprite->spriteheight) / 128;
if (sprite->transformy > 0 &&
cl->tlist[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 *
- cl->tlist[sprite->current_sprite].img_w * sprite->tex_y]
+ cl->tlist[sprite->current_sprite].img_w * sprite->tex_y]
&& cl->rlist.wall_dist_tab[sprite->x] > sprite->transformy)
ft_put_sprite(sprite, cl);
sprite->y++;
diff --git a/src/ft_draw_sprite_extra.c b/src/ft_draw_sprite_extra.c
index c9b8b16..00e295e 100644
--- a/src/ft_draw_sprite_extra.c
+++ b/src/ft_draw_sprite_extra.c
@@ -38,12 +38,13 @@ void
static void
ft_init_sprite(t_cub *cl, t_sprite *sprite)
{
- sprite->invdet = 1.0 / (cl->plist.plane_x * cl->plist.dir_y
- - cl->plist.dir_x * cl->plist.plane_y);
- sprite->transformx = sprite->invdet * (cl->plist.dir_y * sprite->spritex
- - cl->plist.dir_x * sprite->spritey);
- sprite->transformy = sprite->invdet * (-cl->plist.plane_y * sprite->spritex
- + cl->plist.plane_x * sprite->spritey);
+ sprite->invdet = 1.0 /
+ (cl->plist.plane_x * -cl->plist.dir_x
+ - cl->plist.dir_y * cl->plist.plane_y);
+ sprite->transformx = sprite->invdet * (-cl->plist.dir_x * sprite->spritex
+ - cl->plist.dir_y * sprite->spritey);
+ sprite->transformy = sprite->invdet * (cl->plist.plane_y * sprite->spritex
+ - cl->plist.plane_x * sprite->spritey);
sprite->spritescreenx = (int)(cl->wlist.x_size / 2) *
(1 + sprite->transformx / sprite->transformy);
}
@@ -52,21 +53,21 @@ void
ft_calc_sprite(t_cub *cl)
{
t_sprite sprite;
- int16_t i;
- int8_t j;
+ int8_t i;
i = -1;
- j = -1;
ft_sort_sprites(cl, -1, -1);
- while (++j < cl->big_t_val)
+ while (++i < cl->big_t_val)
{
- sprite = cl->sprites[(int8_t)cl->big_t[j][2]][(int32_t)cl->big_t[j][3]];
- sprite.current_sprite = (int8_t)cl->big_t[j][1];
- sprite.spritey = sprite.s_pos_x - (cl->plist.pos_x - 0.5);
- sprite.spritex = sprite.s_pos_y - (cl->plist.pos_y - 0.5);
- ft_init_sprite(cl, &sprite);
- ft_sprite_h_w(cl, &sprite);
- ft_draw_sprite(cl, &sprite);
- i = -1;
+ sprite = cl->sprites[(int8_t)cl->big_t[i][2]][(int32_t)cl->big_t[i][3]];
+ if (sprite.s_pos_x != 0)
+ {
+ sprite.current_sprite = (int8_t)cl->big_t[i][1];
+ sprite.spritey = sprite.s_pos_x - (cl->plist.pos_x - 0.5);
+ sprite.spritex = sprite.s_pos_y - (cl->plist.pos_y - 0.5);
+ ft_init_sprite(cl, &sprite);
+ ft_sprite_h_w(cl, &sprite);
+ ft_draw_sprite(cl, &sprite);
+ }
}
}
diff --git a/src/ft_draw_textures.c b/src/ft_draw_textures.c
index 5bf0854..533564d 100644
--- a/src/ft_draw_textures.c
+++ b/src/ft_draw_textures.c
@@ -46,18 +46,18 @@ void
void
ft_choose_tex(uint16_t x, t_cub *clist)
{
- if (clist->rlist.sqy == clist->mlist.nlx
- && clist->rlist.sqx == clist->mlist.nly)
+ if (clist->rlist.sqx == clist->mlist.nlx
+ && clist->rlist.sqy == clist->mlist.nly)
{
clist->w_side = 5;
}
else
{
- if (clist->rlist.side == 0 && clist->rlist.x_ray_dir < 0)
+ if (clist->rlist.side == 0 && clist->rlist.y_ray_dir < 0)
clist->w_side = 1;
- else if (clist->rlist.side == 0 && clist->rlist.x_ray_dir > 0)
+ else if (clist->rlist.side == 0 && clist->rlist.y_ray_dir > 0)
clist->w_side = 0;
- else if (clist->rlist.side == 1 && clist->rlist.y_ray_dir > 0)
+ else if (clist->rlist.side == 1 && clist->rlist.x_ray_dir > 0)
clist->w_side = 3;
else
clist->w_side = 2;
diff --git a/src/ft_extra_keys.c b/src/ft_extra_keys.c
index 1a71402..c1ea721 100644
--- a/src/ft_extra_keys.c
+++ b/src/ft_extra_keys.c
@@ -21,14 +21,14 @@ int
ft_left_key(t_cub *clist)
{
t_player *pl;
- float sav_dir_x;
+ float sav_dir_y;
float sav_plane_x;
const float rot_speed = FT_ROT_SPEED;
pl = &clist->plist;
- sav_dir_x = pl->dir_x;
- pl->dir_x = pl->dir_x * cos(rot_speed) - pl->dir_y * sin(rot_speed);
- pl->dir_y = sav_dir_x * sin(rot_speed) + pl->dir_y * cos(rot_speed);
+ sav_dir_y = pl->dir_y;
+ pl->dir_y = pl->dir_y * cos(-rot_speed) - pl->dir_x * sin(-rot_speed);
+ pl->dir_x = sav_dir_y * sin(-rot_speed) + pl->dir_x * cos(-rot_speed);
sav_plane_x = pl->plane_x;
pl->plane_x = pl->plane_x * cos(rot_speed) - pl->plane_y * sin(rot_speed);
pl->plane_y = sav_plane_x * sin(rot_speed) + pl->plane_y * cos(rot_speed);
@@ -39,14 +39,14 @@ int
ft_right_key(t_cub *clist)
{
t_player *pl;
- float sav_dir_x;
+ float sav_dir_y;
float sav_plane_x;
const float rot_speed = FT_ROT_SPEED;
pl = &clist->plist;
- sav_dir_x = pl->dir_x;
- pl->dir_x = pl->dir_x * cos(-rot_speed) - pl->dir_y * sin(-rot_speed);
- pl->dir_y = sav_dir_x * sin(-rot_speed) + pl->dir_y * cos(-rot_speed);
+ sav_dir_y = pl->dir_y;
+ pl->dir_y = pl->dir_y * cos(rot_speed) - pl->dir_x * sin(rot_speed);
+ pl->dir_x = sav_dir_y * sin(rot_speed) + pl->dir_x * cos(rot_speed);
sav_plane_x = pl->plane_x;
pl->plane_x = pl->plane_x * cos(-rot_speed) - pl->plane_y * sin(-rot_speed);
pl->plane_y = sav_plane_x * sin(-rot_speed) + pl->plane_y * cos(-rot_speed);
@@ -83,7 +83,7 @@ int
clist->plist.ammo[w_id] -= w_id;
clist->sfx[clist->plist.handles_weapon + 7].sfx_play(clist->sfx);
clist->plist.fire = 1;
- ft_shoot(clist, clist->wlist.x_size / 2);
+ ft_shoot(clist);
return (0);
}
else if (clist->plist.fire == 0 && clist->plist.ammo[w_id] <= 0)
diff --git a/src/ft_find_item.c b/src/ft_find_item.c
index 394e060..f9504d1 100644
--- a/src/ft_find_item.c
+++ b/src/ft_find_item.c
@@ -36,7 +36,7 @@ static uint16_t
uint16_t id;
id = 0;
- while (id <= 64)
+ while (id <= 32)
{
if (cl->sprites[10 + weap_id][id].s_pos_y == pos_y &&
cl->sprites[10 + weap_id][id].s_pos_x == pos_x)
@@ -68,21 +68,23 @@ static void
if (ft_ischarset(FT_CHRST_WEAPONS, map_char))
{
weap_id = 0;
- if (map_char == '@')
- weap_id = 1;
- else if (map_char == '#')
- weap_id = 2;
+ weap_id = (map_char == '@') ? (1) : (weap_id);
+ weap_id = (map_char == '#') ? (2) : (weap_id);
+ weap_id = (map_char == 'x') ? (3) : (weap_id);
cl->mlist.map[(uint64_t)pl->pos_y][(uint64_t)pl->pos_x] = '0';
- that_id = ft_fetch_weaps_id(weap_id, (uint64_t)pl->pos_y,
+ if (weap_id != 3)
+ {
+ that_id = ft_fetch_weaps_id(weap_id, (uint64_t)pl->pos_y,
(uint64_t)pl->pos_x, cl);
- cl->sprites[10 + weap_id][that_id].s_pos_x = 0;
- cl->sprites[10 + weap_id][that_id].s_pos_y = 0;
- pl->has_weapon[weap_id] = 1;
+ cl->sprites[10 + weap_id][that_id].s_pos_x = 0;
+ cl->sprites[10 + weap_id][that_id].s_pos_y = 0;
+ pl->has_weapon[weap_id] = 1;
+ }
pl->handles_weapon = (weap_id == 0) ? (0) : (pl->handles_weapon);
pl->handles_weapon = (weap_id == 1) ? (2) : (pl->handles_weapon);
pl->handles_weapon = (weap_id == 2) ? (4) : (pl->handles_weapon);
- ft_set_ammo(weap_id, pl);
- cl->sfx[6 + (weap_id * 2)].sfx_play(cl->sfx);
+ ft_set_ammo((weap_id == 3) ? (2) : (weap_id), pl);
+ cl->sfx[6 + (((weap_id == 3) ? (2) : (weap_id)) * 2)].sfx_play(cl->sfx);
}
}
diff --git a/src/ft_floor_cast_inits.c b/src/ft_floor_cast_inits.c
index 92b660b..022be1b 100644
--- a/src/ft_floor_cast_inits.c
+++ b/src/ft_floor_cast_inits.c
@@ -33,10 +33,10 @@ void
void
ft_floor_cast_inits(uint16_t y, t_ray *rl, t_cub *cl)
{
- rl->x_f_ray_dir = cl->plist.dir_x - cl->plist.plane_x;
- rl->y_f_ray_dir = cl->plist.dir_y - cl->plist.plane_y;
- rl->x_f_ray_dir_bis = cl->plist.dir_x + cl->plist.plane_x;
- rl->y_f_ray_dir_bis = cl->plist.dir_y + cl->plist.plane_y;
+ rl->x_f_ray_dir = cl->plist.dir_y + cl->plist.plane_x;
+ rl->y_f_ray_dir = cl->plist.dir_x - cl->plist.plane_y;
+ rl->x_f_ray_dir_bis = cl->plist.dir_y - cl->plist.plane_x;
+ rl->y_f_ray_dir_bis = cl->plist.dir_x + cl->plist.plane_y;
rl->p = y - cl->wlist.y_size / 2;
cl->plist.pos_z = 0.5 * cl->wlist.y_size;
rl->row_dist = cl->plist.pos_z / rl->p;
@@ -44,7 +44,7 @@ void
(rl->x_f_ray_dir_bis - rl->x_f_ray_dir) / cl->wlist.x_size;
cl->mlist.y_floor_step = rl->row_dist *
(rl->y_f_ray_dir_bis - rl->y_f_ray_dir) / cl->wlist.x_size;
- rl->x_floor = cl->plist.pos_y + rl->row_dist * rl->x_f_ray_dir;
+ rl->x_floor = -cl->plist.pos_y + rl->row_dist * rl->x_f_ray_dir;
rl->y_floor = cl->plist.pos_x + rl->row_dist * rl->y_f_ray_dir;
}
diff --git a/src/ft_get_player_spawn.c b/src/ft_get_player_spawn.c
index c506775..8642096 100644
--- a/src/ft_get_player_spawn.c
+++ b/src/ft_get_player_spawn.c
@@ -16,37 +16,37 @@
#include <stdint.h>
static void
+ ft_get_s_dir(t_player *pl)
+{
+ pl->dir_y = -pl->dir_y;
+ pl->dir_x = -pl->dir_x;
+ pl->plane_x = -pl->plane_x;
+ pl->plane_y = -pl->plane_y;
+}
+
+static void
ft_get_e_dir(t_player *pl)
{
- float sav_dir_x;
+ float sav_dir_y;
float sav_plane_x;
- sav_dir_x = pl->dir_x;
- pl->dir_x = -pl->dir_y;
- pl->dir_y = sav_dir_x;
+ sav_dir_y = pl->dir_y;
+ pl->dir_y = -pl->dir_x;
+ pl->dir_x = -sav_dir_y;
sav_plane_x = pl->plane_x;
pl->plane_x = -pl->plane_y;
pl->plane_y = sav_plane_x;
}
static void
- ft_get_s_dir(t_player *pl)
-{
- pl->dir_x = -pl->dir_x;
- pl->dir_y = -pl->dir_y;
- pl->plane_x = -pl->plane_x;
- pl->plane_y = -pl->plane_y;
-}
-
-static void
ft_get_w_dir(t_player *pl)
{
- float sav_dir_x;
+ float sav_dir_y;
float sav_plane_x;
- sav_dir_x = pl->dir_x;
- pl->dir_x = pl->dir_y;
- pl->dir_y = -sav_dir_x;
+ sav_dir_y = pl->dir_y;
+ pl->dir_y = pl->dir_x;
+ pl->dir_x = sav_dir_y;
sav_plane_x = pl->plane_x;
pl->plane_x = pl->plane_y;
pl->plane_y = -sav_plane_x;
diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c
index 2105a64..6ad56d1 100644
--- a/src/ft_init_lists.c
+++ b/src/ft_init_lists.c
@@ -47,8 +47,8 @@ t_player
plist.start_x = 0;
plist.start_y = 0;
plist.cam_x = 0;
- plist.dir_x = -1;
- plist.dir_y = 0;
+ plist.dir_y = 1;
+ plist.dir_x = 0;
plist.plane_x = 0;
plist.plane_y = 0.66;
plist.has_weapon[0] = 0;
diff --git a/src/ft_init_s_ray.c b/src/ft_init_s_ray.c
index 0d4ba96..ed68cd6 100644
--- a/src/ft_init_s_ray.c
+++ b/src/ft_init_s_ray.c
@@ -23,17 +23,17 @@ t_ray
rl.wall_dist = 0;
rl.wall_t = 0;
rl.wall_b = 0;
- rl.x_ray_pos = 0;
rl.y_ray_pos = 0;
- rl.x_ray_dir = 0;
+ rl.x_ray_pos = 0;
rl.y_ray_dir = 0;
+ rl.x_ray_dir = 0;
rl.x_side_dist = 0;
rl.y_side_dist = 0;
rl.x_delta_dist = 0;
rl.y_delta_dist = 0;
rl.side = 0;
- rl.sqx = 0;
rl.sqy = 0;
+ rl.sqx = 0;
rl.hit = 0;
return (rl);
}
diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c
index 281c81e..a59a80c 100644
--- a/src/ft_key_loop.c
+++ b/src/ft_key_loop.c
@@ -32,6 +32,7 @@ int
ft_handle_keys(i, old_y, old_x, cl);
i++;
}
+ /* TODO: Don't kill me so fast */
ft_check_bad_boy_shoot(cl);
cl->moves = (cl->key_input[0] == -1) ? (0) : (cl->moves);
begin_frame = clock();
diff --git a/src/ft_select_bad_boy_action.c b/src/ft_select_bad_boy_action.c
index 73b3f9a..2be17f3 100644
--- a/src/ft_select_bad_boy_action.c
+++ b/src/ft_select_bad_boy_action.c
@@ -16,8 +16,8 @@
#include <math.h>
/*
-** bad_boy[].act[] - index summary
-** -------------------------------
+** bad_boy.act[] - index summary
+** -----------------------------
** 0: wait
** 1: walk
** 2: fire
@@ -30,13 +30,6 @@
** rand(0-7) | [0-1] wait | [2] walk | [3-7] fire
*/
-static double
- ft_get_dist(t_sprite sprite, t_cub *cl)
-{
- return (sqrt(pow(cl->plist.pos_x - sprite.s_pos_x, 2) +
- pow(cl->plist.pos_y - sprite.s_pos_y, 2)));
-}
-
static int8_t
ft_set_r_i(void)
{
@@ -74,37 +67,50 @@ static int8_t
static void
ft_bb_act(int8_t r, int8_t i, t_cub *cl)
{
+ cl->bad_boy[i].sleep = 1;
cl->bad_boy[i].act[r](&cl->bad_boy[i],
&cl->sprites[13][i], &cl->mlist);
- cl->bad_boy[i].sleep = 1;
+}
+
+static void
+ ft_select_action(int8_t i, double d, t_cub *cl)
+{
+ int8_t can_shoot;
+ int8_t r;
+
+ if (cl->bad_boy[i].life <= 0)
+ cl->bad_boy[i].does = 3;
+ else
+ can_shoot = ft_can_it_shoot(i, d, cl);
+ if (cl->bad_boy[i].sleep == 0 && cl->bad_boy[i].life > 0 &&
+ (d <= FT_ENMY_SIGHT_RANGE &&
+ can_shoot == 1))
+ {
+ r = ft_set_r_ii();
+ ft_bb_act(r, i, cl);
+ }
+ else if (cl->bad_boy[i].sleep == 0 && cl->bad_boy[i].life > 0)
+ {
+ r = ft_set_r_i();
+ ft_bb_act(r, i, cl);
+ }
}
void
ft_select_bad_boy_action(t_cub *cl)
{
int8_t i;
- int8_t r;
+ double d;
- i = -1;
- while (++i < cl->mlist.sprite_nbr[13])
+ i = 0;
+ while (i < cl->mlist.sprite_nbr[13])
{
- if (cl->bad_boy[i].sleep == 0 && cl->bad_boy[i].life > 0 &&
- (ft_get_dist(cl->sprites[13][i], cl) > FT_ENMY_SIGHT_RANGE
- || cl->rlist.wall_dist_tab[cl->wlist.x_size / 2] <
- ft_get_dist(cl->sprites[13][i], cl)))
- {
- r = ft_set_r_i();
- ft_bb_act(r, i, cl);
- }
- else if (cl->bad_boy[i].sleep == 0 && cl->bad_boy[i].life > 0 &&
- (ft_get_dist(cl->sprites[13][i], cl) <= FT_ENMY_SIGHT_RANGE
- && cl->rlist.wall_dist_tab[cl->wlist.x_size / 2] >
- ft_get_dist(cl->sprites[13][i], cl)))
+ if ((d = sqrt(pow(cl->plist.pos_x - cl->sprites[13][i].s_pos_x, 2) +
+ pow(cl->plist.pos_y - cl->sprites[13][i].s_pos_y, 2)))
+ <= 3 * FT_ENMY_SIGHT_RANGE && cl->bad_boy[i].sleep == 0)
{
- r = ft_set_r_ii();
- ft_bb_act(r, i, cl);
+ ft_select_action(i, d, cl);
}
- else if (cl->bad_boy[i].life <= 0)
- cl->bad_boy[i].does = 3;
+ i++;
}
}
diff --git a/src/ft_sfx_pain.c b/src/ft_sfx_pain.c
index d7ad5ef..2670b99 100644
--- a/src/ft_sfx_pain.c
+++ b/src/ft_sfx_pain.c
@@ -44,9 +44,5 @@ void
void
ft_sfx_pain(t_sfx *sfx)
{
- static uint8_t ref = 0;
-
- ref = (ref > 201) ? (0) : (ref + 1);
- if (ref % 2)
- pthread_mutex_unlock(&sfx[3].mutex);
+ pthread_mutex_unlock(&sfx[3].mutex);
}
diff --git a/src/ft_shoot.c b/src/ft_shoot.c
index 7f12eb6..dbd8862 100644
--- a/src/ft_shoot.c
+++ b/src/ft_shoot.c
@@ -28,8 +28,8 @@ static void
{
while (++j < 4096)
{
- if (cl->sprites[i][j].s_pos_x == cl->rlist.sqy &&
- cl->sprites[i][j].s_pos_y == cl->rlist.sqx)
+ if (cl->sprites[i][j].s_pos_x == cl->rlist.sqx &&
+ cl->sprites[i][j].s_pos_y == cl->rlist.sqy)
{
stop = 1;
break ;
@@ -39,7 +39,7 @@ static void
break ;
j = -1;
}
- cl->mlist.map[cl->rlist.sqx][cl->rlist.sqy] = '0';
+ cl->mlist.map[cl->rlist.sqy][cl->rlist.sqx] = '0';
cl->sprites[i][j].s_pos_x = 0;
cl->sprites[i][j].s_pos_y = 0;
}
@@ -48,8 +48,8 @@ static int8_t
ft_weap_range(t_cub *cl)
{
if (cl->plist.handles_weapon == 0 &&
- sqrtf(powf(cl->plist.pos_x - cl->rlist.sqy, 2)
- + powf(cl->plist.pos_y - cl->rlist.sqx, 2)) > 1.3)
+ sqrtf(powf(cl->plist.pos_x - cl->rlist.sqx, 2)
+ + powf(cl->plist.pos_y - cl->rlist.sqy, 2)) > 1.6)
return (0);
return (1);
}
@@ -60,13 +60,13 @@ static void
if (cl->rlist.x_side_dist < cl->rlist.y_side_dist)
{
cl->rlist.x_side_dist += cl->rlist.x_delta_dist;
- cl->rlist.sqx += cl->mlist.x_step;
+ cl->rlist.sqy += cl->mlist.x_step;
cl->rlist.side = 0;
}
else
{
cl->rlist.y_side_dist += cl->rlist.y_delta_dist;
- cl->rlist.sqy += cl->mlist.y_step;
+ cl->rlist.sqx += cl->mlist.y_step;
cl->rlist.side = 1;
}
}
@@ -78,39 +78,36 @@ static void
{
ft_set_sq(cl);
if (ft_ischarset(FT_CHRST_SPRITES,
- cl->mlist.map[cl->rlist.sqx][cl->rlist.sqy]) && ft_weap_range(cl))
+ cl->mlist.map[cl->rlist.sqy][cl->rlist.sqx]) && ft_weap_range(cl))
{
hit = 1;
ft_hide_sprite(cl);
}
- else if (cl->mlist.map[cl->rlist.sqx][cl->rlist.sqy] == 'e' &&
+ else if (cl->mlist.map[cl->rlist.sqy][cl->rlist.sqx] == 'e' &&
ft_weap_range(cl))
{
hit = 1;
ft_damage_bad_boy(cl);
}
- else if (cl->mlist.map[cl->rlist.sqx][cl->rlist.sqy] == '1')
+ else if (cl->mlist.map[cl->rlist.sqy][cl->rlist.sqx] == '1')
hit = 1;
}
}
void
- ft_shoot(t_cub *cl, uint16_t i)
+ ft_shoot(t_cub *cl)
{
t_win *wl;
t_player *pl;
wl = &cl->wlist;
pl = &cl->plist;
- pl->cam_x = 2 * i / (float)(wl->x_size) - 1;
- cl->rlist.x_ray_pos = pl->pos_y;
- cl->rlist.y_ray_pos = pl->pos_x;
- cl->rlist.x_ray_dir = pl->dir_x + pl->plane_x *
- pl->cam_x;
- cl->rlist.y_ray_dir = pl->dir_y + pl->plane_y *
- pl->cam_x;
- cl->rlist.sqx = (int16_t)cl->rlist.x_ray_pos;
- cl->rlist.sqy = (int16_t)cl->rlist.y_ray_pos;
+ cl->rlist.y_ray_pos = pl->pos_y;
+ cl->rlist.x_ray_pos = pl->pos_x;
+ cl->rlist.y_ray_dir = -pl->dir_y;
+ cl->rlist.x_ray_dir = pl->dir_x;
+ cl->rlist.sqy = (uint64_t)cl->rlist.y_ray_pos;
+ cl->rlist.sqx = (uint64_t)cl->rlist.x_ray_pos;
ft_detection_init_x(cl);
ft_detection_init_y(cl);
ft_hitscan(cl, 0);