-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender.c
More file actions
114 lines (105 loc) · 2.93 KB
/
render.c
File metadata and controls
114 lines (105 loc) · 2.93 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* render.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lwanita <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/12 18:11:29 by lwanita #+# #+# */
/* Updated: 2022/01/12 18:11:30 by lwanita ### ########.fr */
/* */
/* ************************************************************************** */
#include "head.h"
#include "list_func.h"
#include "mlx/mlx.h"
#include "render.h"
#include "liba/libft.h"
int eat_all(t_vars *vars)
{
int i;
i = 0;
while ((i < vars->eat_c) && (!vars->eat_map[i].b))
i++;
if (i == vars->eat_c)
return (1);
return (0);
}
void image_pac2(t_vars *vars)
{
if (vars->entity[0].look == 2)
{
mlx_put_image_to_window(vars->mlx, vars->mlxw,
vars->images[4]->image,
30 * vars->entity[0].x, 30 * vars->entity[0].y);
}
else if (vars->entity[0].look == 3)
{
mlx_put_image_to_window(vars->mlx, vars->mlxw,
vars->images[3]->image,
30 * vars->entity[0].x, 30 * vars->entity[0].y);
}
}
void image_pac(t_vars *vars, int frame)
{
if (frame < 10)
{
if (vars->entity[0].look == 0)
{
mlx_put_image_to_window(vars->mlx, vars->mlxw,
vars->images[2]->image,
30 * vars->entity[0].x, 30 * vars->entity[0].y);
}
else if (vars->entity[0].look == 1)
{
mlx_put_image_to_window(vars->mlx, vars->mlxw,
vars->images[5]->image,
30 * vars->entity[0].x, 30 * vars->entity[0].y);
}
else
image_pac2(vars);
}
else
mlx_put_image_to_window(vars->mlx, vars->mlxw,
vars->images[1]->image,
30 * vars->entity[0].x, 30 * vars->entity[0].y);
}
void image_entity(t_vars *vars, int frame)
{
int i;
i = 1;
image_pac(vars, frame);
while (i < vars->entity_c)
{
if (vars->entity[i].type == -4)
mlx_put_image_to_window(vars->mlx, vars->mlxw,
vars->images[7]->image,
30 * vars->entity[i].x, 30 * vars->entity[i].y);
i++;
}
}
void image_static(t_vars *vars, int step)
{
int x;
int y;
y = 0;
while (y < vars->height)
{
x = 0;
while (x < vars->width)
{
if (vars->intm[y][x] == -2)
mlx_put_image_to_window(vars->mlx, vars->mlxw,
vars->images[15]->image, 30 * x, 30 * y);
if (vars->intm[y][x] == -6 && eat_all(vars))
{
mlx_put_image_to_window(vars->mlx, vars->mlxw,
vars->images[16]->image, 30 * x, 30 * y);
if (vars->entity[0].x == x && vars->entity[0].y == y)
vars->game_stat = 2;
}
x++;
}
y++;
}
mlx_string_put(vars->mlx, vars->mlxw, 0, 0, 0, ft_itoa(step));
}