-
Notifications
You must be signed in to change notification settings - Fork 0
/
wolf.c
85 lines (78 loc) · 2.27 KB
/
wolf.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "wolf.h"
#include <stdio.h>
int ft_wolf(t_env *w)
{
int x;
x = 0;
clear_image(w);
ft_find_path(w);
while (x < WIDTH)
{
set_ray_init(&(w->player), &(w->rc), x);
set_step_dist(&(w->rc));
wall_hit(&(w->rc), w->map);
set_wall_height(w, &(w->rc));
ft_draw_text(w, x);
color_floor_celing(w, x);
x++;
}
calc_frame_and_speed(w);
ft_movement(w);
draw_map(w);
set_crossing(w);
mlx_put_image_to_window(w->mlx, w->win, w->img, 0, 0);
ft_draw_controls(w);
make_new_maze(w);
return (0);
}
void create_win_and_text(t_env *w)
{
void *temp;
int b;
w->mlx = mlx_init();
w->win = mlx_new_window(w->mlx, WIDTH, HEIGHT, "Wolf3D");
w->img = mlx_new_image(w->mlx, WIDTH, HEIGHT);
w->text = (int **)malloc(sizeof(int *) * 4);
temp = mlx_xpm_file_to_image(w->mlx, "2.xpm", &(w->t_h[0]), &(w->t_w[0]));
w->text[0] = (int *)mlx_get_data_addr(temp, &b, &b, &b);
temp = mlx_xpm_file_to_image(w->mlx, "1.xpm", &(w->t_h[1]), &(w->t_w[1]));
w->text[1] = (int *)mlx_get_data_addr(temp, &b, &b, &b);
temp = mlx_xpm_file_to_image(w->mlx, "3.xpm", &(w->t_h[2]), &(w->t_w[2]));
w->text[2] = (int *)mlx_get_data_addr(temp, &b, &b, &b);
temp = mlx_xpm_file_to_image(w->mlx, "3.xpm", &(w->t_h[3]), &(w->t_w[3]));
w->text[3] = (int *)mlx_get_data_addr(temp, &b, &b, &b);
w->data = (int *)mlx_get_data_addr(w->img, &b, &b, &b);
}
int main(void)
{
t_env w;
start_generation(&w);
ft_write_path_map(&w);
w.player.player_x = 2.5;
w.player.player_y = 2.5;
w.player.dir_x = -1;
w.player.dir_y = 0;
w.player.plane_x = 0;
w.player.plane_y = 0.66;
w.player.speed_const = 2.5;
w.flag.flag_w = 0;
w.flag.flag_l = 0;
w.flag.flag_r = 0;
w.flag.flag_s = 0;
w.path_activated = 0;
w.rc.time = 0.0;
w.rc.old_time = 0.0;
create_win_and_text(&w);
mlx_hook(w.win, 2, 1, press_key, &w);
mlx_hook(w.win, 3, 2, release_key, &w);
mlx_loop_hook(w.mlx, ft_wolf, &w);
mlx_loop(w.mlx);
return (0);
}
void ft_draw_controls(t_env *world)
{
mlx_string_put(world->mlx, world->win, 10, HEIGHT - 70, 0x00FFFF00, "W/A/S/D to move");
mlx_string_put(world->mlx, world->win, 10, HEIGHT - 60, 0x00FFFF00, "Lelft Shift to accelerate");
mlx_string_put(world->mlx, world->win, 10, HEIGHT - 50, 0x00FFFF00, "Ctrl to slow down movement");
mlx_string_put(world->mlx, world->win, 10, HEIGHT - 40, 0x00FFFF00, "ESC to exit");
}