// src/timing/movement_controller.h

#pragma once
#include "mbed.h"

// Handles position of the player relative to ground movement
class MovementController {
private:
    float x_pos;
    const int view_width;

    // Scale factor for translating speed difference to pixel movement
    const float motion_scale = 0.2f;

public:
    MovementController(int start_x, int width) : x_pos(static_cast<float>(start_x)), view_width(width) {}

    void reset(int start_x) { x_pos = static_cast<float>(start_x); }

    void update_position(int player_speed, int ground_speed) {
        int delta = player_speed - ground_speed;
        x_pos += static_cast<float>(delta) * motion_scale;

        if (x_pos < 0) x_pos = 0;
        if (x_pos > (VIEW_WIDTH - 10)) x_pos = static_cast<float>(VIEW_WIDTH - 10);
    }

    int get_position() const { return static_cast<int>(x_pos); }
};
