From 7076731c7f72fc4ea3049626475483e91aa11344 Mon Sep 17 00:00:00 2001 From: realtradam Date: Tue, 30 May 2023 04:28:14 -0400 Subject: make input normalized and deltad --- src/input.c | 5 +++-- src/player.c | 31 ++++++++++++++++++++++--------- src/sprite.c | 2 +- src/sprite.h | 2 +- 4 files changed, 27 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/input.c b/src/input.c index 5d7571f..ba355fa 100644 --- a/src/input.c +++ b/src/input.c @@ -2,6 +2,7 @@ #include "input.h" #include "rodeo/input.h" #include "rodeo/audio.h" +#include "cglm/vec2.h" scenes_and_commands_t inputs = {0}; @@ -40,10 +41,10 @@ units_move_generic_input( if(submit_inputs) { *move = 0.0f; - *move += (should_be_positive ? 1 : -1) * (float)*binary_key * 5.0f; + *move += (should_be_positive ? 1 : -1) * (float)*binary_key; *move += (*unbounded_range); *unbounded_range = 0.0f; - *move += ((*bounded_range) * 15.0f); + *move += ((*bounded_range) * 3); } if(input_state != NULL) { diff --git a/src/player.c b/src/player.c index b471fbf..9d1e01e 100644 --- a/src/player.c +++ b/src/player.c @@ -9,6 +9,8 @@ #include "cglm/vec2.h" #include "wall.h" +#include + struct player_t { sprite_t sprite; @@ -147,12 +149,23 @@ parse_player_input(void) // if you arent mid jump, then record attempted movement if(player.move_state != mv_state_jumping) { - float input_lr = (*(float*)units_move_right_input(NULL, NULL) + *(float*)units_move_left_input(NULL, NULL)); - float input_ud = (*(float*)units_move_down_input(NULL, NULL) + *(float*)units_move_up_input(NULL, NULL)); - player_position->dx = input_lr * (rodeo_frame_time_get() / (1000.0f/60.0f) * ((60.0f - (float)player.sprite.iter) / 60.0f)); - player_position->dy = input_ud * (rodeo_frame_time_get() / (1000.0f/60.0f) * ((60.0f - (float)player.sprite.iter) / 60.0f)); + vec2 inputs = { + (*(float*)units_move_right_input(NULL, NULL) + *(float*)units_move_left_input(NULL, NULL)), + (*(float*)units_move_down_input(NULL, NULL) + *(float*)units_move_up_input(NULL, NULL)) + }; + if(glm_vec2_norm(inputs) > 1) + { + glm_vec2_normalize(inputs); + } + rodeo_log( + rodeo_logLevel_info, + "%f, %f", + inputs[0], inputs[1] + ); + player_position->dx = inputs[0] * (rodeo_frame_time_get() / (1000.0f/60.0f) * ((60.0f - (float)player.sprite.iter) / 60.0f)) * 7; + player_position->dy = inputs[1] * (rodeo_frame_time_get() / (1000.0f/60.0f) * ((60.0f - (float)player.sprite.iter) / 60.0f)) * 7; - if(((input_lr != 0) || (input_ud != 0)) && player.move_state == mv_state_standing) + if(((inputs[0] != 0) || (inputs[1] != 0)) && player.move_state == mv_state_standing) { player.move_state = mv_state_jumping; player_position->dy = 0; @@ -168,18 +181,18 @@ move_player(void) { if(player.move_state != mv_state_standing) { - player.sprite.iter += 1; - player.sprite.iter %= player.sprite.config.count; + player.sprite.iter += 1 * rodeo_frame_time_get() / (1000.0f/60.0f); + player.sprite.iter = fmodf(player.sprite.iter, (float)player.sprite.config.count); if(player.sprite.iter > 19) { player.move_state = mv_state_mid_air; } } - if(player.sprite.iter == 60) + if((uint32_t)player.sprite.iter == 60) { player.move_state = mv_state_standing; } - if(player.sprite.iter == 1) + if((uint32_t)player.sprite.iter == 1) { rodeo_audio_sound_play(bubbles_sound); } diff --git a/src/sprite.c b/src/sprite.c index cf7d22d..d966da9 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -13,7 +13,7 @@ draw_sprite(sprite_t *sprite, float x, float y, float scale, rodeo_color_RGBAFlo .height = (float)sprite->config.height * scale }, &(rodeo_rectangle_t){ - .x = (float)sprite->config.width * (float)sprite->iter, + .x = (float)sprite->config.width * (float)(uint32_t)sprite->iter, .y = 0, .width = (float)sprite->config.width, .height = (float)sprite->config.height diff --git a/src/sprite.h b/src/sprite.h index c6656e6..9a44ea3 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -5,7 +5,7 @@ typedef struct { - uint32_t iter; + float iter; struct config { uint32_t width; -- cgit v1.2.3