summaryrefslogtreecommitdiff
path: root/tower.c
diff options
context:
space:
mode:
Diffstat (limited to 'tower.c')
-rw-r--r--tower.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/tower.c b/tower.c
new file mode 100644
index 0000000..882fc60
--- /dev/null
+++ b/tower.c
@@ -0,0 +1,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;
+ }
+}