add documentation

This commit is contained in:
2022-04-13 00:59:23 -04:00
parent 219b277e5c
commit 1c24ba0cd1
12 changed files with 529 additions and 30 deletions

View File

@@ -10,21 +10,51 @@
/**
* @brief This is the godot namespace for all the code included in the library.
*
* @details This namespace is used a prefix when the Godot engine looks for classes, methods, and properties.
*/
namespace godot
{
/**
* @brief This namespace contains the global variables related to the player and its states.
*
*/
namespace player
{
/**
* @brief The default sprite resource of the player.
*
*/
const char player_sprite_frames[] = "res://characters/player/sprites/green.tres";
/**
* @brief The default speed of the player.
*
*/
const float speed = 60.0;
/**
* @brief The default jump force applied when jumping.
*
*/
const float jump_force = 300.0;
/**
* @brief The default gravity applied to the player.
*
*/
const float gravity = 9.81;
/**
* @brief The default run speed multiplier.
*
*/
const float run_speed = 2.0;
/**
* @brief The default double jump activation state.
*
*/
const bool double_jump = true;
/**
* @brief This class is used to control the player.
*
* @details This class allows the player to move, run, and jump as well as controls the sprite displayed for those actions.
*/
class Player : public KinematicBody2D
@@ -34,75 +64,93 @@ namespace godot
private:
/**
* @brief ResourceLoader singleton.
*
*/
ResourceLoader *_resource_loader;
/**
* @brief The animated sprite connected to the KinematicBody2D.
*
*/
AnimatedSprite *animated_sprite;
/**
* @brief The sprite frames used in the animated sprite.
*
*/
Ref<SpriteFrames> sprite_frames;
/**
* @brief The coins the player has collected.
*
*/
uint8_t coins;
/**
* @brief The velocity at which moves the player moves.
*
*/
Vector2 velocity;
/**
* @brief The speed that the player moves in.
*
*/
float speed;
/**
* @brief The force applied to the player when jumping.
*
*/
float jump_force;
/**
* @brief The gravity applied to the player.
*
*/
float gravity;
/**
* @brief The speed multiplier used to make the player move faster.
*
*/
float run_speed;
/**
* @brief If double jump is enabled or not.
*
*/
bool double_jump;
public:
/**
* @brief This method registers classes with Godot.
*
* @details This method registers methods, properties, and signals with the Godot engine.
*/
static void _register_methods();
/**
* @brief Construct a new Player object.
*
*/
Player();
/**
* @brief Destroy the Player object.
*
*/
~Player();
/**
* @brief Initialize the class from Godot.
*
* @details This method is called just once when the Godot engine connects to the instance of the class.
*/
void _init();
/**
* @brief Code to be run when ready.
*
* @details This method is run when all the children of this node are ready.
*/
void _ready();
/**
* @brief This class handles the physics processing.
*
* @details Every delta time, this function is called to check for input and update positioning.
*
* @param[in] delta The difference in time that passed since the last call to this method.
@@ -179,10 +227,33 @@ namespace godot
*/
float get_run_speed();
/**
* @brief Set the double jump object.
*
* @param[in] double_jump The new double dump value.
*/
void set_double_jump(bool double_jump);
/**
* @brief Get the double jump object.
*
* @return true If double jump is enabled.
* @return false If double jump is disabled.
*/
bool get_double_jump();
/**
* @brief Set the velocity object.
*
* @param[in] velocity The new velocity of the player.
*/
void set_velocity(Vector2 velocity);
/**
* @brief Get the velocity object.
*
* @return Vector2 Returns the velocity of the player.
*/
Vector2 get_velocity();
};
}

View File

