mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 01:48:08 +01:00
sort of finished movements
This commit is contained in:
parent
4f573baf23
commit
cc12b7554a
3 changed files with 13 additions and 10 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/06/06 17:42:23 by tchampio #+# #+# */
|
/* Created: 2025/06/06 17:42:23 by tchampio #+# #+# */
|
||||||
/* Updated: 2025/07/09 17:05:10 by tchampio ### ########.fr */
|
/* Updated: 2025/07/10 12:02:18 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -16,6 +16,6 @@
|
||||||
# define HEIGHT 800
|
# define HEIGHT 800
|
||||||
# define WIDTH 800
|
# define WIDTH 800
|
||||||
# define RESSOURCE_DIR "ressources"
|
# define RESSOURCE_DIR "ressources"
|
||||||
# define MOVEMENT_SPEED 10.0
|
# define MOVEMENT_SPEED 0.01
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -60,8 +60,8 @@ typedef struct s_mapdata
|
||||||
|
|
||||||
typedef struct s_player
|
typedef struct s_player
|
||||||
{
|
{
|
||||||
float x;
|
double x;
|
||||||
float y;
|
double y;
|
||||||
double yaw;
|
double yaw;
|
||||||
int health;
|
int health;
|
||||||
t_vec2 movement;
|
t_vec2 movement;
|
||||||
|
|
|
||||||
15
src/main.c
15
src/main.c
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/05/06 13:16:11 by tchampio #+# #+# */
|
/* Created: 2025/05/06 13:16:11 by tchampio #+# #+# */
|
||||||
/* Updated: 2025/07/09 17:19:54 by tchampio ### ########.fr */
|
/* Updated: 2025/07/10 12:01:15 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -94,7 +94,7 @@ int keyrelease_handler(int keycode, t_cub3d_data *data)
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_map(t_mapdata *map, t_mlx_data *data)
|
void draw_map(t_mapdata *map, t_player *player, t_mlx_data *data)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
|
|
@ -115,12 +115,14 @@ void draw_map(t_mapdata *map, t_mlx_data *data)
|
||||||
draw_2d_wall(0x00E84545, data, 10 * j, 10 * i);
|
draw_2d_wall(0x00E84545, data, 10 * j, 10 * i);
|
||||||
else if (map->map[i][j] == 'M')
|
else if (map->map[i][j] == 'M')
|
||||||
draw_2d_wall(0x00F4CE14, data, 10 * j, 10 * i);
|
draw_2d_wall(0x00F4CE14, data, 10 * j, 10 * i);
|
||||||
else if (ft_strchr("NSEW", map->map[i][j]))
|
/* else if (ft_strchr("NSEW", map->map[i][j]))
|
||||||
draw_2d_wall(0x00FF0000, data, 10 * j, 10 * i);
|
draw_2d_wall(0x00FF0000, data, 10 * j, 10 * i);
|
||||||
|
*/
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
draw_2d_wall(0x00FF0000, data, 10 * player->x, 10 * player->y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_player(t_mapdata *mapdata, t_player *player)
|
void init_player(t_mapdata *mapdata, t_player *player)
|
||||||
|
|
@ -134,8 +136,9 @@ int game_loop(t_cub3d_data *data)
|
||||||
{
|
{
|
||||||
data->player.x += data->player.movement.x;
|
data->player.x += data->player.movement.x;
|
||||||
data->player.y += data->player.movement.y;
|
data->player.y += data->player.movement.y;
|
||||||
mlx_clear_window(data->mlx, data->mlx_win);
|
mlx_destroy_image(data->mlx, data->mlx_data->img);
|
||||||
draw_map(data->map, data->mlx_data);
|
data->mlx_data->img = mlx_new_image(data->mlx, 800, 600);
|
||||||
|
draw_map(data->map, &data->player, data->mlx_data);
|
||||||
mlx_put_image_to_window(data->mlx, data->mlx_win, data->mlx_data->img, 0, 0);
|
mlx_put_image_to_window(data->mlx, data->mlx_win, data->mlx_data->img, 0, 0);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
@ -156,7 +159,7 @@ int main(int argc, char **argv)
|
||||||
data.mlx_data->addr = mlx_get_data_addr(data.mlx_data->img, &data.mlx_data->bits_per_pixel, &data.mlx_data->line_length, &data.mlx_data->endian);
|
data.mlx_data->addr = mlx_get_data_addr(data.mlx_data->img, &data.mlx_data->bits_per_pixel, &data.mlx_data->line_length, &data.mlx_data->endian);
|
||||||
init_player(data.map, &(data.player));
|
init_player(data.map, &(data.player));
|
||||||
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, keypress_handler, &data);
|
mlx_hook(data.mlx_win, KeyRelease, KeyReleaseMask, keyrelease_handler, &data);
|
||||||
#ifdef BONUS
|
#ifdef BONUS
|
||||||
mlx_string_put(data.mlx, data.mlx_win, 10, 10, 0x00FFFFFF, "compiled with bonuses");
|
mlx_string_put(data.mlx, data.mlx_win, 10, 10, 0x00FFFFFF, "compiled with bonuses");
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue