used clang-format to format the code
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
#include "player/Player.h"
|
||||
|
||||
#include "Event.h"
|
||||
#include "player/Player.h"
|
||||
|
||||
#include <AudioStreamPlayer.hpp>
|
||||
#include <Camera2D.hpp>
|
||||
@@ -83,7 +82,8 @@ void alai::player::Player::_ready()
|
||||
}
|
||||
}
|
||||
|
||||
void alai::player::Player::_on_level_loaded() {
|
||||
void alai::player::Player::_on_level_loaded()
|
||||
{
|
||||
auto state = get_node("StateMachine")->get_child(0);
|
||||
if (state != nullptr)
|
||||
{
|
||||
@@ -106,27 +106,27 @@ void alai::player::Player::_physics_process(float delta)
|
||||
snap_vector = godot::Vector2::DOWN * 20.0;
|
||||
}
|
||||
|
||||
auto is_on_platform = false;
|
||||
auto is_on_platform = false;
|
||||
auto platform_detector = get_node<godot::RayCast2D>("PlatformDetector");
|
||||
if (platform_detector != nullptr)
|
||||
{
|
||||
is_on_platform = platform_detector->is_colliding();
|
||||
is_on_platform = platform_detector->is_colliding();
|
||||
}
|
||||
else
|
||||
{
|
||||
WARN_PRINT("PlatformDetector not found!");
|
||||
}
|
||||
|
||||
velocity = move_and_slide_with_snap(velocity, snap_vector, godot::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 = godot::Math::lerp((float) velocity.x, (float) 0, (float) 0.2);
|
||||
|
||||
auto count = get_slide_count();
|
||||
for (int64_t i = 0; i < count; i++)
|
||||
{
|
||||
auto collision = get_slide_collision(i);
|
||||
auto collision = get_slide_collision(i);
|
||||
auto collision_object = collision->get_collider();
|
||||
auto collider = Object::cast_to<Node>(collision_object);
|
||||
auto collider = Object::cast_to<Node>(collision_object);
|
||||
if (collider->is_in_group("squashable") && godot::Vector2::UP.dot(collision->get_normal()) > 0.1)
|
||||
{
|
||||
collider->call_deferred("squash");
|
||||
@@ -169,14 +169,15 @@ void alai::player::Player::_physics_process(float delta)
|
||||
auto camera = get_node<godot::Camera2D>("Camera2D");
|
||||
if (camera != nullptr)
|
||||
{
|
||||
auto position = get_global_position();
|
||||
auto position = get_global_position();
|
||||
auto sprite_node = get_node<godot::AnimatedSprite>("AnimatedSprite");
|
||||
if (sprite_node != nullptr)
|
||||
{
|
||||
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 {
|
||||
else
|
||||
{
|
||||
WARN_PRINT("Could not clamp player based on sprite frame size!");
|
||||
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));
|
||||
@@ -196,11 +197,13 @@ void alai::player::Player::_physics_process(float delta)
|
||||
{
|
||||
// The first time the notifier is checked always returns false in the first frame
|
||||
// So skip the check from the first frame
|
||||
if (notifier_initialized) {
|
||||
if (notifier_initialized)
|
||||
{
|
||||
auto event = get_node<alai::Event>("/root/Event");
|
||||
event->emit_signal("player_died");
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
notifier_initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,32 +24,32 @@ namespace alai
|
||||
* @brief The default speed of the player.
|
||||
*
|
||||
*/
|
||||
const float speed = 60.0;
|
||||
const float speed = 60.0;
|
||||
/**
|
||||
* @brief The default jump force applied when jumping.
|
||||
*
|
||||
*/
|
||||
const float jump_force = 300.0;
|
||||
const float jump_force = 300.0;
|
||||
/**
|
||||
* @brief The default bounce force applied when bouncing on something.
|
||||
*
|
||||
*/
|
||||
const float bounce_force = 200.0;
|
||||
const float bounce_force = 200.0;
|
||||
/**
|
||||
* @brief The default gravity applied to the player.
|
||||
*
|
||||
*/
|
||||
const float gravity = 9.81;
|
||||
const float gravity = 9.81;
|
||||
/**
|
||||
* @brief The default run speed multiplier.
|
||||
*
|
||||
*/
|
||||
const float run_speed = 2.0;
|
||||
const float run_speed = 2.0;
|
||||
/**
|
||||
* @brief The default double jump activation state.
|
||||
*
|
||||
*/
|
||||
const bool double_jump = true;
|
||||
const bool double_jump = true;
|
||||
|
||||
/**
|
||||
* @brief This class is used to control the player.
|
||||
@@ -58,7 +58,7 @@ namespace alai
|
||||
*/
|
||||
class Player : public godot::KinematicBody2D
|
||||
{
|
||||
GODOT_CLASS(Player, godot::KinematicBody2D)
|
||||
GODOT_CLASS(Player, godot::KinematicBody2D)
|
||||
|
||||
private:
|
||||
/**
|
||||
@@ -291,7 +291,7 @@ namespace alai
|
||||
*/
|
||||
void _on_level_loaded();
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace player
|
||||
} // namespace alai
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "player/states/PlayerFall.h"
|
||||
|
||||
#include "player/Player.h"
|
||||
#include "player/states/PlayerFall.h"
|
||||
|
||||
void alai::player::PlayerFall::_register_methods()
|
||||
{
|
||||
@@ -46,8 +45,8 @@ void alai::player::PlayerFall::_physics_process(float delta)
|
||||
}
|
||||
|
||||
auto current_speed = parent->get_speed();
|
||||
auto velocity = parent->get_velocity();
|
||||
velocity.x = 0;
|
||||
auto velocity = parent->get_velocity();
|
||||
velocity.x = 0;
|
||||
if (_input->is_action_pressed("run"))
|
||||
{
|
||||
current_speed *= parent->get_run_speed();
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace alai
|
||||
*/
|
||||
class PlayerFall : public State
|
||||
{
|
||||
GODOT_CLASS(PlayerFall, State)
|
||||
GODOT_CLASS(PlayerFall, State)
|
||||
|
||||
private:
|
||||
/**
|
||||
@@ -78,7 +78,7 @@ namespace alai
|
||||
*/
|
||||
void _physics_process(float delta);
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace player
|
||||
} // namespace alai
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "player/states/PlayerIdle.h"
|
||||
|
||||
#include "player/Player.h"
|
||||
#include "player/states/PlayerIdle.h"
|
||||
|
||||
void alai::player::PlayerIdle::_register_methods()
|
||||
{
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace alai
|
||||
*/
|
||||
class PlayerIdle : public State
|
||||
{
|
||||
GODOT_CLASS(PlayerIdle, State)
|
||||
GODOT_CLASS(PlayerIdle, State)
|
||||
|
||||
private:
|
||||
/**
|
||||
@@ -77,7 +77,7 @@ namespace alai
|
||||
*/
|
||||
void _physics_process(float delta);
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace player
|
||||
} // namespace alai
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "player/states/PlayerJump.h"
|
||||
|
||||
#include "player/Player.h"
|
||||
#include "player/states/PlayerJump.h"
|
||||
|
||||
#include <AudioStreamPlayer.hpp>
|
||||
|
||||
@@ -42,16 +41,16 @@ void alai::player::PlayerJump::_state_enter(const godot::String state)
|
||||
double_jumped = false;
|
||||
}
|
||||
|
||||
auto parent = Object::cast_to<Player>(get_parent());
|
||||
auto parent = Object::cast_to<Player>(get_parent());
|
||||
auto velocity = parent->get_velocity();
|
||||
velocity.y = -parent->get_jump_force();
|
||||
velocity.y = -parent->get_jump_force();
|
||||
parent->set_velocity(velocity);
|
||||
}
|
||||
|
||||
void alai::player::PlayerJump::_state_exit()
|
||||
{
|
||||
animated_sprite->set_animation("move");
|
||||
animated_sprite->set_frame(1);
|
||||
animated_sprite->set_animation("move");
|
||||
animated_sprite->set_frame(1);
|
||||
}
|
||||
|
||||
void alai::player::PlayerJump::_physics_process(float delta)
|
||||
@@ -64,8 +63,8 @@ void alai::player::PlayerJump::_physics_process(float delta)
|
||||
}
|
||||
|
||||
auto current_speed = parent->get_speed();
|
||||
auto velocity = parent->get_velocity();
|
||||
velocity.x = 0;
|
||||
auto velocity = parent->get_velocity();
|
||||
velocity.x = 0;
|
||||
if (_input->is_action_pressed("run"))
|
||||
{
|
||||
current_speed *= parent->get_run_speed();
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace alai
|
||||
*/
|
||||
class PlayerJump : public State
|
||||
{
|
||||
GODOT_CLASS(PlayerJump, State)
|
||||
GODOT_CLASS(PlayerJump, State)
|
||||
|
||||
private:
|
||||
/**
|
||||
@@ -85,7 +85,7 @@ namespace alai
|
||||
*/
|
||||
void _physics_process(float delta);
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace player
|
||||
} // namespace alai
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "player/states/PlayerMove.h"
|
||||
|
||||
#include "player/Player.h"
|
||||
#include "player/states/PlayerMove.h"
|
||||
|
||||
void alai::player::PlayerMove::_register_methods()
|
||||
{
|
||||
@@ -40,8 +39,8 @@ void alai::player::PlayerMove::_physics_process(float delta)
|
||||
auto direction_pressed = false;
|
||||
|
||||
auto current_speed = parent->get_speed();
|
||||
auto velocity = parent->get_velocity();
|
||||
velocity.x = 0;
|
||||
auto velocity = parent->get_velocity();
|
||||
velocity.x = 0;
|
||||
if (_input->is_action_pressed("run"))
|
||||
{
|
||||
current_speed *= parent->get_run_speed();
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
#include "state_machine/State.h"
|
||||
|
||||
#include <AnimatedSprite.hpp>
|
||||
#include <Godot.hpp>
|
||||
#include <Input.hpp>
|
||||
#include <AnimatedSprite.hpp>
|
||||
|
||||
namespace alai
|
||||
{
|
||||
@@ -17,7 +17,7 @@ namespace alai
|
||||
*/
|
||||
class PlayerMove : public State
|
||||
{
|
||||
GODOT_CLASS(PlayerMove, State)
|
||||
GODOT_CLASS(PlayerMove, State)
|
||||
|
||||
private:
|
||||
/**
|
||||
@@ -77,7 +77,7 @@ namespace alai
|
||||
*/
|
||||
void _physics_process(float delta);
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace player
|
||||
} // namespace alai
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user