diff --git a/include/blitz/factory/PlayerFactory.h b/include/blitz/factory/PlayerFactory.h new file mode 100644 index 0000000..8531dfd --- /dev/null +++ b/include/blitz/factory/PlayerFactory.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +namespace blitz { +namespace PlayerFactory { + +Player* CreateStudent(); + +} // namespace PlayerFactory +} // namespace blitz diff --git a/include/blitz/factory/ProjectileFactory.h b/include/blitz/factory/ProjectileFactory.h new file mode 100644 index 0000000..c7ac4e0 --- /dev/null +++ b/include/blitz/factory/ProjectileFactory.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +namespace blitz { +namespace ProjectileFactory { + +Bullet* CreatePen(); + +} // namespace ProjectileFactory +} // namespace blitz diff --git a/src/blitz/factory/PlayerFactory.cpp b/src/blitz/factory/PlayerFactory.cpp new file mode 100644 index 0000000..34c127a --- /dev/null +++ b/src/blitz/factory/PlayerFactory.cpp @@ -0,0 +1,17 @@ +#include + +#include +#include + +namespace blitz { +namespace PlayerFactory { + +using namespace godot; + +Player* CreateStudent() { + Ref scene = ResourceLoader::get_singleton()->load("res://Scenes/Characters/remy.tscn"); + return Object::cast_to(scene->instantiate()); +} + +} // namespace PlayerFactory +} // namespace blitz diff --git a/src/blitz/factory/ProjectileFactory.cpp b/src/blitz/factory/ProjectileFactory.cpp new file mode 100644 index 0000000..e2b8088 --- /dev/null +++ b/src/blitz/factory/ProjectileFactory.cpp @@ -0,0 +1,17 @@ +#include + +#include +#include + +namespace blitz { +namespace ProjectileFactory { + +using namespace godot; + +Bullet* CreatePen() { + Ref bulletScene = ResourceLoader::get_singleton()->load("res://Scenes/Weapons/pen.tscn"); + return Object::cast_to(bulletScene->instantiate()); +} + +} // namespace ProjectileFactory +} // namespace blitz diff --git a/src/blitz/godot/World.cpp b/src/blitz/godot/World.cpp index 63a8734..6e9eb6a 100644 --- a/src/blitz/godot/World.cpp +++ b/src/blitz/godot/World.cpp @@ -1,12 +1,11 @@ #include +#include #include #include #include #include #include -#include -#include #include @@ -14,8 +13,6 @@ using namespace godot; namespace blitz { -static const char PlayerScenePath[] = "res://Scenes/Characters/remy.tscn"; - void World::_bind_methods() {} void World::_ready() { @@ -66,9 +63,7 @@ void World::HandlePacket(const protocol::packets::PlayerLeave& a_PlayerLeave) { void World::AddPlayer(PlayerID a_PlayerId, String a_PlayerName) { UtilityFunctions::print("New Player with id : ", a_PlayerId, " and name ", a_PlayerName); - Ref serverScene = ResourceLoader::get_singleton()->load(PlayerScenePath); - - Player* player = Object::cast_to(serverScene->instantiate()); + Player* player = PlayerFactory::CreateStudent(); player->set_name(UtilityFunctions::var_to_str(a_PlayerId)); player->m_PeerId = a_PlayerId; diff --git a/src/client/PlayerController.cpp b/src/client/PlayerController.cpp index 6fddd17..60408f0 100644 --- a/src/client/PlayerController.cpp +++ b/src/client/PlayerController.cpp @@ -1,12 +1,11 @@ #include +#include #include #include #include #include #include -#include -#include #include #include @@ -39,8 +38,6 @@ static constexpr float MAX_FOV_VELOCITY = SPRINT_SPEED * 2.0f; static const float LerpValue = 0.10; static const float AnimationBlend = 7.0; -static const char BulletScenePath[] = "res://Scenes/Weapons/pen.tscn"; - void PlayerController::_bind_methods() {} PlayerController::PlayerController() : m_BobTime(0) {} @@ -112,8 +109,7 @@ void PlayerController::_process(float a_Delta) { void PlayerController::Shoot() { if (Input::get_singleton()->is_action_pressed("shoot")) { - Ref bulletScene = ResourceLoader::get_singleton()->load(BulletScenePath); - auto* bullet = Object::cast_to(bulletScene->instantiate()); + Bullet* bullet = ProjectileFactory::CreatePen(); bullet->set_position(m_Camera->get_global_position()); bullet->set_transform(m_Camera->get_global_transform());