-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmove.c
More file actions
74 lines (68 loc) · 2.93 KB
/
move.c
File metadata and controls
74 lines (68 loc) · 2.93 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* move.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: muerdoga <muerdoga@student.42kocaeli.co +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/22 16:03:12 by bkarlida #+# #+# */
/* Updated: 2023/09/03 14:07:13 by muerdoga ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
void move_forward(t_cub3d *game)
{
if (game->b_map[(int)game->player.y][(int)(game->player.x
+ game->player.dir_x * game->player.speed)] == '0')
game->player.x += game->player.dir_x * game->player.speed;
if (game->b_map[(int)(game->player.y + game->player.dir_y
* game->player.speed)][(int)(game->player.x)] == '0')
game->player.y += game->player.dir_y * game->player.speed;
}
void move_back(t_cub3d *game)
{
if (game->b_map[(int)game->player.y][(int)(game->player.x
- game->player.dir_x * game->player.speed)] == '0')
game->player.x -= game->player.dir_x * game->player.speed;
if (game->b_map[(int)(game->player.y - game->player.dir_y
* game->player.speed)][(int)(game->player.x)] == '0')
game->player.y -= game->player.dir_y * game->player.speed;
}
void move_left(t_cub3d *game)
{
if (game->b_map[(int)game->player.y][(int)(game->player.x
+ game->player.dir_y * game->player.speed)] == '0')
game->player.x += game->player.dir_y * game->player.speed;
if (game->b_map[(int)(game->player.y - game->player.dir_x
* game->player.speed)][(int)(game->player.x)] == '0')
game->player.y += -game->player.dir_x * game->player.speed;
}
void move_right(t_cub3d *game)
{
if (game->b_map[(int)game->player.y][(int)(game->player.x
- game->player.dir_y * game->player.speed)] == '0')
game->player.x -= game->player.dir_y * game->player.speed;
if (game->b_map[(int)(game->player.y + game->player.dir_x
* game->player.speed)][(int)(game->player.x)] == '0')
game->player.y -= -game->player.dir_x * game->player.speed;
}
void player_move(t_cub3d *game)
{
game->b_map[(int)game->player.y][(int)game->player.x] = '0';
if ((game->move[0] || game->move[1]) && (game->move[2] || game->move[3]))
game->player.speed = 0.06 / sqrt(2);
else
game->player.speed = 0.06;
if (game->move[0] == 1)
move_forward(game);
else if (game->move[1] == 1)
move_back(game);
if (game->move[2] == 1)
move_left(game);
else if (game->move[3] == 1)
move_right(game);
if (game->move[4] == 1)
rotate_left(game);
else if (game->move[5] == 1)
rotate_right(game);
}