generated from Persson-dev/Godot-Xmake
brodacast shoot
This commit is contained in:
@@ -25,13 +25,15 @@ class World : public godot::Node3D, public protocol::PacketHandler {
|
|||||||
|
|
||||||
void HandlePacket(const protocol::packets::PlayerJoin&) override;
|
void HandlePacket(const protocol::packets::PlayerJoin&) override;
|
||||||
void HandlePacket(const protocol::packets::PlayerLeave&) override;
|
void HandlePacket(const protocol::packets::PlayerLeave&) override;
|
||||||
|
void HandlePacket(const protocol::packets::PlayerShoot&) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NetworkInterface* m_NetworkInterface;
|
NetworkInterface* m_NetworkInterface;
|
||||||
godot::Node* m_Players;
|
godot::Node* m_Players;
|
||||||
float m_PassedTime;
|
float m_PassedTime;
|
||||||
|
|
||||||
|
virtual void AddProjectile(
|
||||||
|
PlayerID a_Shooter, const godot::Vector3& a_Position, const godot::Vector3& a_Rotation, const godot::Vector3& a_Velocity);
|
||||||
virtual void AddPlayer(PlayerID a_PlayerId, godot::String a_PlayerName);
|
virtual void AddPlayer(PlayerID a_PlayerId, godot::String a_PlayerName);
|
||||||
virtual void RemovePlayer(PlayerID a_PlayerId);
|
virtual void RemovePlayer(PlayerID a_PlayerId);
|
||||||
virtual void SetPlayerPositionAndRotation(
|
virtual void SetPlayerPositionAndRotation(
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <blitz/common/Types.h>
|
#include <blitz/common/Types.h>
|
||||||
#include <vector>
|
|
||||||
#include <godot_cpp/variant/string.hpp>
|
#include <godot_cpp/variant/string.hpp>
|
||||||
#include <godot_cpp/variant/vector3.hpp>
|
#include <godot_cpp/variant/vector3.hpp>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace blitz {
|
namespace blitz {
|
||||||
namespace protocol {
|
namespace protocol {
|
||||||
@@ -66,7 +66,12 @@ struct PlayerPositionAndRotation {
|
|||||||
godot::Vector3 m_Velocity;
|
godot::Vector3 m_Velocity;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PlayerShoot {};
|
struct PlayerShoot {
|
||||||
|
PlayerID m_Sender;
|
||||||
|
godot::Vector3 m_Position;
|
||||||
|
godot::Vector3 m_Rotation;
|
||||||
|
godot::Vector3 m_Velocity;
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace data
|
} // namespace data
|
||||||
} // namespace protocol
|
} // namespace protocol
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
namespace blitz {
|
namespace blitz {
|
||||||
|
|
||||||
|
class NetworkInterface;
|
||||||
|
|
||||||
class PlayerController : public godot::Node {
|
class PlayerController : public godot::Node {
|
||||||
GDCLASS(PlayerController, godot::Node)
|
GDCLASS(PlayerController, godot::Node)
|
||||||
protected:
|
protected:
|
||||||
@@ -25,6 +27,7 @@ class PlayerController : public godot::Node {
|
|||||||
float m_Speed;
|
float m_Speed;
|
||||||
Player* m_Player;
|
Player* m_Player;
|
||||||
godot::Node3D* m_Head;
|
godot::Node3D* m_Head;
|
||||||
|
NetworkInterface* m_NetworkInterface;
|
||||||
|
|
||||||
void UpdateBobbing(float delta);
|
void UpdateBobbing(float delta);
|
||||||
void UpdateFOV(float delta);
|
void UpdateFOV(float delta);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <blitz/godot/World.h>
|
#include <blitz/godot/World.h>
|
||||||
|
|
||||||
#include <blitz/factory/PlayerFactory.h>
|
#include <blitz/factory/PlayerFactory.h>
|
||||||
|
#include <blitz/factory/ProjectileFactory.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>
|
||||||
@@ -28,6 +29,7 @@ void World::_ready() {
|
|||||||
m_NetworkInterface->RegisterHandler(protocol::PacketType::PlayerJoin, *this);
|
m_NetworkInterface->RegisterHandler(protocol::PacketType::PlayerJoin, *this);
|
||||||
m_NetworkInterface->RegisterHandler(protocol::PacketType::PlayerLeave, *this);
|
m_NetworkInterface->RegisterHandler(protocol::PacketType::PlayerLeave, *this);
|
||||||
m_NetworkInterface->RegisterHandler(protocol::PacketType::PlayerPositionAndRotation, *this);
|
m_NetworkInterface->RegisterHandler(protocol::PacketType::PlayerPositionAndRotation, *this);
|
||||||
|
m_NetworkInterface->RegisterHandler(protocol::PacketType::PlayerShoot, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -60,6 +62,11 @@ void World::HandlePacket(const protocol::packets::PlayerLeave& a_PlayerLeave) {
|
|||||||
RemovePlayer(a_PlayerLeave.m_Data.m_PlayerId);
|
RemovePlayer(a_PlayerLeave.m_Data.m_PlayerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void World::HandlePacket(const protocol::packets::PlayerShoot& a_PlayerShoot) {
|
||||||
|
const protocol::data::PlayerShoot& playerShoot = a_PlayerShoot.m_Data;
|
||||||
|
AddProjectile(playerShoot.m_Sender, playerShoot.m_Position, playerShoot.m_Rotation, playerShoot.m_Velocity);
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
@@ -93,4 +100,22 @@ void World::SetPlayerPositionAndRotation(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void World::AddProjectile(
|
||||||
|
PlayerID a_Shooter, const godot::Vector3& a_Position, const godot::Vector3& a_Rotation, const godot::Vector3& a_Velocity) {
|
||||||
|
|
||||||
|
Player* shooter = GetPlayerById(a_Shooter);
|
||||||
|
if (!shooter)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Bullet* bullet = ProjectileFactory::CreatePen();
|
||||||
|
|
||||||
|
bullet->set_position(a_Position);
|
||||||
|
Transform3D bulletTransform = bullet->get_transform();
|
||||||
|
bulletTransform.basis.set_euler(a_Rotation);
|
||||||
|
bullet->set_transform(bulletTransform);
|
||||||
|
|
||||||
|
Node* entities = get_node<Node>("WorldContent/Entities");
|
||||||
|
entities->add_child(bullet);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace blitz
|
} // namespace blitz
|
||||||
@@ -272,9 +272,13 @@ void Deserializer::DeserializePacketData(data::PlayerPositionAndRotation& a_Pack
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Serializer::SerializePacketData(const data::PlayerShoot& a_Packet) {}
|
void Serializer::SerializePacketData(const data::PlayerShoot& a_Packet) {
|
||||||
|
m_Buffer << a_Packet.m_Sender << a_Packet.m_Position << a_Packet.m_Rotation << a_Packet.m_Velocity;
|
||||||
|
}
|
||||||
|
|
||||||
void Deserializer::DeserializePacketData(data::PlayerShoot& a_Packet) {}
|
void Deserializer::DeserializePacketData(data::PlayerShoot& a_Packet) {
|
||||||
|
m_Buffer >> a_Packet.m_Sender >> a_Packet.m_Position >> a_Packet.m_Rotation >> a_Packet.m_Velocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <client/PlayerController.h>
|
#include <client/PlayerController.h>
|
||||||
|
|
||||||
#include <blitz/factory/ProjectileFactory.h>
|
#include <blitz/factory/ProjectileFactory.h>
|
||||||
|
#include <blitz/godot/NetworkInterface.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>
|
||||||
@@ -68,6 +69,9 @@ void PlayerController::_ready() {
|
|||||||
|
|
||||||
m_Player->SetPosition({0, 1, 0});
|
m_Player->SetPosition({0, 1, 0});
|
||||||
m_Player->SetVelocity({0, 0, 0});
|
m_Player->SetVelocity({0, 0, 0});
|
||||||
|
|
||||||
|
m_NetworkInterface = m_Player->get_node<NetworkInterface>("../../../../Network");
|
||||||
|
DEV_ASSERT(m_NetworkInterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerController::_unhandled_input(const godot::Ref<godot::InputEvent>& a_Event) {
|
void PlayerController::_unhandled_input(const godot::Ref<godot::InputEvent>& a_Event) {
|
||||||
@@ -109,13 +113,10 @@ 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")) {
|
||||||
Bullet* bullet = ProjectileFactory::CreatePen();
|
// we don't use velocity yet
|
||||||
|
protocol::packets::PlayerShoot packet(
|
||||||
bullet->set_position(m_Camera->get_global_position());
|
{m_Player->GetId(), m_Camera->get_global_position(), m_Camera->get_global_transform().basis.get_euler(), {}});
|
||||||
bullet->set_transform(m_Camera->get_global_transform());
|
m_NetworkInterface->BroadcastPacket(packet);
|
||||||
|
|
||||||
Node* entities = m_Player->get_node<Node>("../../Entities");
|
|
||||||
entities->add_child(bullet);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user