Collision detection
checkCollision
Checks if a player position collides with any tree in the game world.Vector2
World position of the player to check for collision.
std::vector<Vector2>&
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.Vector2
World position of the player character.
Vector2
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:
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:
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.bool - true if client creation and connection initiation succeed, false on failure.
Implementation:
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.