Collision detection
checkCollision
Checks if a player position collides with any tree in the game world.World position of the player to check for collision.
Reference to vector containing positions of all trees in the world.
bool - true if the player collides with any tree, false otherwise.
Implementation:
The player hitbox is 20×40 pixels and tree hitbox is 20×60 pixels. Uses Raylib’s
CheckCollisionRecs() for rectangle collision detection.World generation
tree_spawner
Creates texture instances for all trees in the game world by loading and duplicating the tree image.std::vector<Texture2D> - Vector containing 115 tree textures.
Implementation:
This function loads the tree image once, creates 115 texture copies, then unloads the source image to free memory.
tree_positions
Generates random positions for all trees within the game world boundaries using uniform distribution.std::vector<Vector2> - Vector containing 115 random tree positions within world bounds (0-2000 range).
Implementation:
Uses Mersenne Twister (
std::mt19937) for random number generation with uniform distribution across the 2000×2000 world map.Directional aiming
getDirectionToMouse
Calculates the compass direction from the player to the mouse cursor position for directional indicators.World position of the player character.
World position of the mouse cursor (converted from screen space using camera).
std::string - One of eight compass directions: “east”, “southeast”, “south”, “southwest”, “west”, “northwest”, “north”, “northeast”.
Implementation:
| Angle Range | Direction |
|---|---|
| 337.5° - 22.5° | East |
| 22.5° - 67.5° | Southeast |
| 67.5° - 112.5° | South |
| 112.5° - 157.5° | Southwest |
| 157.5° - 202.5° | West |
| 202.5° - 247.5° | Northwest |
| 247.5° - 292.5° | North |
| 292.5° - 337.5° | Northeast |
Network setup
SetupHost
Initializes the game server to host multiplayer matches, binding to the specified port and waiting for client connections.bool - true if server creation succeeds, false on failure.
Implementation:
Binds to all available network interfaces.
Port number for incoming connections (SERVER_PORT constant).
Maximum number of simultaneous client connections (1v1 gameplay).
Number of network channels for communication.
See Hosting for complete multiplayer hosting guide.
SetupClient
Initializes the game client and attempts to connect to a game server at the configured IP address and port.bool - true if client creation and connection initiation succeed, false on failure.
Implementation:
Target server IP address for connection.
Target server port number.
See Joining for complete multiplayer joining guide.
Global variables
Key global variables used throughout the game:| Variable | Type | Default | Description |
|---|---|---|---|
connectionState | std::string | "DISCONNECTED" | Current network connection state |
clientHost | ENetHost* | nullptr | Client network host instance |
serverPeer | ENetPeer* | nullptr | Client’s connection to server |
serverHost | ENetHost* | nullptr | Server network host instance |
clientPeer | ENetPeer* | nullptr | Server’s connection to client |
bloodRed | Color | {128, 0, 0, 255} | Color for red spell projectiles |
spellColor | Color | RED | Default spell color |
number_of_trees | int | 115 | Total trees in game world |
state | std::string | "MENU" | Current game state |