Protocol

The Protocol class handles the processing of various game-related messages, such as player creation, entity updates, health management, and more.The class includes methods for handling different types of network operations, including updating player positions, enemy data, bullets, and obstacles.

FunctionsDescription
handleMessageHandles incoming messages based on the opCode extracted from the buffer and calls the appropriate function for each message type.
handleCreatePlayerCallbackHandles player creation by receiving the player’s ID and dimensions, then initializes their properties in the EntityManager.
handleCreatePlayerBroadcastHandles player creation via a broadcast message, initializing the player’s ID, name, and properties in the EntityManager. It allows retrieving information about the existence of other players.
handleUpdatePlayerUpdates a player’s position based on the received data and updates the EntityManager.
handleUpdateViewportUpdates the client’s viewport with the new viewport value.
handleUpdateBlocksUpdates the obstacles based on the ID, coordinates, size, and type, then updates the EntityManager.
handleUpdateEnemiesUpdates the position and properties of enemies based on their type and adds them to the EntityManager.
handleUpdatePlayerInfosUpdates the player’s information such as score and kills based on the received data.
handleUpdateBulletsUpdates bullet information, including position and type, and adds them to the EntityManager.
handleDeleteEntityDeletes an entity from the EntityManager based on its ID, including related entities.
handleUpdateEntityHealthUpdates an entity’s health and manages win/loss conditions based on the entity’s health.