-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw_cell.c
75 lines (67 loc) · 2.17 KB
/
draw_cell.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* draw_cell.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jchapell <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/30 03:09:11 by lebojo #+# #+# */
/* Updated: 2023/06/01 04:28:27 by jchapell ### ########.fr */
/* */
/* ************************************************************************** */
#include "inc/proto.h"
int draw_player(t_level *l)
{
t_vector pos;
int f;
pos = l->player.pos;
f = l->tx.pf.nb;
draw_image(l, l->tx.player[f], pos);
return (0);
}
int draw_coins(t_level *l, t_vector pos)
{
int f;
f = l->tx.cf.nb;
draw_image(l, l->tx.coins[f], pos);
return (0);
}
int draw_cell(t_level *lvl, char c, t_vector pos)
{
if (c == '\n')
return (0);
if ((pos.x == pos.y * 3 || pos.y == pos.x * 2) && c == lvl->data.empty)
draw_image(lvl, lvl->tx.empty[1], pos);
else
draw_image(lvl, lvl->tx.empty[0], pos);
if (c == lvl->data.coins)
draw_coins(lvl, pos);
else if (c == lvl->data.exit)
draw_image(lvl, lvl->tx.exit, pos);
else if (c == lvl->data.wall && pos.y - 1 < lvl->player.pos.y)
draw_image(lvl, lvl->tx.wall, pos);
else if (c == lvl->data.enemy)
draw_image(lvl, lvl->tx.enemy, pos);
return (1);
}
void draw_wall(t_level *l)
{
t_vector pos;
t_vector cursor;
set_vector(&cursor, l->player.pos.x / 32, l->player.pos.y / 32);
set_vector(&pos, cursor.x * 32, (cursor.y + 1) * 32);
while (cursor.y < l->data.size.y)
{
cursor.x = 1;
pos.x = 0;
while (cursor.x <= l->data.size.x)
{
if (l->map_matrix[cursor.y][cursor.x] == l->data.wall)
draw_image(l, l->tx.wall, pos);
pos.x += l->tx.width;
cursor.x++;
}
pos.y += l->tx.width;
cursor.y++;
}
}