#include "player.h"

#include "world.h"
#include "config.h"

#include "raylib.h"

// let's a go!
float curhorvel=0.0f; //current horizonatal velocity
void UpdatePlayerControls(void)
{
    // if there isn't a player, you probably can't do much
    if (!player){
        return;
    }
    if(curhorvel==0.0f){
        curhorvel=10.0f*scale;
    }
    // if a key pressed, push player to the left
    if (IsKeyDown(KEY_A))
    {
        if(curhorvel<PMV){
            curhorvel=curhorvel*PLAYER_SPEED_FACTOR;
        }
        ApplyForce(
            player,
            (Vector2){-curhorvel, 0}
        );
    }
    // if d key pressed, push player to the right
    else if (IsKeyDown(KEY_D))
    {
        if(curhorvel<=PMV){
            curhorvel=curhorvel*PLAYER_SPEED_FACTOR;
        }
        ApplyForce(
            player,
            (Vector2){curhorvel, 0}
       );
    }
    else{
        curhorvel=10.0f*scale;
    }
    // if sspace key pressed (and player isn't already jumping), push player
    if (IsGrounded(player) &&
        IsKeyPressed(KEY_SPACE))
    {
        player->velocity.y = 0;

        ApplyForce(
            player,
            (Vector2){0, -JUMP_FORCE}
        );
    }
}
