16 .with<ecs::Velocity>(
"player_velocity", 0.F, 0.F)
21 .with<ecs::Player>(
"player",
true)
83 sendInputsIfChanged();
91 auto checkKey = [
this](
const eng::Key key) ->
bool
93 auto it = m_keysPressed.find(key);
94 return it != m_keysPressed.end() && it->second;
103 sendInputToServer(up, down, left, right, shoot);
108 std::vector<std::uint8_t> inputData;
109 inputData.push_back(up ? 1 : 0);
110 inputData.push_back(down ? 1 : 0);
111 inputData.push_back(left ? 1 : 0);
112 inputData.push_back(right ? 1 : 0);
113 inputData.push_back(shoot ? 1 : 0);
118 eventRecord.
data = inputData;
121 std::vector<rnp::EventRecord> events;
122 events.push_back(eventRecord);
135 if (!keyboardEntities.empty())
137 keyboardEntity = keyboardEntities.begin()->first;
146 auto checkKey = [
this](
const eng::Key key) ->
bool
148 auto it = m_keysPressed.find(key);
149 return it != m_keysPressed.end() && it->second;
165 constexpr float SPEED = 500.0f;
169 auto checkKey = [
this](
const eng::Key key) ->
bool
171 auto it = m_keysPressed.find(key);
172 return it != m_keysPressed.end() && it->second;
182 velocity->y = -SPEED;
190 velocity->x = -SPEED;
197 if (velocity->x != 0.0f && velocity->y != 0.0f)
199 velocity->x *= 0.707f;
200 velocity->y *= 0.707f;
203 transform->x += velocity->x * dt;
204 transform->y += velocity->y * dt;
206 transform->x = std::max(0.0f, std::min(1920.0f, transform->x));
207 transform->y = std::max(0.0f, std::min(1080.0f, transform->y));
215 return it != m_keysPressed.end() && it->second;
This file contains the component definitions.
Configuration constants for the multiplayer game.
Utility functions for hitbox calculations.
Multiplayer player controller system for R-Type client.
This file contains the network protocol.
Network packet serializer for RNP protocol.
EntityBuilder & with(Args &&...args)
Class for managing entities and their components.
EntityBuilder createEntity()
std::unordered_map< Entity, T > & getAll()
T * getComponent(Entity e)
bool isSpacePressed() const
Check if space bar is currently pressed.
void sendInputToServer(bool up, bool down, bool left, bool right, bool shoot) const
Send input command to server via event bus.
void sendInputsIfChanged()
Send input update if state has changed.
ecs::Entity m_playerEntity
Local player entity ID.
void handleInput(ecs::Registry ®istry, const eng::Event &event)
Handle input events from the window.
ecs::Entity createPlayer(ecs::Registry ®istry, float x, float y)
Create the local player entity.
void update(ecs::Registry ®istry, float dt) override
Update the player controller system (called each frame)
Binary serializer for RNP protocol packets.
const std::vector< std::uint8_t > & getData() const
Get the serialized data.
void serializeEntityEvents(const std::vector< EventRecord > &events)
Serialize multiple EventRecords for ENTITY_EVENT packet.
constexpr Entity INVALID_ENTITY
constexpr float MAX_CHARGE
constexpr float PLAYER_RADIUS
constexpr float SPRITE_HEIGHT
constexpr float SPRITE_WIDTH
constexpr auto TEXTURE_PLAYER
std::pair< float, float > calculateHitboxOffsets(const float spriteWidth, const float spriteHeight, const float scale)
Calculate hitbox offsets to center the hitbox on the sprite.
static constexpr std::uint32_t NETWORK_CLIENT
Event record for ENTITY_EVENT packets (TLV format)
std::vector< std::uint8_t > data