sinus speed is displaying frames of the animation now

This commit is contained in:
Filipriec
2025-11-15 22:07:15 +01:00
parent 2753aed573
commit de6facff03
4 changed files with 13 additions and 8 deletions

View File

@@ -1,5 +1,6 @@
// src/game/state.cpp
#include "state.h"
#include <cmath>
#include "../render/player.h"
#include "../timing/speed_controller.h"
@@ -19,8 +20,14 @@ void WalkingState::start_crawl() {
}
// TODO THIS NEEDS REDESIGN ACCORDING TO SPEED
void WalkingState::toggle_walk_frame(int step) {
run_index = (run_index + step) % 7;
void WalkingState::toggle_walk_frame(float player_speed, int tick_counter) {
constexpr int FRAME_COUNT = 8;
float phase_speed = player_speed * 0.1f; // tune this scaling for animation tempo
float phase = fmodf(tick_counter * phase_speed, 1.0f);
int frame = static_cast<int>((1.0f - fabsf(sinf(phase * M_PI))) * (FRAME_COUNT - 1));
run_index = frame;
}
// void RunningState::toggle_run_frame() {
// if (++run_index >= 7) run_index = 0;