mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 01:48:08 +01:00
fix(player init): deleted old init_player function in favor of the new
one
This commit is contained in:
parent
9c710c13e3
commit
ac94e9e937
2 changed files with 22 additions and 32 deletions
48
src/main.c
48
src/main.c
|
|
@ -6,12 +6,13 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */
|
/* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */
|
||||||
/* Updated: 2025/07/29 12:33:46 by tchampio ### ########.fr */
|
/* Updated: 2025/07/29 13:28:35 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../libft/includes/libft.h"
|
#include "../libft/includes/libft.h"
|
||||||
#include "../mlx/mlx.h"
|
#include "../mlx/mlx.h"
|
||||||
|
#include "player/player.h"
|
||||||
#include "consts.h"
|
#include "consts.h"
|
||||||
#include "cub3d_data.h"
|
#include "cub3d_data.h"
|
||||||
#include "draw/drawutils.h"
|
#include "draw/drawutils.h"
|
||||||
|
|
@ -29,21 +30,6 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdio.h> // BAD
|
#include <stdio.h> // BAD
|
||||||
|
|
||||||
void init_player(t_mapdata *mapdata, t_player *player)
|
|
||||||
{
|
|
||||||
player->health = 100;
|
|
||||||
player->x = mapdata->startx * SIZE + ((float)SIZE / 2);
|
|
||||||
player->y = mapdata->starty * SIZE + ((float)SIZE / 2);
|
|
||||||
if (mapdata->map[mapdata->starty][mapdata->startx] == 'N')
|
|
||||||
player->yaw = M_PI;
|
|
||||||
else if (mapdata->map[mapdata->starty][mapdata->startx] == 'S')
|
|
||||||
player->yaw = 0;
|
|
||||||
else if (mapdata->map[mapdata->starty][mapdata->startx] == 'E')
|
|
||||||
player->yaw = M_PI / 2;
|
|
||||||
else if (mapdata->map[mapdata->starty][mapdata->startx] == 'W')
|
|
||||||
player->yaw = 3 * M_PI / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool touch(float px, float py, t_mapdata *map)
|
bool touch(float px, float py, t_mapdata *map)
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
|
|
@ -56,20 +42,20 @@ bool touch(float px, float py, t_mapdata *map)
|
||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_line(t_cub3d_data *data, float start_angle)
|
// void draw_line(t_cub3d_data *data, float start_angle)
|
||||||
{
|
// {
|
||||||
float cos_angle = cos(start_angle);
|
// float cos_angle = cos(start_angle);
|
||||||
float sin_angle = sin(start_angle);
|
// float sin_angle = sin(start_angle);
|
||||||
float ray_x = data->player.x;
|
// float ray_x = data->player.x;
|
||||||
float ray_y = data->player.y;
|
// float ray_y = data->player.y;
|
||||||
|
//
|
||||||
while(!touch(ray_x, ray_y, data->map))
|
// while(!touch(ray_x, ray_y, data->map))
|
||||||
{
|
// {
|
||||||
my_mlx_pixel_put(data->img_data, (int)(MAP_SIZE * (ray_x / SIZE)), (int)(MAP_SIZE * (ray_y / SIZE)), 0xcc241b);
|
// my_mlx_pixel_put(data->img_data, (int)(MAP_SIZE * (ray_x / SIZE)), (int)(MAP_SIZE * (ray_y / SIZE)), 0xcc241b);
|
||||||
ray_x += sin_angle;
|
// ray_x += sin_angle;
|
||||||
ray_y += cos_angle;
|
// ray_y += cos_angle;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
t_cardinal_dir angle_cardinal_dir(float angle)
|
t_cardinal_dir angle_cardinal_dir(float angle)
|
||||||
{
|
{
|
||||||
|
|
@ -177,7 +163,7 @@ int main(int argc, char **argv)
|
||||||
data.img_data->addr = mlx_get_data_addr(data.img_data->img,
|
data.img_data->addr = mlx_get_data_addr(data.img_data->img,
|
||||||
&data.img_data->bits_per_pixel, &data.img_data->line_length,
|
&data.img_data->bits_per_pixel, &data.img_data->line_length,
|
||||||
&data.img_data->endian);
|
&data.img_data->endian);
|
||||||
init_player(data.map, &(data.player));
|
init_player(&data.player, data.map);
|
||||||
mlx_hook(data.mlx_win, KeyPress, KeyPressMask, keypress_handler, &data);
|
mlx_hook(data.mlx_win, KeyPress, KeyPressMask, keypress_handler, &data);
|
||||||
mlx_hook(data.mlx_win, KeyRelease, KeyReleaseMask,
|
mlx_hook(data.mlx_win, KeyRelease, KeyReleaseMask,
|
||||||
keyrelease_handler, &data);
|
keyrelease_handler, &data);
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,15 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/07/17 15:51:29 by kcolin #+# #+# */
|
/* Created: 2025/07/17 15:51:29 by kcolin #+# #+# */
|
||||||
/* Updated: 2025/07/29 12:01:02 by tchampio ### ########.fr */
|
/* Updated: 2025/07/29 13:28:08 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef PLAYER_H
|
#ifndef PLAYER_H
|
||||||
# define PLAYER_H
|
# define PLAYER_H
|
||||||
|
|
||||||
|
# include "../map/mapdata.h"
|
||||||
|
|
||||||
typedef struct s_vec2
|
typedef struct s_vec2
|
||||||
{
|
{
|
||||||
double x;
|
double x;
|
||||||
|
|
@ -32,4 +34,6 @@ typedef struct s_player
|
||||||
t_vec2 movement;
|
t_vec2 movement;
|
||||||
} t_player;
|
} t_player;
|
||||||
|
|
||||||
|
void init_player(t_player *player, t_mapdata *map);
|
||||||
|
|
||||||
#endif // PLAYER_H
|
#endif // PLAYER_H
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue