alai/src/player/Player.h

258 lines
7.9 KiB
C
Raw Normal View History

2022-04-09 21:50:08 -04:00
#ifndef ALAI_PLAYER_H
#define ALAI_PLAYER_H
2022-04-05 14:51:59 -04:00
#include <Godot.hpp>
#include <KinematicBody2D.hpp>
#include <Sprite.hpp>
#include <AnimatedSprite.hpp>
#include <SpriteFrames.hpp>
#include <ResourceLoader.hpp>
namespace godot
{
2022-04-13 00:59:23 -04:00
/**
* @brief This namespace contains the global variables related to the player and its states.
*
*/
namespace player
2022-04-05 14:51:59 -04:00
{
2022-04-13 00:59:23 -04:00
/**
* @brief The default sprite resource of the player.
*
*/
const char player_sprite_frames[] = "res://characters/player/sprites/green.tres";
2022-04-13 00:59:23 -04:00
/**
* @brief The default speed of the player.
*
*/
const float speed = 60.0;
2022-04-13 00:59:23 -04:00
/**
* @brief The default jump force applied when jumping.
*
*/
const float jump_force = 300.0;
2022-04-13 00:59:23 -04:00
/**
* @brief The default gravity applied to the player.
*
*/
const float gravity = 9.81;
2022-04-13 00:59:23 -04:00
/**
* @brief The default run speed multiplier.
*
*/
const float run_speed = 2.0;
2022-04-13 00:59:23 -04:00
/**
* @brief The default double jump activation state.
*
*/
const bool double_jump = true;
/**
* @brief This class is used to control the player.
2022-04-13 00:59:23 -04:00
*
* @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
{
GODOT_CLASS(Player, KinematicBody2D)
private:
/**
* @brief ResourceLoader singleton.
2022-04-13 00:59:23 -04:00
*
*/
ResourceLoader *_resource_loader;
/**
* @brief The animated sprite connected to the KinematicBody2D.
2022-04-13 00:59:23 -04:00
*
*/
AnimatedSprite *animated_sprite;
/**
* @brief The sprite frames used in the animated sprite.
2022-04-13 00:59:23 -04:00
*
*/
Ref<SpriteFrames> sprite_frames;
/**
* @brief The coins the player has collected.
2022-04-13 00:59:23 -04:00
*
*/
uint8_t coins;
/**
* @brief The velocity at which moves the player moves.
2022-04-13 00:59:23 -04:00
*
*/
Vector2 velocity;
/**
* @brief The speed that the player moves in.
2022-04-13 00:59:23 -04:00
*
*/
float speed;
/**
* @brief The force applied to the player when jumping.
2022-04-13 00:59:23 -04:00
*
*/
float jump_force;
/**
* @brief The gravity applied to the player.
2022-04-13 00:59:23 -04:00
*
*/
float gravity;
/**
* @brief The speed multiplier used to make the player move faster.
2022-04-13 00:59:23 -04:00
*
*/
float run_speed;
2022-04-13 00:59:23 -04:00
/**
* @brief If double jump is enabled or not.
*
*/
bool double_jump;
public:
/**
* @brief This method registers classes with Godot.
2022-04-13 00:59:23 -04:00
*
* @details This method registers methods, properties, and signals with the Godot engine.
*/
static void _register_methods();
/**
* @brief Construct a new Player object.
2022-04-13 00:59:23 -04:00
*
*/
Player();
/**
* @brief Destroy the Player object.
2022-04-13 00:59:23 -04:00
*
*/
~Player();
/**
* @brief Initialize the class from Godot.
2022-04-13 00:59:23 -04:00
*
* @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.
2022-04-13 00:59:23 -04:00
*
* @details This method is run when all the children of this node are ready.
*/
void _ready();
/**
* @brief This class handles the physics processing.
2022-04-13 00:59:23 -04:00
*
* @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.
*/
void _physics_process(float delta);
/**
* @brief Set the sprite frames object.
*
2022-04-12 11:33:22 -04:00
* @param[in] sprite_frames The new sprite frame.
*/
2022-04-12 11:33:22 -04:00
void set_sprite_frames(Ref<SpriteFrames> sprite_frames);
/**
* @brief Get the sprite frames object.
*
* @return Ref<SpriteFrames> A reference to the sprite frames object.
*/
Ref<SpriteFrames> get_sprite_frames();
/**
* @brief Set the speed object.
*
2022-04-12 11:33:22 -04:00
* @param[in] speed The new speed.
*/
2022-04-12 11:33:22 -04:00
void set_speed(float speed);
/**
* @brief Get the speed object.
*
* @return float The current speed of the player.
*/
float get_speed();
/**
* @brief Set the jump force object.
*
2022-04-12 11:33:22 -04:00
* @param[in] jump_force The new force applied to the player to make him jump.
*/
2022-04-12 11:33:22 -04:00
void set_jump_force(float jump_force);
/**
* @brief Get the jump force object.
*
* @return float The current force being applied to the player.
*/
float get_jump_force();
/**
* @brief Set the gravity object.
*
2022-04-12 11:33:22 -04:00
* @param[in] gravity The new gravity to apply to the player.
*/
2022-04-12 11:33:22 -04:00
void set_gravity(float gravity);
/**
* @brief Get the gravity object.
*
* @return float The current gravity applied to the player.
*/
float get_gravity();
/**
* @brief Set the run speed object.
*
2022-04-12 11:33:22 -04:00
* @param[in] run_speed The new speed for running.
*/
2022-04-12 11:33:22 -04:00
void set_run_speed(float run_speed);
/**
* @brief Get the run speed object.
*
* @return float The current run speed of the player.
*/
float get_run_speed();
2022-04-13 00:59:23 -04:00
/**
* @brief Set the double jump object.
*
* @param[in] double_jump The new double dump value.
*/
void set_double_jump(bool double_jump);
2022-04-13 00:59:23 -04:00
/**
* @brief Get the double jump object.
*
* @return true If double jump is enabled.
* @return false If double jump is disabled.
*/
bool get_double_jump();
2022-04-13 00:59:23 -04:00
/**
* @brief Set the velocity object.
*
* @param[in] velocity The new velocity of the player.
*/
void set_velocity(Vector2 velocity);
2022-04-13 00:59:23 -04:00
/**
* @brief Get the velocity object.
*
* @return Vector2 Returns the velocity of the player.
*/
Vector2 get_velocity();
};
}
2022-04-05 14:51:59 -04:00
}
#endif