From 8acfec7d7b4924d0dca8e4563eb0fd64ea6ec6ef Mon Sep 17 00:00:00 2001 From: Abdulmujeeb Raji Date: Fri, 30 Aug 2024 11:39:07 +0100 Subject: [PATCH] Roadmap to MVP + bugfix mouse aiming, now aiming uses ndc instead of world space --- entity.c | 1 + entry_helpless.c | 23 ++++++++++++++++++++++- player.c | 3 +-- util.c | 34 +++++++++++++++++++++++++--------- 4 files changed, 49 insertions(+), 12 deletions(-) diff --git a/entity.c b/entity.c index 86c81c9..3819791 100644 --- a/entity.c +++ b/entity.c @@ -114,4 +114,5 @@ Vector2* entity_resolve_hitbox(Entity* en) { void entity_take_damage(Entity* en, float damage) { en->health = clamp(en->health - damage, 0, en->max_health); + // todo add knockback } \ No newline at end of file diff --git a/entry_helpless.c b/entry_helpless.c index 059dcdd..8a1a701 100644 --- a/entry_helpless.c +++ b/entry_helpless.c @@ -116,8 +116,12 @@ int entry(int argc, char **argv) { } } } + + // TODO Add Armour (one piece set) + + // TODO Animate all this stuff - // TODO Finish dis + // TODO Finish item pickup system // if (en->is_item && is_key_just_pressed('E')) { // Vector2* player_hitbox = entity_resolve_hitbox(player); // Vector2* item_hitbox = entity_resolve_hitbox(en); @@ -127,6 +131,14 @@ int entry(int argc, char **argv) { // } // } + // TODO Add inventory system using item_inv_size + + // TODO Add NPCs you can talk to (dialogue system) + // TODO Add NPCs who sell you stuff (shop system) + // TODO Add choices on what to do with stuff (decision tree system) + + // ONCE ALL TODOs are done, MVP prototype is done, and then you just spam content (enemy AI, bosses, world gen, items, decisions, NPCs) + if (en->is_weapon) { en->weapon_cooldown_secs -= 1.0 * delta_time; // decreases by 1 every second if (is_key_down(MOUSE_BUTTON_LEFT) && en->weapon_cooldown_secs <= 0) { @@ -175,6 +187,11 @@ int entry(int argc, char **argv) { } } + // :background world rendering (TBD when we have world data to load) + { + + } + // :entity rendering for (Entity* en = 0; entity_increment(&en);) { if (en->alive && en->renderable) { @@ -275,6 +292,10 @@ int entry(int argc, char **argv) { Vector2 justified = v2_sub(health_text_pos, v2_divf(health_metrics.functional_size, 2)); draw_text(font, health_text, 48, justified, v2(1, 1), COLOR_WHITE); } + + // TODO Add inventory menu + + // TODO Add dialogue box } os_update(); diff --git a/player.c b/player.c index 1af5925..1c6a91a 100644 --- a/player.c +++ b/player.c @@ -24,8 +24,7 @@ void player_process_input(Entity* player, Entity* player_weapon, float delta_tim player->pos = v2_add(player->pos, v2_mulf(move_axis, 75 * delta_time)); player_weapon->weapon_owner_pos = player->pos; - Vector2 mouse_dir = v2_normalize(mouse_world_pos()); - player_weapon->weapon_dir = v2(mouse_dir.x, mouse_dir.y); + player_weapon->weapon_dir = v2_normalize(get_mouse_pos_in_ndc()); // weapon swapping if (is_key_just_pressed(MOUSE_BUTTON_RIGHT)) { diff --git a/util.c b/util.c index b05da29..0d29867 100644 --- a/util.c +++ b/util.c @@ -17,24 +17,40 @@ bool animate_to_target_v2(Vector2* value, Vector2 target, float delta_time, floa return result_x && result_y; } -Vector2 screen_to_world(Vector2 screen) { +Vector2 get_mouse_pos_in_ndc() { + float mouse_x = input_frame.mouse_x; + float mouse_y = input_frame.mouse_y; Matrix4 proj = draw_frame.projection; Matrix4 view = draw_frame.camera_xform; float window_w = window.width; float window_h = window.height; // Normalize the mouse coordinates - float ndc_x = (screen.x / (window_w * 0.5f)) - 1.0f; - float ndc_y = (screen.y / (window_h * 0.5f)) - 1.0f; + float ndc_x = (mouse_x / (window_w * 0.5f)) - 1.0f; + float ndc_y = (mouse_y / (window_h * 0.5f)) - 1.0f; + + return (Vector2){ ndc_x, ndc_y }; +} + + +Vector2 get_mouse_pos_in_world_space() { + float mouse_x = input_frame.mouse_x; + float mouse_y = input_frame.mouse_y; + Matrix4 proj = draw_frame.projection; + Matrix4 view = draw_frame.camera_xform; + float window_w = window.width; + float window_h = window.height; + + // Normalize the mouse coordinates + float ndc_x = (mouse_x / (window_w * 0.5f)) - 1.0f; + float ndc_y = (mouse_y / (window_h * 0.5f)) - 1.0f; // Transform to world coordinates Vector4 world_pos = v4(ndc_x, ndc_y, 0, 1); world_pos = m4_transform(m4_inverse(proj), world_pos); world_pos = m4_transform(view, world_pos); - - return world_pos.xy; -} + log("%f, %f", world_pos.x, world_pos.y); -Vector2 mouse_world_pos() { - return screen_to_world(v2(input_frame.mouse_x, input_frame.mouse_y)); -} \ No newline at end of file + // Return as 2D vector + return (Vector2){ world_pos.x, world_pos.y }; +}