generated from Persson-dev/Godot-Xmake
make factories
This commit is contained in:
11
include/blitz/factory/PlayerFactory.h
Normal file
11
include/blitz/factory/PlayerFactory.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <client/Player.h>
|
||||||
|
|
||||||
|
namespace blitz {
|
||||||
|
namespace PlayerFactory {
|
||||||
|
|
||||||
|
Player* CreateStudent();
|
||||||
|
|
||||||
|
} // namespace PlayerFactory
|
||||||
|
} // namespace blitz
|
||||||
11
include/blitz/factory/ProjectileFactory.h
Normal file
11
include/blitz/factory/ProjectileFactory.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <client/Bullet.h>
|
||||||
|
|
||||||
|
namespace blitz {
|
||||||
|
namespace ProjectileFactory {
|
||||||
|
|
||||||
|
Bullet* CreatePen();
|
||||||
|
|
||||||
|
} // namespace ProjectileFactory
|
||||||
|
} // namespace blitz
|
||||||
17
src/blitz/factory/PlayerFactory.cpp
Normal file
17
src/blitz/factory/PlayerFactory.cpp
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#include <blitz/factory/PlayerFactory.h>
|
||||||
|
|
||||||
|
#include <godot_cpp/classes/packed_scene.hpp>
|
||||||
|
#include <godot_cpp/classes/resource_loader.hpp>
|
||||||
|
|
||||||
|
namespace blitz {
|
||||||
|
namespace PlayerFactory {
|
||||||
|
|
||||||
|
using namespace godot;
|
||||||
|
|
||||||
|
Player* CreateStudent() {
|
||||||
|
Ref<PackedScene> scene = ResourceLoader::get_singleton()->load("res://Scenes/Characters/remy.tscn");
|
||||||
|
return Object::cast_to<Player>(scene->instantiate());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace PlayerFactory
|
||||||
|
} // namespace blitz
|
||||||
17
src/blitz/factory/ProjectileFactory.cpp
Normal file
17
src/blitz/factory/ProjectileFactory.cpp
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#include <blitz/factory/ProjectileFactory.h>
|
||||||
|
|
||||||
|
#include <godot_cpp/classes/packed_scene.hpp>
|
||||||
|
#include <godot_cpp/classes/resource_loader.hpp>
|
||||||
|
|
||||||
|
namespace blitz {
|
||||||
|
namespace ProjectileFactory {
|
||||||
|
|
||||||
|
using namespace godot;
|
||||||
|
|
||||||
|
Bullet* CreatePen() {
|
||||||
|
Ref<PackedScene> bulletScene = ResourceLoader::get_singleton()->load("res://Scenes/Weapons/pen.tscn");
|
||||||
|
return Object::cast_to<Bullet>(bulletScene->instantiate());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace ProjectileFactory
|
||||||
|
} // namespace blitz
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
#include <blitz/godot/World.h>
|
#include <blitz/godot/World.h>
|
||||||
|
|
||||||
|
#include <blitz/factory/PlayerFactory.h>
|
||||||
#include <blitz/godot/NetworkInterface.h>
|
#include <blitz/godot/NetworkInterface.h>
|
||||||
#include <client/Player.h>
|
#include <client/Player.h>
|
||||||
#include <client/PlayerController.h>
|
#include <client/PlayerController.h>
|
||||||
#include <godot_cpp/classes/engine.hpp>
|
#include <godot_cpp/classes/engine.hpp>
|
||||||
#include <godot_cpp/classes/multiplayer_api.hpp>
|
#include <godot_cpp/classes/multiplayer_api.hpp>
|
||||||
#include <godot_cpp/classes/packed_scene.hpp>
|
|
||||||
#include <godot_cpp/classes/resource_loader.hpp>
|
|
||||||
#include <godot_cpp/variant/utility_functions.hpp>
|
#include <godot_cpp/variant/utility_functions.hpp>
|
||||||
|
|
||||||
|
|
||||||
@@ -14,8 +13,6 @@ using namespace godot;
|
|||||||
|
|
||||||
namespace blitz {
|
namespace blitz {
|
||||||
|
|
||||||
static const char PlayerScenePath[] = "res://Scenes/Characters/remy.tscn";
|
|
||||||
|
|
||||||
void World::_bind_methods() {}
|
void World::_bind_methods() {}
|
||||||
|
|
||||||
void World::_ready() {
|
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) {
|
void World::AddPlayer(PlayerID a_PlayerId, String a_PlayerName) {
|
||||||
UtilityFunctions::print("New Player with id : ", a_PlayerId, " and name ", a_PlayerName);
|
UtilityFunctions::print("New Player with id : ", a_PlayerId, " and name ", a_PlayerName);
|
||||||
|
|
||||||
Ref<PackedScene> serverScene = ResourceLoader::get_singleton()->load(PlayerScenePath);
|
Player* player = PlayerFactory::CreateStudent();
|
||||||
|
|
||||||
Player* player = Object::cast_to<Player>(serverScene->instantiate());
|
|
||||||
player->set_name(UtilityFunctions::var_to_str(a_PlayerId));
|
player->set_name(UtilityFunctions::var_to_str(a_PlayerId));
|
||||||
player->m_PeerId = a_PlayerId;
|
player->m_PeerId = a_PlayerId;
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
#include <client/PlayerController.h>
|
#include <client/PlayerController.h>
|
||||||
|
|
||||||
|
#include <blitz/factory/ProjectileFactory.h>
|
||||||
#include <godot_cpp/classes/camera3d.hpp>
|
#include <godot_cpp/classes/camera3d.hpp>
|
||||||
#include <godot_cpp/classes/engine.hpp>
|
#include <godot_cpp/classes/engine.hpp>
|
||||||
#include <godot_cpp/classes/input.hpp>
|
#include <godot_cpp/classes/input.hpp>
|
||||||
#include <godot_cpp/classes/input_event_mouse_motion.hpp>
|
#include <godot_cpp/classes/input_event_mouse_motion.hpp>
|
||||||
#include <godot_cpp/classes/input_map.hpp>
|
#include <godot_cpp/classes/input_map.hpp>
|
||||||
#include <godot_cpp/classes/packed_scene.hpp>
|
|
||||||
#include <godot_cpp/classes/resource_loader.hpp>
|
|
||||||
#include <godot_cpp/core/math.hpp>
|
#include <godot_cpp/core/math.hpp>
|
||||||
#include <godot_cpp/variant/utility_functions.hpp>
|
#include <godot_cpp/variant/utility_functions.hpp>
|
||||||
|
|
||||||
@@ -39,8 +38,6 @@ static constexpr float MAX_FOV_VELOCITY = SPRINT_SPEED * 2.0f;
|
|||||||
static const float LerpValue = 0.10;
|
static const float LerpValue = 0.10;
|
||||||
static const float AnimationBlend = 7.0;
|
static const float AnimationBlend = 7.0;
|
||||||
|
|
||||||
static const char BulletScenePath[] = "res://Scenes/Weapons/pen.tscn";
|
|
||||||
|
|
||||||
void PlayerController::_bind_methods() {}
|
void PlayerController::_bind_methods() {}
|
||||||
|
|
||||||
PlayerController::PlayerController() : m_BobTime(0) {}
|
PlayerController::PlayerController() : m_BobTime(0) {}
|
||||||
@@ -112,8 +109,7 @@ void PlayerController::_process(float a_Delta) {
|
|||||||
|
|
||||||
void PlayerController::Shoot() {
|
void PlayerController::Shoot() {
|
||||||
if (Input::get_singleton()->is_action_pressed("shoot")) {
|
if (Input::get_singleton()->is_action_pressed("shoot")) {
|
||||||
Ref<PackedScene> bulletScene = ResourceLoader::get_singleton()->load(BulletScenePath);
|
Bullet* bullet = ProjectileFactory::CreatePen();
|
||||||
auto* bullet = Object::cast_to<Node3D>(bulletScene->instantiate());
|
|
||||||
|
|
||||||
bullet->set_position(m_Camera->get_global_position());
|
bullet->set_position(m_Camera->get_global_position());
|
||||||
bullet->set_transform(m_Camera->get_global_transform());
|
bullet->set_transform(m_Camera->get_global_transform());
|
||||||
|
|||||||
Reference in New Issue
Block a user