#include "cube3d.h" t_game *init_game(void) { t_game *game; game = mb_alloc(sizeof(t_game)); game->cell = 20; // player first position game->plr_exact_x = 2 * game->cell; game->plr_exact_y = 2 * game->cell; game->plr_x = game->plr_exact_x; game->plr_y = game->plr_exact_y; // rotation game->rot = 0; game->cosi = 0; game->cosj = 0; game->sini = 0; game->sinj = 0; // map size game->map_size_x = 24; game->map_size_y = 24; // size window game->win_size_x = game->map_size_x * game->cell; game->win_size_y = game->map_size_y * game->cell; // init connexion to server game->mlx_ptr = mlx_init(); mb_add(game->mlx_ptr); // create the window game->win_ptr = mlx_new_window(game->mlx_ptr, game->win_size_x, game->win_size_y, "test"); // k(ey)_hook is the array containing the values of key press events ft_bzero(&game->k_hook, sizeof(game->k_hook)); // map int tmp[24][24] = { {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,1,0,1,0,1,0,0,0,1}, {1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,1,0,0,0,1}, {1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,1,1,0,1,1,0,0,0,0,1,0,1,0,1,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, {1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, {1,1,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, {1,1,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, {1,1,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, {1,1,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, {1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, }; int i = 0; game->map = mb_alloc(sizeof(char*) * (game->map_size_y + 1)); (game->map)[game->map_size_y] = NULL; while (i < 24) { (game->map)[i] = mb_alloc(sizeof(char) * (game->map_size_x + 1)); (game->map)[i][game->map_size_x] = '\0'; i++; } int j; i = 0; while (i < game->map_size_y) { j = 0; while (j < game->map_size_x) { (game->map)[i][j] = tmp[i][j] + '0'; j++; } i++; } // draw screen dist game->screen_dist.start_x = 0; game->screen_dist.start_y = 0; game->screen_dist.end_x = 0; game->screen_dist.end_y = -SCREEN_DIST; // draw screen size game->screen_size.start_x = -SCREEN_SIZE / 2; game->screen_size.start_y = -SCREEN_DIST; game->screen_size.end_x = SCREEN_SIZE / 2; game->screen_size.end_y = -SCREEN_DIST; // draw ray game->ray.start_x = 0; game->ray.start_y = 0; game->ray.end_x = -SCREEN_SIZE / 2; game->ray.end_y = -SCREEN_DIST; // tmp game->ray_highlight = -1; game->ray_activ = 0; // create image and get its data address game->img_ptr = mlx_new_image(game->mlx_ptr, game->win_size_x, game->win_size_y); game->img_data = mlx_get_data_addr(game->img_ptr, &(game->bpp), &(game->sizel), &(game->endian)); return (game); }