blob: 8cabe9ac2a2ab7f9ecb55aba6e53327c00878cd4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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);
}
|