summaryrefslogtreecommitdiff
path: root/tower.c
blob: 882fc604f326181e64fb0c22f7f154b9a8b36b1d (plain)
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
#include "tower.h"

Sound BEAM_SOUND;

tower_t make_tower(int damage, int range, int x, int y, int width, int height, Texture2D *texture){
    return (tower_t) {
        .texture = texture,
        .damage = damage,
        .range = range,
        .position = (Vector2){ x, y },
        .size = (Vector2){ width, height },
        .center = (Vector2){ x + width / 2, y + height / 2},
        .cooldown = 0.0,
        .cooldown_max = 1.0
    };
}

tower_beam_t make_beam(Vector2 src, Vector2 dest, float live_time){
    return (tower_beam_t){ .src = src, .dest = dest, .live_time = live_time };
}

char _tower_cooldown_text[16];
void draw_tower(tower_t *tower){
    DrawTexture(*tower->texture, tower->position.x, tower->position.y, WHITE);
    /* DrawRectangleV(tower->position, tower->size, BLUE); */
    DrawCircleLinesV(tower->center, tower->range, LIGHTGRAY);
    const Vector2 p = tower->position;
    const Vector2 s = tower->size;
    DrawRectangle(p.x, p.y - 15, s.x * ((tower->cooldown_max - tower->cooldown) / tower->cooldown_max), 5, BLUE);
    DrawRectangleLines(p.x, p.y - 15, s.x, 5, BLACK);
    /* snprintf(_tower_cooldown_text, 16, "%.2f", tower->cooldown);
       DrawText(_tower_cooldown_text, tower->position.x + (tower->size.x / 2), tower->position.y - 25, 10, LIGHTGRAY); */
}

void update_tower(tower_t *t, float dt){
    if (t->cooldown > 0){
        t->cooldown -= dt;
    }
}