#include "Keys.h"

Keys gameControls;

void initKeys()
{
    gameControls.controlFlags = 0;
}

void setDefaultKeys()
{
    gameControls.left = Key_CursorLeft;
    gameControls.right = Key_CursorRight;
    gameControls.up = Key_CursorUp;
    gameControls.down = Key_CursorDown;
    gameControls.shoot = Key_Space;
    gameControls.exit = Key_Esc;
    gameControls.use = Key_X;
    gameControls.jump = Key_Z;
}

void readGameControls()
{
    if (cpct_isKeyPressed(gameControls.up))
    {
        gameControls.controlFlags |= CONTROL_UP_FLAG;
    }
    else
    {
        gameControls.controlFlags &= ~CONTROL_UP_FLAG;
    }

    if (cpct_isKeyPressed(gameControls.down))
    {
        gameControls.controlFlags |= CONTROL_DOWN_FLAG;
    }
    else
    {
        gameControls.controlFlags &= ~CONTROL_DOWN_FLAG;
    }

    if (cpct_isKeyPressed(gameControls.left))
    {
        gameControls.controlFlags |= CONTROL_LEFT_FLAG;
    }
    else
    {
        gameControls.controlFlags &= ~CONTROL_LEFT_FLAG;
    }

    if (cpct_isKeyPressed(gameControls.right))
    {
        gameControls.controlFlags |= CONTROL_RIGHT_FLAG;
    }
    else
    {
        gameControls.controlFlags &= ~CONTROL_RIGHT_FLAG;
    }

    if (cpct_isKeyPressed(gameControls.use))
    {
        gameControls.controlFlags |= CONTROL_USE_FLAG;
    }
    else
    {
        gameControls.controlFlags &= ~CONTROL_USE_FLAG;
    }

    if (cpct_isKeyPressed(gameControls.shoot))
    {
        gameControls.controlFlags |= CONTROL_SHOOT_FLAG;
    }
    else
    {
        gameControls.controlFlags &= ~CONTROL_SHOOT_FLAG;
    }

    if (cpct_isKeyPressed(gameControls.jump))
    {
        gameControls.controlFlags |= CONTROL_JUMP_FLAG;
    }
    else
    {
        gameControls.controlFlags &= ~CONTROL_JUMP_FLAG;
    }

    if (cpct_isKeyPressed(gameControls.exit))
    {
        gameControls.controlFlags |= CONTROL_EXIT_FLAG;
    }
    else
    {
        gameControls.controlFlags &= ~CONTROL_EXIT_FLAG;
    }
}