sinus speed is displaying frames of the animation now
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -23,7 +23,7 @@ private:
|
||||
public:
|
||||
void update();
|
||||
void start_crawl();
|
||||
void toggle_walk_frame(int step);
|
||||
void toggle_walk_frame(float player_speed, int tick_counter);
|
||||
|
||||
FrameSelection get_frame_selection() const;
|
||||
PlayerState get_state() const { return current_state; }
|
||||
|
||||
@@ -22,5 +22,5 @@ int main(void) {
|
||||
printf("Baud: %d, Format: 8-N-1\r\n", BAUD_RATE);
|
||||
|
||||
// Just call into render feature
|
||||
render_loop(1);
|
||||
render_loop(6);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ void render_loop(int speed) {
|
||||
bool need_redraw = false;
|
||||
|
||||
int tick_counter = 0;
|
||||
int player_speed = 3;
|
||||
int player_speed = 4;
|
||||
|
||||
while (true) {
|
||||
tick_counter++;
|
||||
@@ -66,9 +66,7 @@ void render_loop(int speed) {
|
||||
|
||||
|
||||
if (player_state.get_state() != PlayerState::Crawl) {
|
||||
int step = timing.frame_advance_for(player_speed, tick_counter);
|
||||
if (step > 0)
|
||||
player_state.toggle_walk_frame(step);
|
||||
player_state.toggle_walk_frame(player_speed, tick_counter);
|
||||
}
|
||||
|
||||
ThisThread::sleep_for(50ms);
|
||||
|
||||
Reference in New Issue
Block a user