Skip to main content

Overview

The Player is a specialized character entity that represents a playable character in the game. Players can be controlled via keyboard/mouse or gamepad, render to individual canvases, and support split-screen multiplayer.

Function Reference

player_new()

Creates and initializes a new player entity.
t_player *player_new(t_game *game, t_ftm_window *window, char identifier);
game
t_game *
required
Pointer to the game instance
window
t_ftm_window *
required
Pointer to the window instance
identifier
char
required
Character identifier for configuration lookup. Valid values: 'N', 'S', 'E', 'W' for spawn direction
return
t_player *
Pointer to the newly created player, or NULL on allocation failure

Structure Definition

s_player

The player structure extends t_character with rendering and controller properties.
struct s_player
{
    t_character      character;
    t_ftm_image      *canvas;
    t_coords         last_canvas_pos;
    int              controller_id;
    bool             friendly_fire;
};
character
t_character
Base character data (see Characters)
canvas
t_ftm_image *
Individual render canvas for this player (split-screen support)
last_canvas_pos
t_coords
Last recorded canvas position for rendering optimization
controller_id
int
Controller identifier for input mapping
friendly_fire
bool
Whether this player can damage other players. Configurable via map type FRIENDLY_FIRE

Configuration

Players are configured through map type identifiers. The following constants define player behavior:

Player Constants

#define PLAYER_RAYS_NO_HIT_LENGTH 50.0
#define PLAYER_FOV 66.0
#define PLAYER_RAY_SUBRAYS 5
#define PLAYER_MOUSE_LOOK_VELOCITY 20.0
#define PLAYER_KEY_LOOK_VELOCITY 180.0
#define PLAYER_WALK_VELOCITY 4.0
#define PLAYER_SPRINT_VELOCITY 6.0
#define PLAYER_RAY_HIT_ENTITIES_NUMBER 5
#define PLAYER_MAX_TARGET_DISTANCE 1.2
#define PLAYER_WIDTH 0.23
#define PLAYER_HEIGHT 0.23
#define PLAYER_MAX 4
#define PLAYER_DEAD_RESET_DELAY 2000
PLAYER_RAYS_NO_HIT_LENGTH
double
Maximum ray distance when no collision detected
PLAYER_FOV
double
Field of view in degrees
PLAYER_RAY_SUBRAYS
int
Number of sub-rays for improved collision detection
PLAYER_MOUSE_LOOK_VELOCITY
double
Mouse look sensitivity multiplier
PLAYER_KEY_LOOK_VELOCITY
double
Keyboard look rotation speed in degrees per second
PLAYER_WALK_VELOCITY
double
Walking speed in units per second
PLAYER_SPRINT_VELOCITY
double
Sprinting speed in units per second
PLAYER_RAY_HIT_ENTITIES_NUMBER
int
Maximum number of entities detected per ray
PLAYER_MAX_TARGET_DISTANCE
double
Maximum distance for entity interaction/targeting
PLAYER_WIDTH
double
Player collision width in map units
PLAYER_HEIGHT
double
Player collision height in map units
PLAYER_MAX
int
Maximum number of simultaneous players (split-screen limit)
PLAYER_DEAD_RESET_DELAY
int
Delay in milliseconds before respawning after death

Spawn Direction

The identifier determines initial player orientation:
  • 'N' - North (yaw: 270.0°)
  • 'S' - South (yaw: 90.0°)
  • 'E' - East (yaw: 0.0°)
  • 'W' - West (yaw: 180.0°)

Map Type Configuration

Players can be customized via map type properties:
N_CONTROLLER PLAYER
FRIENDLY_FIRE FALSE
N_COLLISION assets/sounds/player_collision.wav
CONTROLLER
string
Controller type. Set to "PLAYER" for player-controlled entities
FRIENDLY_FIRE
string
"TRUE" to enable damage between players, "FALSE" to disable (default: TRUE)
COLLISION
string
Path to collision sound effect

Example

// Create a player spawning facing North
t_player *player = player_new(game, window, 'N');

if (!player)
    return (error_handler("Failed to create player"));

// Access player properties
player->friendly_fire = false;
player->controller_id = 0;

// Access inherited character properties
player->character.ammo = 50;
player->character.score = 0;
player->character.billboard.entity.health = 100;

See Also

Build docs developers (and LLMs) love