-
Notifications
You must be signed in to change notification settings - Fork 0
/
player_mouvement.c
74 lines (67 loc) · 2.15 KB
/
player_mouvement.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* player_mouvement.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hgrissen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/01/21 17:11:55 by hgrissen #+# #+# */
/* Updated: 2021/02/19 11:38:16 by hgrissen ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
void damage(int newx, int newy)
{
int dmg;
dmg = g_healthmax / DMG;
if ((is_sprite(g_p.x, newy) || is_sprite(newx, g_p.y)) && g_damageable)
{
printf("damage is : %d\n", dmg);
printf("max health is : %d\n", g_healthmax);
printf("actual health is : %d\n", g_healthmax - g_dmg);
g_dmg += dmg;
g_damageable = 0;
if (g_dmg >= g_healthmax)
{
printf("GAME OVER!!!!!!");
ft_quit();
//kill(g_damage_sf);
}
g_post = 1;
play_damage_sfx();
}
else if (!is_sprite(g_p.x, g_p.y))
g_damageable = 1;
}
void move(void)
{
float newx;
float newy;
float move_step;
g_p.rotang += (g_p.turndir * g_p.turnspeed);
move_step = g_p.vir_dir * g_p.movespeed;
newx = g_p.x + cos(g_p.rotang + g_p.hlfpi) * (move_step);
newy = g_p.y + sin(g_p.rotang + g_p.hlfpi) * (move_step);
if (g_x && g_p.iscrouch)
{
g_p.crouch += CROUCH;
g_x = 0;
}
if (!g_p.iscrouch && !g_x)
{
g_p.crouch -= CROUCH;
g_x = 1;
}
collision(newx, newy);
if (BON)
damage(newx, newy);
}
void collision(float newx, float newy)
{
if ((!is_wall(g_p.x, newy + COL_DIS)) && (!is_wall(g_p.x, newy - COL_DIS))
/*&& !is_sprite(g_p.x, newy)*/)
g_p.y = newy;
if ((!is_wall(newx + COL_DIS, g_p.y)) && (!is_wall(newx - COL_DIS, g_p.y))
/*&& !is_sprite(newx, g_p.y)*/)
g_p.x = newx;
}