-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw_game.c
96 lines (89 loc) · 2.6 KB
/
draw_game.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
86
87
88
89
90
91
92
93
94
95
96
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* draw_game.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmadau <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/09/12 14:32:24 by tmadau #+# #+# */
/* Updated: 2018/09/18 15:32:55 by tmadau ### ########.fr */
/* */
/* ************************************************************************** */
#include "wolf3d.h"
void draw_floor(t_sdl *var, t_raycast *op)
{
var->count_j = var->draw_end + 1;
while (var->count_j <= op->height)
{
REND_COLOR(var->renderer, 163, 94, 48, 0);
SDL_RenderDrawPoint(var->renderer, op->count_x, var->count_j);
var->count_j++;
}
}
void draw_ceiling(t_sdl *var, t_raycast *op)
{
var->count_j = var->draw_end + 1;
while (var->count_j <= op->height)
{
REND_COLOR(var->renderer, 0, 135, 255, 0);
SDL_RenderDrawPoint(var->renderer, op->count_x, op->height -
var->count_j);
var->count_j++;
}
draw_floor(var, op);
}
void ft_render_stuff(t_sdl *var, t_raycast *op)
{
draw_ceiling(var, op);
if (SDX > 2)
SDX = 2;
if (SDY > 2)
SDY = 2;
var->count_y = var->draw_start;
if (op->side == 0)
REND_COLOR(var->renderer, 186 / SDX, 133 / SDX, 0, ALP_OPQ);
if (op->side != 0)
REND_COLOR(var->renderer, 214 / SDY, 64 / SDY, 0, ALP_OPQ);
if (op->side == 0 && op->ray_dir_x < 0)
REND_COLOR(var->renderer, 255 / SDX, 218 / SDX, 168 / SDX, ALP_OPQ);
if (op->side == 1 && op->ray_dir_y < 0)
REND_COLOR(var->renderer, 0xFF / SDY, 0x9f / SDY, 0, ALP_OPQ);
while (var->count_y < var->draw_end)
{
SDL_RenderDrawPoint(var->renderer, op->count_x, var->count_y);
var->count_y++;
}
}
void ft_do_stuff(t_raycast *op, t_sdl *var, t_map *in)
{
ft_ray_calc(op);
ft_side_dist_calc(op);
ft_dda_calc(op, in);
ft_draw_stuff(op, var);
ft_render_stuff(var, op);
}
int place_player(t_map *in, t_raycast *op)
{
int c;
int i;
int space;
c = -1;
space = 0;
while (++c < in->get_y - 1 && space != 1)
{
i = -1;
while (i++ < in->get_x - 1)
{
if (in->map[c][i] == 0)
{
op->pos_x = c + 0.5;
op->pos_y = i + 0.5;
space = 1;
break ;
}
}
}
if (space == 0)
return (0);
return (1);
}