Roadmap to MVP + bugfix mouse aiming, now aiming uses ndc instead of world space
This commit is contained in:
parent
1c9ca3be5a
commit
8acfec7d7b
4 changed files with 49 additions and 12 deletions
1
entity.c
1
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
|
||||
}
|
|
@ -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();
|
||||
|
|
3
player.c
3
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)) {
|
||||
|
|
34
util.c
34
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));
|
||||
}
|
||||
// Return as 2D vector
|
||||
return (Vector2){ world_pos.x, world_pos.y };
|
||||
}
|
||||
|
|
Reference in a new issue