cleanup c++ code
This commit is contained in:
@@ -1,48 +1,45 @@
|
||||
#include "player/Player.h"
|
||||
|
||||
#include <Camera2D.hpp>
|
||||
#include <TileMap.hpp>
|
||||
#include <VisibilityNotifier2D.hpp>
|
||||
#include <KinematicCollision2D.hpp>
|
||||
#include <RayCast2D.hpp>
|
||||
#include <SceneTree.hpp>
|
||||
#include <Texture.hpp>
|
||||
#include <TileMap.hpp>
|
||||
#include <Viewport.hpp>
|
||||
#include <RayCast2D.hpp>
|
||||
#include <KinematicCollision2D.hpp>
|
||||
#include <VisibilityNotifier2D.hpp>
|
||||
|
||||
using namespace godot;
|
||||
using namespace player;
|
||||
|
||||
void Player::_register_methods()
|
||||
void alai::player::Player::_register_methods()
|
||||
{
|
||||
register_method("_ready", &Player::_ready);
|
||||
register_method("_physics_process", &Player::_physics_process);
|
||||
register_method("set_velocity", &Player::set_velocity);
|
||||
register_method("get_velocity", &Player::get_velocity);
|
||||
register_method("_on_player_touched", &Player::_on_player_touched);
|
||||
register_method("_on_monitor_loaded", &Player::_on_monitor_loaded);
|
||||
//register_property<Player, Ref<SpriteFrames>>("sprite_frames", &Player::set_sprite_frames, &Player::get_sprite_frames, Ref<SpriteFrames>(), GODOT_METHOD_RPC_MODE_DISABLED, GODOT_PROPERTY_USAGE_DEFAULT, GODOT_PROPERTY_HINT_RESOURCE_TYPE, String("SpriteFrames"));
|
||||
register_property<Player, float>("speed", &Player::set_speed, &Player::get_speed, player::speed);
|
||||
register_property<Player, float>("jump_force", &Player::set_jump_force, &Player::get_jump_force, player::jump_force);
|
||||
register_property<Player, float>("bounce_force", &Player::set_bounce_force, &Player::get_bounce_force, player::bounce_force);
|
||||
register_property<Player, float>("gravity", &Player::set_gravity, &Player::get_gravity, player::gravity);
|
||||
register_property<Player, float>("run_speed", &Player::set_run_speed, &Player::get_run_speed, player::run_speed);
|
||||
register_property<Player, bool>("double_jump", &Player::set_double_jump, &Player::get_double_jump, player::double_jump);
|
||||
register_signal<Player>("object_created", "name", GODOT_VARIANT_TYPE_STRING, "state", GODOT_VARIANT_TYPE_STRING, "position", GODOT_VARIANT_TYPE_VECTOR2, "velocity", GODOT_VARIANT_TYPE_VECTOR2);
|
||||
register_signal<Player>("object_updated", "name", GODOT_VARIANT_TYPE_STRING, "state", GODOT_VARIANT_TYPE_STRING, "position", GODOT_VARIANT_TYPE_VECTOR2, "velocity", GODOT_VARIANT_TYPE_VECTOR2);
|
||||
register_signal<Player>("object_removed", "name", GODOT_VARIANT_TYPE_STRING);
|
||||
godot::register_method("_ready", &Player::_ready);
|
||||
godot::register_method("_physics_process", &Player::_physics_process);
|
||||
godot::register_method("set_velocity", &Player::set_velocity);
|
||||
godot::register_method("get_velocity", &Player::get_velocity);
|
||||
godot::register_method("_on_player_touched", &Player::_on_player_touched);
|
||||
godot::register_method("_on_monitor_loaded", &Player::_on_monitor_loaded);
|
||||
//godot::register_property<Player, godot::Ref<godot::SpriteFrames>>("sprite_frames", &Player::set_sprite_frames, &Player::get_sprite_frames, godot::Ref<godot::SpriteFrames>(), GODOT_METHOD_RPC_MODE_DISABLED, GODOT_PROPERTY_USAGE_DEFAULT, GODOT_PROPERTY_HINT_RESOURCE_TYPE, godot::String("SpriteFrames"));
|
||||
godot::register_property<Player, float>("speed", &Player::set_speed, &Player::get_speed, player::speed);
|
||||
godot::register_property<Player, float>("jump_force", &Player::set_jump_force, &Player::get_jump_force, player::jump_force);
|
||||
godot::register_property<Player, float>("bounce_force", &Player::set_bounce_force, &Player::get_bounce_force, player::bounce_force);
|
||||
godot::register_property<Player, float>("gravity", &Player::set_gravity, &Player::get_gravity, player::gravity);
|
||||
godot::register_property<Player, float>("run_speed", &Player::set_run_speed, &Player::get_run_speed, player::run_speed);
|
||||
godot::register_property<Player, bool>("double_jump", &Player::set_double_jump, &Player::get_double_jump, player::double_jump);
|
||||
godot::register_signal<Player>("object_created", "name", GODOT_VARIANT_TYPE_STRING, "state", GODOT_VARIANT_TYPE_STRING, "position", GODOT_VARIANT_TYPE_VECTOR2, "velocity", GODOT_VARIANT_TYPE_VECTOR2);
|
||||
godot::register_signal<Player>("object_updated", "name", GODOT_VARIANT_TYPE_STRING, "state", GODOT_VARIANT_TYPE_STRING, "position", GODOT_VARIANT_TYPE_VECTOR2, "velocity", GODOT_VARIANT_TYPE_VECTOR2);
|
||||
godot::register_signal<Player>("object_removed", "name", GODOT_VARIANT_TYPE_STRING);
|
||||
}
|
||||
|
||||
Player::Player()
|
||||
alai::player::Player::Player()
|
||||
{
|
||||
}
|
||||
|
||||
Player::~Player()
|
||||
alai::player::Player::~Player()
|
||||
{
|
||||
}
|
||||
|
||||
void Player::_init()
|
||||
void alai::player::Player::_init()
|
||||
{
|
||||
_resource_loader = ResourceLoader::get_singleton();
|
||||
_resource_loader = godot::ResourceLoader::get_singleton();
|
||||
|
||||
//sprite_frames = _resource_loader->load(player::sprite_frames);
|
||||
set_speed(player::speed);
|
||||
@@ -54,23 +51,23 @@ void Player::_init()
|
||||
|
||||
coins = 0;
|
||||
|
||||
velocity = Vector2();
|
||||
velocity = godot::Vector2();
|
||||
}
|
||||
|
||||
void Player::_ready()
|
||||
void alai::player::Player::_ready()
|
||||
{
|
||||
animated_sprite = get_node<AnimatedSprite>("AnimatedSprite");
|
||||
animated_sprite = get_node<godot::AnimatedSprite>("AnimatedSprite");
|
||||
if (!animated_sprite)
|
||||
{
|
||||
ERR_PRINT("AnimateSprite not found!");
|
||||
animated_sprite = AnimatedSprite()._new();
|
||||
animated_sprite = godot::AnimatedSprite()._new();
|
||||
}
|
||||
//animated_sprite->set_sprite_frames(sprite_frames);
|
||||
|
||||
auto node = get_parent()->find_node("Middleground");
|
||||
if (node != nullptr)
|
||||
{
|
||||
auto tile_map = Object::cast_to<TileMap>(node);
|
||||
auto tile_map = Object::cast_to<godot::TileMap>(node);
|
||||
get_parent()->call_deferred("remove_child", this);
|
||||
tile_map->call_deferred("add_child", this);
|
||||
}
|
||||
@@ -80,7 +77,7 @@ void Player::_ready()
|
||||
}
|
||||
}
|
||||
|
||||
void Player::_on_monitor_loaded() {
|
||||
void alai::player::Player::_on_monitor_loaded() {
|
||||
auto object_node = get_tree()->get_root()->find_node("Monitor", true, false);
|
||||
if (object_node != nullptr)
|
||||
{
|
||||
@@ -105,22 +102,22 @@ void Player::_on_monitor_loaded() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void Player::_physics_process(float delta)
|
||||
void alai::player::Player::_physics_process(float delta)
|
||||
{
|
||||
velocity.y += get_gravity();
|
||||
|
||||
auto snap_vector = Vector2::ZERO;
|
||||
auto snap_vector = godot::Vector2::ZERO;
|
||||
if (!is_on_floor())
|
||||
{
|
||||
snap_vector = Vector2::DOWN * 20.0;
|
||||
snap_vector = godot::Vector2::DOWN * 20.0;
|
||||
}
|
||||
|
||||
auto platform_detector = get_node<RayCast2D>("PlatformDetector");
|
||||
auto platform_detector = get_node<godot::RayCast2D>("PlatformDetector");
|
||||
auto is_on_platform = platform_detector->is_colliding();
|
||||
|
||||
velocity = move_and_slide_with_snap(velocity, snap_vector, Vector2::UP, !is_on_platform, 4, 0.9, false);
|
||||
velocity = move_and_slide_with_snap(velocity, snap_vector, godot::Vector2::UP, !is_on_platform, 4, 0.9, false);
|
||||
//velocity = move_and_slide(velocity, Vector2::UP, !is_on_platform);
|
||||
velocity.x = Math::lerp((float) velocity.x, (float) 0, (float) 0.2);
|
||||
velocity.x = godot::Math::lerp((float) velocity.x, (float) 0, (float) 0.2);
|
||||
|
||||
auto count = get_slide_count();
|
||||
for (int64_t i = 0; i < count; i++)
|
||||
@@ -128,7 +125,7 @@ void Player::_physics_process(float delta)
|
||||
auto collision = get_slide_collision(i);
|
||||
auto collision_object = collision->get_collider();
|
||||
auto collider = Object::cast_to<Node>(collision_object);
|
||||
if (collider->is_in_group("squashable") && Vector2::UP.dot(collision->get_normal()) > 0.1)
|
||||
if (collider->is_in_group("squashable") && godot::Vector2::UP.dot(collision->get_normal()) > 0.1)
|
||||
{
|
||||
collider->call_deferred("squash");
|
||||
/*auto dup_node = collider->duplicate();
|
||||
@@ -147,7 +144,7 @@ void Player::_physics_process(float delta)
|
||||
}*/
|
||||
velocity.y = -get_bounce_force();
|
||||
}
|
||||
else if (collider->is_in_group("enemy") && (collider->is_in_group("rideable") && Vector2::DOWN.dot(collision->get_normal()) > 0))
|
||||
else if (collider->is_in_group("enemy") && (collider->is_in_group("rideable") && godot::Vector2::DOWN.dot(collision->get_normal()) > 0))
|
||||
{
|
||||
_on_player_touched();
|
||||
}
|
||||
@@ -158,23 +155,23 @@ void Player::_physics_process(float delta)
|
||||
}
|
||||
|
||||
// Clamp the player's position inside the camera's limits
|
||||
auto camera = get_node<Camera2D>("Camera2D");
|
||||
auto camera = get_node<godot::Camera2D>("Camera2D");
|
||||
auto position = get_global_position();
|
||||
auto sprite_node = get_node<AnimatedSprite>("AnimatedSprite");
|
||||
auto sprite_node = get_node<godot::AnimatedSprite>("AnimatedSprite");
|
||||
if (sprite_node != nullptr)
|
||||
{
|
||||
position.x = Math::clamp((float) position.x, (float) camera->get_limit(0), (float) camera->get_limit(2) - sprite_node->get_sprite_frames()->get_frame("idle", 0)->get_size().x);
|
||||
position.y = Math::clamp((float) position.y, (float) camera->get_limit(1), (float) camera->get_limit(3) + sprite_node->get_sprite_frames()->get_frame("idle", 0)->get_size().y);
|
||||
position.x = godot::Math::clamp((float) position.x, (float) camera->get_limit(0), (float) camera->get_limit(2) - sprite_node->get_sprite_frames()->get_frame("idle", 0)->get_size().x);
|
||||
position.y = godot::Math::clamp((float) position.y, (float) camera->get_limit(1), (float) camera->get_limit(3) + sprite_node->get_sprite_frames()->get_frame("idle", 0)->get_size().y);
|
||||
}
|
||||
else {
|
||||
WARN_PRINT("Could not clamp player based on sprite frame size!");
|
||||
position.x = Math::clamp((float) position.x, (float) camera->get_limit(0), (float) camera->get_limit(2));
|
||||
position.y = Math::clamp((float) position.y, (float) camera->get_limit(1), (float) camera->get_limit(3));
|
||||
position.x = godot::Math::clamp((float) position.x, (float) camera->get_limit(0), (float) camera->get_limit(2));
|
||||
position.y = godot::Math::clamp((float) position.y, (float) camera->get_limit(1), (float) camera->get_limit(3));
|
||||
}
|
||||
set_global_position(position);
|
||||
|
||||
// If the player is off screen reload the scene
|
||||
auto notifier = get_node<VisibilityNotifier2D>("Camera2D/VisibilityNotifier2D");
|
||||
auto notifier = get_node<godot::VisibilityNotifier2D>("Camera2D/VisibilityNotifier2D");
|
||||
if (notifier != nullptr)
|
||||
{
|
||||
if (!notifier->is_on_screen())
|
||||
@@ -182,9 +179,9 @@ void Player::_physics_process(float delta)
|
||||
if (get_parent()->get_class() == "TileMap")
|
||||
{
|
||||
auto error = get_tree()->change_scene("res://Main.tscn");
|
||||
if (error != Error::OK)
|
||||
if (error != godot::Error::OK)
|
||||
{
|
||||
ERR_PRINT(String().num((int) error) + " Could not load scene!");
|
||||
ERR_PRINT(godot::String().num((int) error) + " Could not load scene!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -201,91 +198,91 @@ void Player::_physics_process(float delta)
|
||||
}
|
||||
}
|
||||
|
||||
void Player::set_sprite_frames(Ref<SpriteFrames> sprite_frames)
|
||||
void alai::player::Player::set_sprite_frames(godot::Ref<godot::SpriteFrames> sprite_frames)
|
||||
{
|
||||
this->sprite_frames = sprite_frames;
|
||||
}
|
||||
|
||||
Ref<SpriteFrames> Player::get_sprite_frames()
|
||||
godot::Ref<godot::SpriteFrames> alai::player::Player::get_sprite_frames()
|
||||
{
|
||||
return this->sprite_frames;
|
||||
}
|
||||
|
||||
void Player::set_speed(float speed)
|
||||
void alai::player::Player::set_speed(float speed)
|
||||
{
|
||||
this->speed = speed;
|
||||
}
|
||||
|
||||
float Player::get_speed()
|
||||
float alai::player::Player::get_speed()
|
||||
{
|
||||
return this->speed;
|
||||
}
|
||||
|
||||
void Player::set_jump_force(float jump_force)
|
||||
void alai::player::Player::set_jump_force(float jump_force)
|
||||
{
|
||||
this->jump_force = jump_force;
|
||||
}
|
||||
|
||||
float Player::get_jump_force()
|
||||
float alai::player::Player::get_jump_force()
|
||||
{
|
||||
return this->jump_force;
|
||||
}
|
||||
|
||||
void Player::set_bounce_force(float bounce_force)
|
||||
void alai::player::Player::set_bounce_force(float bounce_force)
|
||||
{
|
||||
this->bounce_force = bounce_force;
|
||||
}
|
||||
|
||||
float Player::get_bounce_force()
|
||||
float alai::player::Player::get_bounce_force()
|
||||
{
|
||||
return this->bounce_force;
|
||||
}
|
||||
|
||||
void Player::set_gravity(float gravity)
|
||||
void alai::player::Player::set_gravity(float gravity)
|
||||
{
|
||||
this->gravity = gravity;
|
||||
}
|
||||
|
||||
float Player::get_gravity()
|
||||
float alai::player::Player::get_gravity()
|
||||
{
|
||||
return this->gravity;
|
||||
}
|
||||
|
||||
void Player::set_run_speed(float run_speed)
|
||||
void alai::player::Player::set_run_speed(float run_speed)
|
||||
{
|
||||
this->run_speed = run_speed;
|
||||
}
|
||||
|
||||
float Player::get_run_speed()
|
||||
float alai::player::Player::get_run_speed()
|
||||
{
|
||||
return this->run_speed;
|
||||
}
|
||||
|
||||
void Player::set_double_jump(bool double_jump)
|
||||
void alai::player::Player::set_double_jump(bool double_jump)
|
||||
{
|
||||
this->double_jump = double_jump;
|
||||
}
|
||||
|
||||
bool Player::get_double_jump()
|
||||
bool alai::player::Player::get_double_jump()
|
||||
{
|
||||
return this->double_jump;
|
||||
}
|
||||
|
||||
void Player::set_velocity(Vector2 velocity)
|
||||
void alai::player::Player::set_velocity(godot::Vector2 velocity)
|
||||
{
|
||||
this->velocity = velocity;
|
||||
}
|
||||
|
||||
Vector2 Player::get_velocity()
|
||||
godot::Vector2 alai::player::Player::get_velocity()
|
||||
{
|
||||
return this->velocity;
|
||||
}
|
||||
|
||||
void Player::_on_player_touched()
|
||||
void alai::player::Player::_on_player_touched()
|
||||
{
|
||||
auto error = get_tree()->change_scene("res://Main.tscn");
|
||||
if (error != Error::OK)
|
||||
if (error != godot::Error::OK)
|
||||
{
|
||||
ERR_PRINT(String().num((int) error) + " Could not load scene!");
|
||||
ERR_PRINT(godot::String().num((int) error) + " Could not load scene!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
#ifndef ALAI_PLAYER_H
|
||||
#define ALAI_PLAYER_H
|
||||
#ifndef ALAI_PLAYER_PLAYER_H
|
||||
#define ALAI_PLAYER_PLAYER_H
|
||||
|
||||
#include <AnimatedSprite.hpp>
|
||||
#include <Godot.hpp>
|
||||
#include <KinematicBody2D.hpp>
|
||||
#include <Sprite.hpp>
|
||||
#include <AnimatedSprite.hpp>
|
||||
#include <SpriteFrames.hpp>
|
||||
#include <ResourceLoader.hpp>
|
||||
#include <SpriteFrames.hpp>
|
||||
|
||||
namespace godot
|
||||
namespace alai
|
||||
{
|
||||
/**
|
||||
* @brief This namespace contains the global variables related to the player and its states.
|
||||
@@ -57,27 +56,27 @@ namespace godot
|
||||
*
|
||||
* @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
|
||||
class Player : public godot::KinematicBody2D
|
||||
{
|
||||
GODOT_CLASS(Player, KinematicBody2D)
|
||||
GODOT_CLASS(Player, godot::KinematicBody2D)
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief ResourceLoader singleton.
|
||||
*
|
||||
*/
|
||||
ResourceLoader *_resource_loader;
|
||||
godot::ResourceLoader *_resource_loader;
|
||||
|
||||
/**
|
||||
* @brief The animated sprite connected to the KinematicBody2D.
|
||||
*
|
||||
*/
|
||||
AnimatedSprite *animated_sprite;
|
||||
godot::AnimatedSprite *animated_sprite;
|
||||
/**
|
||||
* @brief The sprite frames used in the animated sprite.
|
||||
*
|
||||
*/
|
||||
Ref<SpriteFrames> sprite_frames;
|
||||
godot::Ref<godot::SpriteFrames> sprite_frames;
|
||||
/**
|
||||
* @brief The coins the player has collected.
|
||||
*
|
||||
@@ -87,7 +86,7 @@ namespace godot
|
||||
* @brief The velocity at which moves the player moves.
|
||||
*
|
||||
*/
|
||||
Vector2 velocity;
|
||||
godot::Vector2 velocity;
|
||||
/**
|
||||
* @brief The speed that the player moves in.
|
||||
*
|
||||
@@ -167,14 +166,14 @@ namespace godot
|
||||
*
|
||||
* @param[in] sprite_frames The new sprite frame.
|
||||
*/
|
||||
void set_sprite_frames(Ref<SpriteFrames> sprite_frames);
|
||||
void set_sprite_frames(godot::Ref<godot::SpriteFrames> sprite_frames);
|
||||
|
||||
/**
|
||||
* @brief Get the sprite frames object.
|
||||
*
|
||||
* @return Ref<SpriteFrames> A reference to the sprite frames object.
|
||||
*/
|
||||
Ref<SpriteFrames> get_sprite_frames();
|
||||
godot::Ref<godot::SpriteFrames> get_sprite_frames();
|
||||
|
||||
/**
|
||||
* @brief Set the speed object.
|
||||
@@ -266,14 +265,14 @@ namespace godot
|
||||
*
|
||||
* @param[in] velocity The new velocity of the player.
|
||||
*/
|
||||
void set_velocity(Vector2 velocity);
|
||||
void set_velocity(godot::Vector2 velocity);
|
||||
|
||||
/**
|
||||
* @brief Get the velocity object.
|
||||
*
|
||||
* @return Vector2 Returns the velocity of the player.
|
||||
*/
|
||||
Vector2 get_velocity();
|
||||
godot::Vector2 get_velocity();
|
||||
|
||||
/**
|
||||
* @brief This function is called when an enemy touches the player.
|
||||
@@ -281,6 +280,10 @@ namespace godot
|
||||
*/
|
||||
void _on_player_touched();
|
||||
|
||||
/**
|
||||
* @brief Called when the monitor is loaded to connect the player to it for tracking.
|
||||
*
|
||||
*/
|
||||
void _on_monitor_loaded();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,45 +1,42 @@
|
||||
#include "player/states/PlayerFall.h"
|
||||
#include "player/Player.h"
|
||||
|
||||
using namespace godot;
|
||||
using namespace player;
|
||||
|
||||
void PlayerFall::_register_methods()
|
||||
void alai::player::PlayerFall::_register_methods()
|
||||
{
|
||||
register_method("_state_enter", &PlayerFall::_state_enter);
|
||||
register_method("_state_exit", &PlayerFall::_state_exit);
|
||||
register_method("_physics_process", &PlayerFall::_physics_process);
|
||||
}
|
||||
|
||||
PlayerFall::PlayerFall()
|
||||
alai::player::PlayerFall::PlayerFall()
|
||||
{
|
||||
}
|
||||
|
||||
PlayerFall::~PlayerFall()
|
||||
alai::player::PlayerFall::~PlayerFall()
|
||||
{
|
||||
}
|
||||
|
||||
void PlayerFall::_init()
|
||||
void alai::player::PlayerFall::_init()
|
||||
{
|
||||
_input = Input::get_singleton();
|
||||
_input = godot::Input::get_singleton();
|
||||
}
|
||||
|
||||
void PlayerFall::_state_enter()
|
||||
void alai::player::PlayerFall::_state_enter()
|
||||
{
|
||||
animated_sprite = get_parent()->get_node<AnimatedSprite>("AnimatedSprite");
|
||||
animated_sprite = get_parent()->get_node<godot::AnimatedSprite>("AnimatedSprite");
|
||||
animated_sprite->stop();
|
||||
animated_sprite->set_animation("air");
|
||||
}
|
||||
|
||||
void PlayerFall::_state_exit()
|
||||
void alai::player::PlayerFall::_state_exit()
|
||||
{
|
||||
animated_sprite->set_animation("move");
|
||||
animated_sprite->set_frame(1);
|
||||
}
|
||||
|
||||
void PlayerFall::_physics_process(float delta)
|
||||
void alai::player::PlayerFall::_physics_process(float delta)
|
||||
{
|
||||
auto parent = Object::cast_to<player::Player>(get_parent());
|
||||
auto parent = Object::cast_to<Player>(get_parent());
|
||||
|
||||
if (parent->is_on_floor())
|
||||
{
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#ifndef JUEGO_PLAYER_FALL_H
|
||||
#define JUEGO_PLAYER_FALL_H
|
||||
#ifndef ALAI_PLAYER_STATES_PLAYER_FALL_H
|
||||
#define ALAI_PLAYER_STATES_PLAYER_FALL_H
|
||||
|
||||
#include "state_machine/State.h"
|
||||
|
||||
#include <AnimatedSprite.hpp>
|
||||
#include <Godot.hpp>
|
||||
#include <Input.hpp>
|
||||
#include <AnimatedSprite.hpp>
|
||||
|
||||
namespace godot
|
||||
namespace alai
|
||||
{
|
||||
namespace player
|
||||
{
|
||||
@@ -24,13 +24,13 @@ namespace godot
|
||||
* @brief Input singleton.
|
||||
*
|
||||
*/
|
||||
Input *_input;
|
||||
godot::Input *_input;
|
||||
|
||||
/**
|
||||
* @brief The animated sprite connected to the Player.
|
||||
*
|
||||
*/
|
||||
AnimatedSprite *animated_sprite;
|
||||
godot::AnimatedSprite *animated_sprite;
|
||||
|
||||
public:
|
||||
/**
|
||||
|
||||
@@ -1,43 +1,40 @@
|
||||
#include "player/states/PlayerIdle.h"
|
||||
#include "player/Player.h"
|
||||
|
||||
using namespace godot;
|
||||
using namespace player;
|
||||
|
||||
void PlayerIdle::_register_methods()
|
||||
void alai::player::PlayerIdle::_register_methods()
|
||||
{
|
||||
register_method("_state_enter", &PlayerIdle::_state_enter);
|
||||
register_method("_state_exit", &PlayerIdle::_state_exit);
|
||||
register_method("_physics_process", &PlayerIdle::_physics_process);
|
||||
}
|
||||
|
||||
PlayerIdle::PlayerIdle()
|
||||
alai::player::PlayerIdle::PlayerIdle()
|
||||
{
|
||||
}
|
||||
|
||||
PlayerIdle::~PlayerIdle()
|
||||
alai::player::PlayerIdle::~PlayerIdle()
|
||||
{
|
||||
}
|
||||
|
||||
void PlayerIdle::_init()
|
||||
void alai::player::PlayerIdle::_init()
|
||||
{
|
||||
_input = Input::get_singleton();
|
||||
_input = godot::Input::get_singleton();
|
||||
}
|
||||
|
||||
void PlayerIdle::_state_enter()
|
||||
void alai::player::PlayerIdle::_state_enter()
|
||||
{
|
||||
animated_sprite = get_parent()->get_node<AnimatedSprite>("AnimatedSprite");
|
||||
animated_sprite = get_parent()->get_node<godot::AnimatedSprite>("AnimatedSprite");
|
||||
animated_sprite->stop();
|
||||
animated_sprite->set_animation("idle");
|
||||
}
|
||||
|
||||
void PlayerIdle::_state_exit()
|
||||
void alai::player::PlayerIdle::_state_exit()
|
||||
{
|
||||
}
|
||||
|
||||
void PlayerIdle::_physics_process(float delta)
|
||||
void alai::player::PlayerIdle::_physics_process(float delta)
|
||||
{
|
||||
auto parent = Object::cast_to<player::Player>(get_parent());
|
||||
auto parent = Object::cast_to<Player>(get_parent());
|
||||
|
||||
if (_input->is_action_pressed("right"))
|
||||
{
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
#ifndef JUEGO_PLAYER_IDLE_H
|
||||
#define JUEGO_PLAYER_IDLE_H
|
||||
#ifndef ALAI_PLAYER_STATES_PLAYER_IDLE_H
|
||||
#define ALAI_PLAYER_STATES_PLAYER_IDLE_H
|
||||
|
||||
#include "state_machine/State.h"
|
||||
|
||||
#include <Godot.hpp>
|
||||
#include <Node.hpp>
|
||||
#include <Input.hpp>
|
||||
#include <AnimatedSprite.hpp>
|
||||
#include <Godot.hpp>
|
||||
#include <Input.hpp>
|
||||
|
||||
namespace godot
|
||||
namespace alai
|
||||
{
|
||||
namespace player
|
||||
{
|
||||
@@ -25,12 +24,12 @@ namespace godot
|
||||
* @brief Input singleton.
|
||||
*
|
||||
*/
|
||||
Input *_input;
|
||||
godot::Input *_input;
|
||||
/**
|
||||
* @brief The animated sprite of the Player.
|
||||
*
|
||||
*/
|
||||
AnimatedSprite *animated_sprite;
|
||||
godot::AnimatedSprite *animated_sprite;
|
||||
|
||||
public:
|
||||
/**
|
||||
|
||||
@@ -3,35 +3,32 @@
|
||||
|
||||
#include <AudioStreamPlayer.hpp>
|
||||
|
||||
using namespace godot;
|
||||
using namespace player;
|
||||
|
||||
void PlayerJump::_register_methods()
|
||||
void alai::player::PlayerJump::_register_methods()
|
||||
{
|
||||
register_method("_state_enter", &PlayerJump::_state_enter);
|
||||
register_method("_state_exit", &PlayerJump::_state_exit);
|
||||
register_method("_physics_process", &PlayerJump::_physics_process);
|
||||
}
|
||||
|
||||
PlayerJump::PlayerJump()
|
||||
alai::player::PlayerJump::PlayerJump()
|
||||
{
|
||||
}
|
||||
|
||||
PlayerJump::~PlayerJump()
|
||||
alai::player::PlayerJump::~PlayerJump()
|
||||
{
|
||||
}
|
||||
|
||||
void PlayerJump::_init()
|
||||
void alai::player::PlayerJump::_init()
|
||||
{
|
||||
_input = Input::get_singleton();
|
||||
_input = godot::Input::get_singleton();
|
||||
}
|
||||
|
||||
void PlayerJump::_state_enter(const String state)
|
||||
void alai::player::PlayerJump::_state_enter(const godot::String state)
|
||||
{
|
||||
auto jump_sound = get_parent()->get_node<AudioStreamPlayer>("Sounds/Jump");
|
||||
auto jump_sound = get_parent()->get_node<godot::AudioStreamPlayer>("Sounds/Jump");
|
||||
jump_sound->play();
|
||||
|
||||
animated_sprite = get_parent()->get_node<AnimatedSprite>("AnimatedSprite");
|
||||
animated_sprite = get_parent()->get_node<godot::AnimatedSprite>("AnimatedSprite");
|
||||
animated_sprite->stop();
|
||||
animated_sprite->set_animation("air");
|
||||
|
||||
@@ -44,21 +41,21 @@ void PlayerJump::_state_enter(const String state)
|
||||
double_jumped = false;
|
||||
}
|
||||
|
||||
auto parent = Object::cast_to<player::Player>(get_parent());
|
||||
auto parent = Object::cast_to<Player>(get_parent());
|
||||
auto velocity = parent->get_velocity();
|
||||
velocity.y = -parent->get_jump_force();
|
||||
parent->set_velocity(velocity);
|
||||
}
|
||||
|
||||
void PlayerJump::_state_exit()
|
||||
void alai::player::PlayerJump::_state_exit()
|
||||
{
|
||||
animated_sprite->set_animation("move");
|
||||
animated_sprite->set_frame(1);
|
||||
}
|
||||
|
||||
void PlayerJump::_physics_process(float delta)
|
||||
void alai::player::PlayerJump::_physics_process(float delta)
|
||||
{
|
||||
auto parent = Object::cast_to<player::Player>(get_parent());
|
||||
auto parent = Object::cast_to<Player>(get_parent());
|
||||
if (parent->is_on_floor())
|
||||
{
|
||||
get_state_machine()->change("Move");
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#ifndef JUEGO_PLAYER_JUMP_H
|
||||
#define JUEGO_PLAYER_JUMP_H
|
||||
#ifndef ALAI_PLAYER_STATES_PLAYER_JUMP_H
|
||||
#define ALAI_PLAYER_STATES_PLAYER_JUMP_H
|
||||
|
||||
#include "state_machine/State.h"
|
||||
|
||||
#include <AnimatedSprite.hpp>
|
||||
#include <Godot.hpp>
|
||||
#include <Input.hpp>
|
||||
#include <AnimatedSprite.hpp>
|
||||
|
||||
namespace godot
|
||||
namespace alai
|
||||
{
|
||||
namespace player
|
||||
{
|
||||
@@ -24,12 +24,12 @@ namespace godot
|
||||
* @brief Input singleton.
|
||||
*
|
||||
*/
|
||||
Input *_input;
|
||||
godot::Input *_input;
|
||||
/**
|
||||
* @brief The animated sprite connected to the Player.
|
||||
*
|
||||
*/
|
||||
AnimatedSprite *animated_sprite;
|
||||
godot::AnimatedSprite *animated_sprite;
|
||||
/**
|
||||
* @brief If the player has already performed a double jump or not.
|
||||
*
|
||||
@@ -70,7 +70,7 @@ namespace godot
|
||||
*
|
||||
* @param[in] state The previous state before this one was entered.
|
||||
*/
|
||||
void _state_enter(const String state);
|
||||
void _state_enter(const godot::String state);
|
||||
|
||||
/**
|
||||
* @brief Called when the player exits the jump state.
|
||||
|
||||
@@ -1,43 +1,40 @@
|
||||
#include "player/states/PlayerMove.h"
|
||||
#include "player/Player.h"
|
||||
|
||||
using namespace godot;
|
||||
using namespace player;
|
||||
|
||||
void PlayerMove::_register_methods()
|
||||
void alai::player::PlayerMove::_register_methods()
|
||||
{
|
||||
register_method("_state_enter", &PlayerMove::_state_enter);
|
||||
register_method("_state_exit", &PlayerMove::_state_exit);
|
||||
register_method("_physics_process", &PlayerMove::_physics_process);
|
||||
}
|
||||
|
||||
PlayerMove::PlayerMove()
|
||||
alai::player::PlayerMove::PlayerMove()
|
||||
{
|
||||
}
|
||||
|
||||
PlayerMove::~PlayerMove()
|
||||
alai::player::PlayerMove::~PlayerMove()
|
||||
{
|
||||
}
|
||||
|
||||
void PlayerMove::_init()
|
||||
void alai::player::PlayerMove::_init()
|
||||
{
|
||||
_input = Input::get_singleton();
|
||||
_input = godot::Input::get_singleton();
|
||||
}
|
||||
|
||||
void PlayerMove::_state_enter()
|
||||
void alai::player::PlayerMove::_state_enter()
|
||||
{
|
||||
animated_sprite = get_parent()->get_node<AnimatedSprite>("AnimatedSprite");
|
||||
animated_sprite = get_parent()->get_node<godot::AnimatedSprite>("AnimatedSprite");
|
||||
animated_sprite->set_animation("move");
|
||||
animated_sprite->play();
|
||||
}
|
||||
|
||||
void PlayerMove::_state_exit()
|
||||
void alai::player::PlayerMove::_state_exit()
|
||||
{
|
||||
}
|
||||
|
||||
void PlayerMove::_physics_process(float delta)
|
||||
void alai::player::PlayerMove::_physics_process(float delta)
|
||||
{
|
||||
auto parent = Object::cast_to<player::Player>(get_parent());
|
||||
auto parent = Object::cast_to<Player>(get_parent());
|
||||
|
||||
auto direction_pressed = false;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef JUEGO_PLAYER_MOVE_H
|
||||
#define JUEGO_PLAYER_MOVE_H
|
||||
#ifndef ALAI_PLAYER_STATES_PLAYER_MOVE_H
|
||||
#define ALAI_PLAYER_STATES_PLAYER_MOVE_H
|
||||
|
||||
#include "state_machine/State.h"
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <Input.hpp>
|
||||
#include <AnimatedSprite.hpp>
|
||||
|
||||
namespace godot
|
||||
namespace alai
|
||||
{
|
||||
namespace player
|
||||
{
|
||||
@@ -24,12 +24,12 @@ namespace godot
|
||||
* @brief Input singleton.
|
||||
*
|
||||
*/
|
||||
Input *_input;
|
||||
godot::Input *_input;
|
||||
/**
|
||||
* @brief The animated sprite of the Player.
|
||||
*
|
||||
*/
|
||||
AnimatedSprite *animated_sprite;
|
||||
godot::AnimatedSprite *animated_sprite;
|
||||
|
||||
public:
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user