Skip to main content

Collision detection

checkCollision

Checks if a player position collides with any tree in the game world.
Parameters:
Vector2
World position of the player to check for collision.
std::vector<Vector2>&
Reference to vector containing positions of all trees in the world.
Returns: 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.
Usage:

World generation

tree_spawner

Creates texture instances for all trees in the game world by loading and duplicating the tree image.
Returns: 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.
Returns: 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.
Parameters:
Vector2
World position of the player character.
Vector2
World position of the mouse cursor (converted from screen space using camera).
Returns: std::string - One of eight compass directions: “east”, “southeast”, “south”, “southwest”, “west”, “northwest”, “north”, “northeast”. Implementation:
Direction mapping:
This function uses atan2() to calculate the angle between two points, then converts to degrees and maps to one of eight cardinal/intercardinal directions.

Network setup

SetupHost

Initializes the game server to host multiplayer matches, binding to the specified port and waiting for client connections.
Returns: bool - true if server creation succeeds, false on failure. Implementation:
Configuration:
enet_uint32
default:"ENET_HOST_ANY"
Binds to all available network interfaces.
enet_uint16
default:"7777"
Port number for incoming connections (SERVER_PORT constant).
size_t
default:"1"
Maximum number of simultaneous client connections (1v1 gameplay).
size_t
default:"2"
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.
Returns: bool - true if client creation and connection initiation succeed, false on failure. Implementation:
Configuration:
const char*
default:"127.0.0.1"
Target server IP address for connection.
const int
default:"7777"
Target server port number.
See Joining for complete multiplayer joining guide.

Global variables

Key global variables used throughout the game:
These are global variables accessible throughout the codebase. Modify with caution in multiplayer contexts.