aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_draw_weapons_extra.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-03-19 14:57:04 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2020-03-19 14:57:04 +0100
commitebcfbdc44e2cdc64dca661520e8d0db2652da64e (patch)
tree687b919c4b859476ed495f7a5d68dfc41fe9af96 /src/ft_draw_weapons_extra.c
parentParsed weapons spawns (diff)
download42-cub3d-ebcfbdc44e2cdc64dca661520e8d0db2652da64e.tar.gz
42-cub3d-ebcfbdc44e2cdc64dca661520e8d0db2652da64e.tar.bz2
42-cub3d-ebcfbdc44e2cdc64dca661520e8d0db2652da64e.tar.xz
42-cub3d-ebcfbdc44e2cdc64dca661520e8d0db2652da64e.tar.zst
42-cub3d-ebcfbdc44e2cdc64dca661520e8d0db2652da64e.zip
Weapons sprites do draw
Diffstat (limited to 'src/ft_draw_weapons_extra.c')
-rw-r--r--src/ft_draw_weapons_extra.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/ft_draw_weapons_extra.c b/src/ft_draw_weapons_extra.c
new file mode 100644
index 0000000..04b61ea
--- /dev/null
+++ b/src/ft_draw_weapons_extra.c
@@ -0,0 +1,43 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_draw_weapons_extra.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/24 20:22:45 by rbousset #+# #+# */
+/* Updated: 2020/03/09 18:56:01 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <cub3d.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+static void
+ ft_calc_weapon(uint8_t id, t_cub *cl)
+{
+ t_sprite sprite;
+
+ sprite = cl->weaps[id][0];
+ sprite.spritey = sprite.s_pos_x - (cl->plist.pos_x - 0.5);
+ sprite.spritex = sprite.s_pos_y - (cl->plist.pos_y - 0.5);
+ 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.spritescreenx = (int)(cl->wlist.x_size / 2) *
+ (1 + sprite.transformx / sprite.transformy);
+ ft_sprite_h_w(cl, &sprite);
+ ft_draw_weapon(cl, &sprite);
+}
+
+void
+ ft_calc_weaps(t_cub *cl)
+{
+ ft_calc_weapon(0, cl);
+ ft_calc_weapon(1, cl);
+}