2025-05-05 17:09:11 +02:00
|
|
|
/* ************************************************************************** */
|
|
|
|
|
/* */
|
|
|
|
|
/* ::: :::::::: */
|
|
|
|
|
/* main.c :+: :+: :+: */
|
|
|
|
|
/* +:+ +:+ +:+ */
|
2025-07-17 14:11:30 +02:00
|
|
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
2025-05-05 17:09:11 +02:00
|
|
|
/* +#+#+#+#+#+ +#+ */
|
2025-07-17 14:11:30 +02:00
|
|
|
/* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */
|
2025-08-07 12:35:01 +02:00
|
|
|
/* Updated: 2025/08/07 12:27:47 by tchampio ### ########.fr */
|
2025-05-05 17:09:11 +02:00
|
|
|
/* */
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
2025-07-17 14:11:30 +02:00
|
|
|
#include "../libft/includes/libft.h"
|
2025-06-06 13:57:31 +02:00
|
|
|
#include "../mlx/mlx.h"
|
2025-07-17 14:55:04 +02:00
|
|
|
#include "consts.h"
|
2025-07-28 13:04:32 +02:00
|
|
|
#include "cub3d_data.h"
|
2025-07-29 14:58:30 +02:00
|
|
|
#include "player/move.h"
|
2025-07-17 14:19:34 +02:00
|
|
|
#include "draw/draw_map.h"
|
2025-07-30 16:25:12 +02:00
|
|
|
#include "raycast/raycaster.h"
|
|
|
|
|
#include "renderer/render.h"
|
|
|
|
|
#include "raycast/ray.h"
|
2025-08-06 14:06:15 +02:00
|
|
|
#include "sprites/sprite_caster.h"
|
|
|
|
|
#include "utils/inits.h"
|
2025-08-05 14:17:29 +02:00
|
|
|
#include "sprites/sprite.h"
|
2025-07-17 14:19:34 +02:00
|
|
|
#include "utils/hooks.h"
|
2025-07-31 13:31:05 +02:00
|
|
|
#include "utils/inits.h"
|
2025-07-31 14:07:56 +02:00
|
|
|
#include <bits/types/struct_timeval.h>
|
2025-05-06 13:24:32 +02:00
|
|
|
#include <stdbool.h>
|
2025-07-09 16:45:13 +02:00
|
|
|
#include <X11/keysym.h>
|
|
|
|
|
#include <X11/X.h>
|
2025-05-06 13:24:32 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <fcntl.h>
|
2025-07-31 14:07:56 +02:00
|
|
|
#include "utils/time.h"
|
2025-07-29 10:26:52 +02:00
|
|
|
|
2025-07-09 17:30:16 +02:00
|
|
|
int game_loop(t_cub3d_data *data)
|
|
|
|
|
{
|
2025-07-30 16:25:12 +02:00
|
|
|
t_ray ray;
|
|
|
|
|
|
2025-07-31 14:53:18 +02:00
|
|
|
data->last_tick = get_milliseconds();
|
2025-07-17 14:57:29 +02:00
|
|
|
mlx_destroy_image(data->mlx, data->img_data->img);
|
2025-07-22 12:48:44 +02:00
|
|
|
data->img_data->img = mlx_new_image(data->mlx, WIDTH, HEIGHT);
|
2025-07-30 16:25:12 +02:00
|
|
|
reset_matrix(data);
|
|
|
|
|
raycaster(data, &ray);
|
2025-07-29 14:58:30 +02:00
|
|
|
move_player(data);
|
2025-08-06 14:06:15 +02:00
|
|
|
sprite_caster(data);
|
2025-07-30 16:25:12 +02:00
|
|
|
matrix_to_image(data);
|
2025-07-30 16:35:39 +02:00
|
|
|
draw_map(data->map, &data->player, data->img_data);
|
2025-07-15 10:33:25 +02:00
|
|
|
mlx_put_image_to_window(data->mlx, data->mlx_win,
|
2025-07-17 14:57:29 +02:00
|
|
|
data->img_data->img, 0, 0);
|
2025-07-15 10:33:25 +02:00
|
|
|
mlx_string_put(data->mlx, data->mlx_win, 10, 10, 0x00FFFFFF, COMPILED_TEXT);
|
2025-07-31 14:53:18 +02:00
|
|
|
data->delta = (get_milliseconds() - data->last_tick);
|
|
|
|
|
ft_printf("%d,%d\n", data->last_tick, data->delta);
|
2025-07-09 17:30:16 +02:00
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-05 17:09:11 +02:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
|
{
|
2025-07-15 10:33:25 +02:00
|
|
|
t_cub3d_data data;
|
2025-05-06 12:25:17 +02:00
|
|
|
|
2025-05-05 17:09:11 +02:00
|
|
|
if (argc < 2)
|
2025-06-06 18:38:21 +02:00
|
|
|
return (ft_printf("Error: Missing cub3d file\n"), 1);
|
2025-07-31 13:31:05 +02:00
|
|
|
init_cub3d_data(&data, argv);
|
2025-08-05 14:17:29 +02:00
|
|
|
// placing a sprite next to player to ease debugging
|
2025-08-07 12:35:01 +02:00
|
|
|
data.sprite_list = ft_calloc(sizeof(t_sprite *), 3);
|
|
|
|
|
data.sprite_list[0] = ft_calloc(sizeof(t_sprite), 1);
|
|
|
|
|
data.sprite_list[1] = ft_calloc(sizeof(t_sprite), 1);
|
|
|
|
|
data.sprite_list[0]->x = data.map->startx + 1;
|
|
|
|
|
data.sprite_list[0]->y = data.map->starty;
|
|
|
|
|
data.sprite_list[0]->image = load_single_texture(&data, "ressources/box.xpm");
|
|
|
|
|
data.sprite_list[1]->x = data.map->startx;
|
|
|
|
|
data.sprite_list[1]->y = data.map->starty - 2;
|
|
|
|
|
data.sprite_list[1]->image = load_single_texture(&data, "ressources/test.xpm");
|
2025-07-09 16:45:13 +02:00
|
|
|
mlx_hook(data.mlx_win, KeyPress, KeyPressMask, keypress_handler, &data);
|
2025-07-15 10:33:25 +02:00
|
|
|
mlx_hook(data.mlx_win, KeyRelease, KeyReleaseMask,
|
|
|
|
|
keyrelease_handler, &data);
|
2025-07-09 17:30:16 +02:00
|
|
|
mlx_loop_hook(data.mlx, game_loop, &data);
|
2025-06-24 11:51:49 +02:00
|
|
|
mlx_loop(data.mlx);
|
2025-05-05 17:09:11 +02:00
|
|
|
}
|