Skip to main content
Wizard Duel supports real-time multiplayer battles between two players using the ENet networking library. One player hosts the game while another joins, and position data is synchronized in real-time.

Features

  • 1v1 battles: Supports two players in direct combat
  • Real-time synchronization: Player positions are transmitted and updated every frame
  • Low-latency networking: Built on ENet for reliable UDP networking
  • Ping display: Shows round-trip time to monitor connection quality

Network configuration

The game uses the following network settings:
main.cpp
By default, the server runs on localhost (127.0.0.1) on port 7777. For LAN play, the host should replace SERVER_IP with their local network IP address.

Connection states

The game tracks connection status using four states:
  • DISCONNECTED: No active connection, initial state
  • HOSTING: Server is running and waiting for a client to join
  • JOINING: Client is attempting to connect to a server
  • CONNECTED: Connection established, game is active
main.cpp

Position synchronization

Player positions are synchronized using the PositionPacket structure:
main.cpp
When a player moves, their position is packaged and sent to the opponent:
main.cpp

ENet initialization

Before any networking can occur, ENet must be initialized:
main.cpp
ENet initialization must happen before creating any hosts or peers. The atexit call ensures proper cleanup when the program terminates.

Network cleanup

When the game exits, network resources are properly released:
main.cpp

Ping monitoring

The game displays real-time ping to help players monitor connection quality:
main.cpp
ENet automatically tracks the round-trip time for each peer connection.