mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 01:48:08 +01:00
Compare commits
1 commit
98e0119c91
...
f9218303d4
| Author | SHA1 | Date | |
|---|---|---|---|
| f9218303d4 |
3 changed files with 43 additions and 8 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -4,3 +4,4 @@ cub3d
|
|||
libft.a
|
||||
vgcore.*
|
||||
cscope.*
|
||||
callgrind.out.*
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/07/17 14:54:36 by kcolin #+# #+# */
|
||||
/* Updated: 2025/08/07 11:38:18 by tchampio ### ########.fr */
|
||||
/* Updated: 2025/08/07 13:45:34 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -21,6 +21,7 @@
|
|||
# define PLAYER_SIZE 6
|
||||
# define RESSOURCE_DIR "ressources"
|
||||
# define MOVEMENT_SPEED 0.000005
|
||||
# define MOVEMENT_STEP 0.1
|
||||
# define ROTATION_SPEED 0.000002
|
||||
# define PLANE_VALUE 0.6
|
||||
# define TEXTURE_SIZE 64
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/08/05 12:53:06 by kcolin #+# #+# */
|
||||
/* Updated: 2025/08/06 11:46:04 by kcolin ### ########.fr */
|
||||
/* Updated: 2025/08/07 14:12:42 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,6 +14,23 @@
|
|||
#include "angle.h"
|
||||
#include "../consts.h"
|
||||
#include "../map/collision.h"
|
||||
#include <math.h>
|
||||
|
||||
static double ft_special_min(double a, double b)
|
||||
{
|
||||
double ret;
|
||||
|
||||
if (fabs(a) > fabs(b))
|
||||
{
|
||||
if (a > 0)
|
||||
ret = b;
|
||||
else
|
||||
ret = -b;
|
||||
}
|
||||
else
|
||||
ret = a;
|
||||
return (ret);
|
||||
}
|
||||
|
||||
void move_player_forward(t_cub3d_data *data)
|
||||
{
|
||||
|
|
@ -21,15 +38,31 @@ void move_player_forward(t_cub3d_data *data)
|
|||
double next_x;
|
||||
double next_y;
|
||||
float movspeed;
|
||||
int blocks;
|
||||
|
||||
movspeed = MOVEMENT_SPEED * data->delta;
|
||||
map = data->map;
|
||||
next_x = data->player.x + data->player.dir_x * movspeed;
|
||||
next_y = data->player.y + data->player.dir_y * movspeed;
|
||||
if (!blocks_movement(map, (int)data->player.y, (int)next_x))
|
||||
data->player.x += data->player.dir_x * movspeed;
|
||||
if (!blocks_movement(map, (int)next_y, (int)data->player.x))
|
||||
data->player.y += data->player.dir_y * movspeed;
|
||||
double mov_x = data->player.dir_x * movspeed;
|
||||
double mov_y = data->player.dir_y * movspeed;
|
||||
blocks = 0;
|
||||
while ((fabs(mov_x) > MOVEMENT_SPEED || fabs(mov_y) > MOVEMENT_SPEED) && blocks < 2)
|
||||
{
|
||||
blocks = 2;
|
||||
next_x = data->player.x + ft_special_min(mov_x, MOVEMENT_STEP);
|
||||
next_y = data->player.y + ft_special_min(mov_y, MOVEMENT_STEP);
|
||||
if (!blocks_movement(map, (int)data->player.y, (int)next_x))
|
||||
{
|
||||
data->player.x = next_x;
|
||||
blocks--;
|
||||
}
|
||||
if (!blocks_movement(map, (int)next_y, (int)data->player.x))
|
||||
{
|
||||
data->player.y = next_y;
|
||||
blocks--;
|
||||
}
|
||||
mov_x -= ft_special_min(mov_x, MOVEMENT_STEP);
|
||||
mov_y -= ft_special_min(mov_y, MOVEMENT_STEP);
|
||||
}
|
||||
}
|
||||
|
||||
void move_player_backward(t_cub3d_data *data)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue