summaryrefslogtreecommitdiff
path: root/src/wall_item.c
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrik@amftech.nl>2022-12-18 11:24:42 +0100
committerAldrik Ramaekers <aldrik@amftech.nl>2022-12-18 11:24:42 +0100
commit1ac44d4ec6b6b51fefe6ca50ef82d5d2fc1f6dfb (patch)
tree8322478a56450878e2f02a6a794a4a664d86e176 /src/wall_item.c
parent89984db7afa433e2842c4ef8c8c265a3e3993636 (diff)
wall items
Diffstat (limited to 'src/wall_item.c')
-rw-r--r--src/wall_item.c84
1 files changed, 82 insertions, 2 deletions
diff --git a/src/wall_item.c b/src/wall_item.c
index a9f556c..b1b7f5d 100644
--- a/src/wall_item.c
+++ b/src/wall_item.c
@@ -1,4 +1,7 @@
#include "../include/wall_item.h"
+#include "../include/players.h"
+#include "../include/keybindings.h"
+#include "../include/asset_defs.h"
static image* get_wallitem_img(wall_item_type item, wall_item_data data) {
switch(item) {
@@ -8,6 +11,23 @@ static image* get_wallitem_img(wall_item_type item, wall_item_data data) {
return 0;
}
+static char* get_wallitem_name(wall_item_type item, wall_item_data data) {
+ switch(item) {
+ case WALLITEM_GUN: return get_gun_by_type(data.gun).name;
+ }
+
+ return 0;
+}
+
+static void apply_wallitem_to_player(wall_item item, player* p) {
+ if (item.item == WALLITEM_GUN) {
+ gun g = get_gun_by_type(item.data.gun);
+ p->guntype = g.type;
+ p->total_ammo = g.max_ammunition;
+ p->ammo_in_mag = g.magazine_size;
+ }
+}
+
void create_wallitem(vec3f position, wall_item_type type, wall_item_data data) {
wall_item item;
item.active = true;
@@ -38,12 +58,72 @@ void update_wallitems() {
}
}
+static float wallspace_entry_time = 0.0f;
+void draw_keybinding_for_wallitem_purchase(platform_window* window, wall_item item) {
+ OVERLAY_RENDER_DEPTH();
+
+ map_info info = get_map_info(window);
+
+ char purchase_text[50];
+ snprintf(purchase_text, 50, "Press %s to purchase %s", keybind_wall_purchase.text, get_wallitem_name(item.item, item.data));
+ int purchase_text_length = renderer->calculate_text_width(fnt_24, purchase_text);
+
+ float center_tilex = item.position.x;
+ float center_tiley = item.position.y - 2.5f;
+ #define KEY_DRAW_W (0.8f)
+ #define KEY_DRAW_H (0.6f)
+ float height = 0.5;
+ if (((int)wallspace_entry_time % 2) == 1) height = 0.1f;
+ box key_box = get_render_box_of_square_without_incline(window, (vec3f){center_tilex - (purchase_text_length/info.tile_width)/2,
+ center_tiley, 0}, (vec3f){KEY_DRAW_W, KEY_DRAW_H, height});
+
+ #define KEY_INSET ((0.12f)*info.tile_width)
+ key_box.tl_u.x += KEY_INSET; key_box.bl_u.x += KEY_INSET;
+ key_box.tl_u.y -= KEY_INSET; key_box.bl_u.y -= KEY_INSET;
+ key_box.tr_u.x -= KEY_INSET; key_box.br_u.x -= KEY_INSET;
+ key_box.tr_u.y -= KEY_INSET; key_box.br_u.y -= KEY_INSET;
+ render_box_with_outline(key_box, rgb(255,255,255));
+
+ int surface_w = key_box.tr_u.x - key_box.tl_u.x;
+ int surface_h = key_box.br_u.y - key_box.tr_u.y;
+
+ int text_w = renderer->calculate_text_width(fnt_24, keybind_wall_purchase.text);
+ renderer->render_text(fnt_24, key_box.tl_u.x + surface_w/2 - text_w/2,
+ key_box.tl_u.y + surface_h/2 - fnt_24->px_h/2, keybind_wall_purchase.text, rgb(0,0,0));
+
+ renderer->render_text(fnt_24, key_box.tr_d.x + 10, key_box.tr_d.y + (surface_h/2) - (fnt_24->px_h/2), purchase_text, rgb(255,255,255));
+
+ wallspace_entry_time += update_delta;
+
+ if (keyboard_is_key_pressed(keybind_wall_purchase.key)) {
+ player* p = get_player_by_id(player_id);
+ if (!p) return;
+ apply_wallitem_to_player(item, p);
+ }
+}
+
void draw_wallitems(platform_window* window) {
for (int i = 0; i < MAX_WALLITEMS; i++) {
wall_item item = wallitems[i];
if (!item.active) continue;
- box box = get_render_box_of_square(window, item.position, (vec3f){1,1,2});
- renderer->render_image(item.img, box.tl_u.x, box.tl_u.y, box.tr_u.x - box.tl_u.x, box.br_u.y - box.tr_u.y);
+ {
+ OBJECT_RENDER_DEPTH((int)item.position.y);
+ box box = get_render_box_of_square(window, item.position, (vec3f){1,1,2});
+ renderer->render_image(item.img, box.tl_u.x, box.tl_u.y, box.tr_u.x - box.tl_u.x, box.br_u.y - box.tr_u.y);
+ }
+
+ player* p = get_player_by_id(player_id);
+ if (!p) continue;
+ float dirx = ((item.position.x + (0.5)) - (p->playerx + (get_player_size_in_tile()/2)));
+ float diry = ((item.position.y) - (p->playery + (get_player_size_in_tile()/2)));
+ float length = sqrt(dirx * dirx + diry * diry);
+
+ if (length < 1.0f) {
+ draw_keybinding_for_wallitem_purchase(window, item);
+ }
+ else {
+ wallspace_entry_time = 0.0f;
+ }
}
} \ No newline at end of file