-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharacter.c
66 lines (60 loc) · 1.87 KB
/
character.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
/*
** EPITECH PROJECT, 2022
** character
** File description:
** character
*/
#include <SFML/Graphics.h>
#include "header.h"
#include <stdlib.h>
#include <time.h>
void set_vectors(chara *charac, sfVector2f init_pos, games *game)
{
if (init_pos.x < 330)
charac->dir_x = ((double) (rand() % 251)) *
((double) 1 + ((double) game->score / 500 / 10));
if (init_pos.x >= 330 && init_pos.x <= 660)
charac->dir_x = ((double) (rand() % 501) - 250) *
((double) 1 + ((double) game->score / 500 / 10));
if (init_pos.x > 660)
charac->dir_x = ((double) (rand() % 251 - 250)) *
((double) 1 + ((double) game->score / 500 / 10));
charac->dir_y = -300 * ((double) 1 + ((double) game->score / 500 / 10));
}
void set_rect(chara *charac, int origin, int width, int height)
{
charac->rect.top = 0;
charac->rect.left = 0;
charac->rect.width = 110;
charac->rect.height = 110;
}
int set_charac_sprite(chara *charac, char *image_path, sfVector2f init_pos)
{
charac->texture = sfTexture_createFromFile(image_path, NULL);
if (!charac->texture)
return 84;
charac->sprite = sfSprite_create();
sfSprite_setTexture(charac->sprite, charac->texture, sfTrue);
sfSprite_setPosition(charac->sprite, init_pos);
if (charac->dir_x >= 0)
charac->heading = 0;
else {
charac->heading = 1;
move_rect(&charac->rect, 330, 660);
}
return 0;
}
void repos_charac(chara *charac, games *game)
{
sfVector2f init_pos = get_init_pos_ran();
set_vectors(charac, init_pos, game);
sfSprite_setPosition(charac->sprite, init_pos);
if (charac->dir_x >= 0 && charac->heading == 1) {
move_rect(&charac->rect, 0, 330);
charac->heading = 0;
}
if (charac->dir_x < 0 && charac->heading == 0) {
charac->heading = 1;
move_rect(&charac->rect, 330, 660);
}
}