@@ -7,35 +7,80 @@
#include <Input.hpp>
#include <AnimatedSprite.hpp>
/**
* @brief This is the godot namespace for all the code included in the library.
*
* @details This namespace is used a prefix when the Godot engine looks for classes, methods, and properties.
*/
namespace godot
{
namespace player
{
/**
* @brief This class controls what happens when the player is in a falling state.
*
*/
class PlayerFall : public State
{
GODOT_CLASS(PlayerFall, State)
private:
/**
* @brief Input singleton.
*
*/
Input *_input;
/**
* @brief The animated sprite connected to the player.
*
*/
AnimatedSprite *animated_sprite;
public:
/**
* @brief This method registers classes with Godot.
*
* @details This method registers methods, properties, and signals with the Godot engine.
*/
static void _register_methods();
/**
* @brief Construct a new Player Fall object.
*
*/
PlayerFall();
/**
* @brief Destroy the Player Fall object.
*
*/
~PlayerFall();
/**
* @brief Initialize the class from Godot.
*
* @details This method is called just once when the Godot engine connects to the instance of the class.
*/
void _init();
/**
* @brief Called when the fall state is entered.
*
*/
void _state_enter();
/**
* @brief Called when the fall state is exited.
*
*/
void _state_exit();
/**
* @brief The physics processed every delta time.
*
* @param[in] delta The time since the method was last run.
*/
void _physics_process(float delta);
};
}

View File

@@ -12,31 +12,70 @@ namespace godot
{
namespace player
{
/**
* @brief This class controls what happens when the player is in the idle state.
*
*/
class PlayerIdle : public State
{
GODOT_CLASS(PlayerIdle, State)
private:
/**
* @brief Input singleton.
*
*/
Input *_input;
/**
* @brief The animated sprite of the player.
*
*/
AnimatedSprite *animated_sprite;
public:
/**
* @brief This method registers classes with Godot.
*
* @details This method registers methods, properties, and signals with the Godot engine.
*/
static void _register_methods();
/**
* @brief Construct a new Player Idle object.
*
*/
PlayerIdle();
/**
* @brief Destroy the Player Idle object.
*
*/
~PlayerIdle();
/**
* @brief Initialize the class from Godot.
*
* @details This method is called just once when the Godot engine connects to the instance of the class.
*/
void _init();
/**
* @brief Called when the idle state is entered.
*
*/
void _state_enter();
/**
* @brief Called when the idle state is exited.
*
*/
void _state_exit();
/**
* @brief The physics processed every delta time.
*
* @param[in] delta The time since the method was last run.
*/
void _physics_process(float delta);
};
}

View File

@@ -11,32 +11,78 @@ namespace godot
{
namespace player
{
/**
* @brief This class control what happens when the player is in the jump state.
*
*/
class PlayerJump : public State
{
GODOT_CLASS(PlayerJump, State)
private:
/**
* @brief Input singleton.
*
*/
Input *_input;
/**
* @brief The animated sprite connected to the player.
*
*/
AnimatedSprite *animated_sprite;
/**
* @brief If the player has already performed a double jump or not.
*
*/
bool double_jumped;
public:
/**
* @brief This method registers classes with Godot.
*
* @details This method registers methods, properties, and signals with the Godot engine.
*/
static void _register_methods();
/**
* @brief Construct a new Player Jump object.
*
*/
PlayerJump();
/**
* @brief Destroy the Player Jump object.
*
*/
~PlayerJump();
/**
* @brief Initialize the class from Godot.
*
* @details This method is called just once when the Godot engine connects to the instance of the class.
*/
void _init();
/**
* @brief Called when the player enters the jump state.
*
* @details If the previous state was the jump state, a double jump was performed.
*
* @param[in] state The previous state before this one was entered.
*/
void _state_enter(const String state);
/**
* @brief Called when the player exits the jump state.
*
*/
void _state_exit();
/**
* @brief The physics processed every delta time.
*
* @param[in] delta The time since the method was last run.
*/
void _physics_process(float delta);
};
}

View File

@@ -24,7 +24,7 @@ void PlayerMove::_init()
_input = Input::get_singleton();
}
void PlayerMove::_state_enter(String state, Array args)
void PlayerMove::_state_enter()
{
animated_sprite = get_parent()->get_node<AnimatedSprite>("AnimatedSprite");
animated_sprite->set_animation("move");

View File

@@ -11,34 +11,71 @@ namespace godot
{
namespace player
{
/**
* @brief This class controls what happens when the player is in the move state.
*
*/
class PlayerMove : public State
{
GODOT_CLASS(PlayerMove, State)
private:
/**
* @brief Input singleton.
*
*/
Input *_input;
/**
* @brief The animated sprite of the player.
*
*/
AnimatedSprite *animated_sprite;
public:
/**
* @brief This method registers classes with Godot.
*
* @details This method registers methods, properties, and signals with the Godot engine.
*/
static void _register_methods();
/**
* @brief Construct a new Player Move object.
*
*/
PlayerMove();
/**
* @brief Destroy the Player Move object.
*
*/
~PlayerMove();
/**
* @brief Initialize the class from Godot.
*
* @details This method is called just once when the Godot engine connects to the instance of the class.
*/
void _init();
void _state_enter(String state, Array args);
/**
* @brief Called when the player enters the move state.
*
*/
void _state_enter();
/**
* @brief Called when the player exists the move state.
*
*/
void _state_exit();
/**
* @brief The physics processed every delta time.
*
* @param[in] delta The time since the method was last run.
*/
void _physics_process(float delta);
Vector2 move_player(Vector2 velocity);
};
}
}