Finish
This commit is contained in:
parent
4bd265e213
commit
6cd5b54918
14
game/draw.c
14
game/draw.c
@ -6,7 +6,7 @@
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/11 14:41:48 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/05/11 16:05:42 by erey-bet ### ########.fr */
|
||||
/* Updated: 2023/06/15 12:52:23 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -44,11 +44,11 @@ void draw(t_game *game, t_dda *dda, int x)
|
||||
{
|
||||
int y;
|
||||
|
||||
y = -1;
|
||||
while (++y < dda->draw_start)
|
||||
mlx_put_pixel(game->window, x, y, game->map.color_bot);
|
||||
y = 0;
|
||||
while (y < dda->draw_start && y >= 0 && y < HEIGHT)
|
||||
mlx_put_pixel(game->window, x, y++, game->map.color_bot);
|
||||
draw_texture(game, dda, x);
|
||||
y = dda->draw_end - 1;
|
||||
while (++y < HEIGHT && y > 0)
|
||||
mlx_put_pixel(game->window, x, y, game->map.color_top);
|
||||
y = dda->draw_end;
|
||||
while (y < HEIGHT && y >= 0)
|
||||
mlx_put_pixel(game->window, x, y++, game->map.color_top);
|
||||
}
|
||||
|
19
game/game.c
19
game/game.c
@ -6,13 +6,13 @@
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/26 12:59:53 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/06/13 14:19:08 by erey-bet ### ########.fr */
|
||||
/* Updated: 2023/06/15 12:40:32 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "game.h"
|
||||
|
||||
static int destroy(t_game *game)
|
||||
static void destroy(t_game *game)
|
||||
{
|
||||
if (game->textures[0])
|
||||
{
|
||||
@ -32,17 +32,13 @@ static int destroy(t_game *game)
|
||||
}
|
||||
}
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static void hook(void *param)
|
||||
{
|
||||
t_game *game;
|
||||
|
||||
game = param;
|
||||
//printf("%d\n", mlx_is_key_down(game->mlx, MLX_KEY_ESCAPE));
|
||||
if (manage_keys(game))
|
||||
raycasting(game);
|
||||
}
|
||||
@ -52,17 +48,22 @@ int start_game(t_map map)
|
||||
t_game game;
|
||||
|
||||
if (init(map, &game))
|
||||
return (destroy(&game));
|
||||
{
|
||||
destroy(&game);
|
||||
return (1);
|
||||
}
|
||||
game.window = mlx_new_image(game.mlx, WIDTH, HEIGHT);
|
||||
if (!game.window)
|
||||
{
|
||||
mlx_terminate(game.mlx);
|
||||
return (destroy(&game));
|
||||
destroy(&game);
|
||||
return (1);
|
||||
}
|
||||
if (mlx_image_to_window(game.mlx, game.window, 0, 0) == -1)
|
||||
{
|
||||
mlx_terminate(game.mlx);
|
||||
return (destroy(&game));
|
||||
destroy(&game);
|
||||
return (1);
|
||||
}
|
||||
raycasting(&game);
|
||||
mlx_loop_hook(game.mlx, &hook, &game);
|
||||
|
@ -6,13 +6,13 @@
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/27 14:14:51 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/06/13 13:28:58 by erey-bet ### ########.fr */
|
||||
/* Updated: 2023/06/15 13:00:31 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "game.h"
|
||||
|
||||
void rotate(t_ply *ply, bool right)
|
||||
static int rotate(t_ply *ply, bool right)
|
||||
{
|
||||
double old_dir_x;
|
||||
double old_dir_y;
|
||||
@ -31,41 +31,46 @@ void rotate(t_ply *ply, bool right)
|
||||
ply->dir_y = old_dir_x * sin(speed) + old_dir_y * cos(speed);
|
||||
ply->pla_x = old_plane_x * cos(speed) - old_plane_y * sin(speed);
|
||||
ply->pla_y = old_plane_x * sin(speed) + old_plane_y * cos(speed);
|
||||
return (1);
|
||||
}
|
||||
|
||||
void movement(t_ply *ply, double x, double y)
|
||||
static int movement(t_ply *ply, double x, double y)
|
||||
{
|
||||
ply->pos_x += x;
|
||||
ply->pos_y += y;
|
||||
return (1);
|
||||
}
|
||||
|
||||
int manage_movement(t_game *game)
|
||||
{
|
||||
t_ply *ply;
|
||||
int is_moving;
|
||||
int is_moving;
|
||||
|
||||
ply = &game->ply;
|
||||
is_moving = 1;
|
||||
is_moving = 0;
|
||||
if (mlx_is_key_down(game->mlx, MLX_KEY_W))
|
||||
movement(ply, (ply->dir_x * MOVESPEED), (ply->dir_y * MOVESPEED));
|
||||
else if (mlx_is_key_down(game->mlx, MLX_KEY_S))
|
||||
movement(ply, -(ply->dir_x * MOVESPEED), -(ply->dir_y * MOVESPEED));
|
||||
else if (mlx_is_key_down(game->mlx, MLX_KEY_D))
|
||||
movement(ply, (ply->pla_x * MOVESPEED), (ply->pla_y * MOVESPEED));
|
||||
else if (mlx_is_key_down(game->mlx, MLX_KEY_A))
|
||||
movement(ply, -(ply->pla_x * MOVESPEED), -(ply->pla_y * MOVESPEED));
|
||||
else if (mlx_is_key_down(game->mlx, MLX_KEY_RIGHT))
|
||||
rotate(ply, true);
|
||||
else if (mlx_is_key_down(game->mlx, MLX_KEY_LEFT))
|
||||
rotate(ply, false);
|
||||
else
|
||||
is_moving = 0;
|
||||
is_moving = movement(ply, (ply->dir_x * MOVESPEED),
|
||||
(ply->dir_y * MOVESPEED));
|
||||
if (mlx_is_key_down(game->mlx, MLX_KEY_S))
|
||||
is_moving = movement(ply, -(ply->dir_x * MOVESPEED),
|
||||
-(ply->dir_y * MOVESPEED));
|
||||
if (mlx_is_key_down(game->mlx, MLX_KEY_D))
|
||||
is_moving = movement(ply, (ply->pla_x * MOVESPEED),
|
||||
(ply->pla_y * MOVESPEED));
|
||||
if (mlx_is_key_down(game->mlx, MLX_KEY_A))
|
||||
is_moving = movement(ply, -(ply->pla_x * MOVESPEED),
|
||||
-(ply->pla_y * MOVESPEED));
|
||||
if (mlx_is_key_down(game->mlx, MLX_KEY_RIGHT)
|
||||
|| mlx_is_key_down(game->mlx, MLX_KEY_L))
|
||||
is_moving = rotate(ply, true);
|
||||
else if (mlx_is_key_down(game->mlx, MLX_KEY_LEFT)
|
||||
|| mlx_is_key_down(game->mlx, MLX_KEY_J))
|
||||
is_moving = rotate(ply, false);
|
||||
return (is_moving);
|
||||
}
|
||||
|
||||
int manage_keys(t_game *game)
|
||||
{
|
||||
|
||||
if (mlx_is_key_down(game->mlx, MLX_KEY_ESCAPE))
|
||||
mlx_close_window(game->mlx);
|
||||
if (manage_movement(game))
|
||||
|
@ -12,7 +12,7 @@ C 225,30,0
|
||||
101100000111000000000000001
|
||||
101100000111000000000000001 1111
|
||||
1011000001110000000000000011111100001
|
||||
101100000111000000000000000000000W001
|
||||
101100000111000000000000000000000N001
|
||||
1011000001110000000000000011111100001
|
||||
101100000111000000000000001 10101
|
||||
101100000111000000000000001 11111
|
||||
|
Loading…
Reference in New Issue
Block a user