-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.c
More file actions
executable file
·81 lines (75 loc) · 2.73 KB
/
utils.c
File metadata and controls
executable file
·81 lines (75 loc) · 2.73 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
75
76
77
78
79
80
81
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tnaceur <tnaceur@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/17 18:22:26 by tnaceur #+# #+# */
/* Updated: 2023/03/08 15:08:31 by tnaceur ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub.h"
double distance(t_game *game, double x1, double y1)
{
return (sqrt(pow(x1 - game->p_x, 2) + pow(y1 - game->p_y, 2)));
}
int my_mlx_pixel_put(t_game *game, int x, int y, int color)
{
char *dst;
if (x >= WIDTH || y >= HEIGHT || y < 0 || x < 0)
return (0);
dst = game->addr + (y * game->line_length + x * (game->bits_per_pixel / 8));
*(unsigned int *)dst = color;
return (1);
}
void move_w_s(int key, t_game *game, int n_x, int n_y)
{
if (key == KEY_W)
{
n_x = floor((game->p_x + 4 * cos(game->rot_angle)));
n_y = floor((game->p_y + 4 * sin(game->rot_angle)));
if (player_pos(game, n_x, n_y) && player_pos(game, n_x, game->p_y)
&& player_pos(game, game->p_x, n_y))
{
game->p_x += 4.0 * cos(game->rot_angle);
game->p_y += 4.0 * sin(game->rot_angle);
}
}
else if (key == KEY_S)
{
n_x = floor((game->p_x - 4 * cos(game->rot_angle)));
n_y = floor((game->p_y - 4 * sin(game->rot_angle)));
if ((player_pos(game, n_x, n_y) && player_pos(game, n_x, game->p_y)
&& player_pos(game, game->p_x, n_y)))
{
game->p_x += -4.0 * cos(game->rot_angle);
game->p_y += -4.0 * sin(game->rot_angle);
}
}
}
void move_a_d(int key, t_game *game, int n_x, int n_y)
{
if (key == KEY_A)
{
n_x = floor(game->p_x + 4 * sin(game->rot_angle));
n_y = floor(game->p_y - 4 * cos(game->rot_angle));
if ((player_pos(game, n_x, n_y) && player_pos(game, n_x, game->p_y)
&& player_pos(game, game->p_x, n_y)))
{
game->p_x += +4.0 * sin(game->rot_angle);
game->p_y += -4.0 * cos(game->rot_angle);
}
}
else if (key == KEY_D)
{
n_x = floor(game->p_x - 4 * sin(game->rot_angle));
n_y = floor(game->p_y + 4 * cos(game->rot_angle));
if ((player_pos(game, n_x, n_y) && player_pos(game, n_x, game->p_y)
&& player_pos(game, game->p_x, n_y)))
{
game->p_x += -4.0 * sin(game->rot_angle);
game->p_y += +4.0 * cos(game->rot_angle);
}
}
}