#pragma once

#include "core/script.hpp"
#include "geometry/general.hpp"

#include "constants.hpp"


struct paddle_script : frog::script
{
    float angle = 0;

    paddle_script(float starting_angle)
        : angle(starting_angle) {}

    void init(frog::game_object& object, frog::engine&) override
    {
        using namespace frog;

        object.model().rot.y() = angle * geo::ToRad;
    }

    void stable_update(frog::game_object& object, frog::engine& engine) override
    {
        using namespace frog;

        double time = engine.global->stable_frame_time();

        if (engine.input->is_down(os::key{ GLFW_KEY_D }))
        {
            angle -= Paddle::Speed * time;
        }

        if (engine.input->is_down(os::key{ GLFW_KEY_A }))
        {
            angle += Paddle::Speed * time;
        }

        object.model().rot.y() = angle * geo::ToRad;
    }
};
