-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtower.c
More file actions
69 lines (62 loc) · 1.98 KB
/
tower.c
File metadata and controls
69 lines (62 loc) · 1.98 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
/*
** EPITECH PROJECT, 2024
** B-MUL-100-LYN-1-1-myradar-aurelien.demeusy
** File description:
** tower.c
*/
#include <SFML/Graphics.h>
#include <SFML/Window.h>
#include <stdlib.h>
#include "include/structs.h"
#include "include/my.h"
#include <math.h>
void create_tower_sprites(control_tower_t *tower)
{
sfTexture *texture = sfTexture_createFromFile("img/towerr.png", NULL);
control_tower_t *current;
if (!tower)
return;
if (!texture)
return;
for (current = tower; current; current = current->next) {
current->sprite = sfSprite_create();
if (current->sprite) {
sfSprite_setTexture(current->sprite, texture, sfTrue);
sfSprite_setPosition(current->sprite,
(sfVector2f){current->x - 40, current->y -40});
}
}
}
void draw_tower_hitboxes(sfRenderWindow *window, control_tower_t *tower)
{
control_tower_t *current;
sfCircleShape *hitbox = sfCircleShape_create();
sfColor fillColor = sfColor_fromRGBA(255, 0, 0, 128);
sfColor outlineColor = sfColor_fromRGB(0, 255, 0);
float circ_posx;
float circ_posy;
if (!hitbox)
return;
sfCircleShape_setFillColor(hitbox, fillColor);
sfCircleShape_setOutlineColor(hitbox, outlineColor);
for (current = tower; current; current = current->next) {
circ_posx = current->x - current->radius + 39;
circ_posy = current->y - current->radius + 40;
sfCircleShape_setRadius(hitbox, current->radius);
sfCircleShape_setPosition(hitbox, (sfVector2f)
{circ_posx - 40, circ_posy - 40});
sfRenderWindow_drawCircleShape(window, hitbox, NULL);
}
sfCircleShape_destroy(hitbox);
}
void draw_tower_sprites(sfRenderWindow *window, control_tower_t *tower)
{
control_tower_t *current;
if (!window || !tower)
return;
for (current = tower; current; current = current->next) {
if (current->sprite) {
sfRenderWindow_drawSprite(window, current->sprite, NULL);
}
}
}