summaryrefslogtreecommitdiff
path: root/src/player_process.c
diff options
context:
space:
mode:
authorDominik Kaiser2024-05-14 12:45:49 +0200
committerDominik Kaiser2024-05-14 12:45:49 +0200
commit300128b8b0eaf4e6dd04c076887721dc645c939e (patch)
tree42ade0794bb118ded99c0528dde17d59c78eb047 /src/player_process.c
parent7b021c4426f21bf20fed61459ddedb5224e25bc4 (diff)
downloadso_long-300128b8b0eaf4e6dd04c076887721dc645c939e.tar.gz
so_long-300128b8b0eaf4e6dd04c076887721dc645c939e.zip
Outsource player processing and add collision func
Diffstat (limited to 'src/player_process.c')
-rw-r--r--src/player_process.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/player_process.c b/src/player_process.c
new file mode 100644
index 0000000..8cabe9a
--- /dev/null
+++ b/src/player_process.c
@@ -0,0 +1,40 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* player_process.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2024/05/14 12:40:05 by dkaiser #+# #+# */
+/* Updated: 2024/05/14 12:44:17 by dkaiser ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "so_long.h"
+
+static t_vector get_direction_from_input(t_game *game);
+
+void player_process(t_game *game)
+{
+ t_player player;
+
+ player = game->player;
+ player.direction = get_direction_from_input(game);
+ player.velocity.x = player.direction.x * PLAYER_MOVE_SPEED
+ * game->mlx->delta_time;
+ player.velocity.y = player.direction.y * PLAYER_MOVE_SPEED
+ * game->mlx->delta_time;
+ player.position.x += player.velocity.x;
+ player.position.y += player.velocity.y;
+}
+
+static t_vector get_direction_from_input(t_game *game)
+{
+ t_vector result;
+
+ result.x = ((game->input_direction & RIGHT) != 0)
+ - ((game->input_direction & LEFT) != 0);
+ result.y = ((game->input_direction & DOWN) != 0)
+ - ((game->input_direction & UP) != 0);
+ return (result);
+}