Skip to main content

Overview

The item system provides a flexible framework for weapons, collectibles, and usable items. Items can be carried in character inventories, dropped as world entities, and configured with custom behaviors.

Function Reference

item_new()

Creates a generic item.
t_item *item_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
Item identifier for configuration lookup
return
t_item *
Pointer to the newly created item, or NULL on allocation failure

weapon_new()

Creates a weapon item with damage and range properties.
t_weapon *weapon_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
Weapon identifier for configuration lookup
return
t_weapon *
Pointer to the newly created weapon, or NULL on allocation failure

collectible_new()

Creates a collectible item that modifies character stats.
t_collectible *collectible_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
Collectible identifier for configuration lookup
return
t_collectible *
Pointer to the newly created collectible, or NULL on allocation failure

Structure Definitions

s_item

Base item structure with common properties and behavior hooks.
struct s_item
{
    void            (*frame)(t_item *item);
    void            (*clear)(void *this);
    void            (*use)(t_item *item, t_drop *drop);
    void            (*drop)(t_game *, t_ftm_window *, t_item *, t_character *dropper);
    char            identifier;
    char            *name;
    char            *description;
    bool            weapon;
    bool            collectible;
    bool            can_use;
    t_character     *user;
    bool            prev_using;
    bool            already_using;
    bool            single_use;
    t_time          use_delay;
    t_fta_audio     *cant_sound;
    t_time          last_cant_use_sound_play;
    t_time          last_use;
    t_fta_audio     *use_sound;
    t_fta_audio     *get_sound;
    t_sprite        *icon_use_sprite;
    t_sprite        *_icon_sprite;
    t_sprite        *icon_sprite;
    t_sprite        *screen_use_sprite;
    t_sprite        *screen_sprite;
    t_sprite        *_screen_sprite;
};
frame
void (*)(t_item *)
Called every frame to update item state
clear
void (*)(void *)
Cleanup function called before freeing item
use
void (*)(t_item *, t_drop *)
Called when item is used by a character
drop
void (*)(t_game *, t_ftm_window *, t_item *, t_character *)
Called when item is dropped into the world
identifier
char
Unique character identifying this item type
name
char *
Display name of the item
description
char *
Item description text
weapon
bool
True if item is a weapon
collectible
bool
True if item is a collectible
can_use
bool
Whether item can currently be used
user
t_character *
Character currently using this item
prev_using
bool
Previous frame’s usage state
already_using
bool
True if item is currently being used
single_use
bool
If true, item is consumed after one use
use_delay
t_time
Minimum delay between uses in milliseconds
cant_sound
t_fta_audio *
Sound played when item cannot be used
last_cant_use_sound_play
t_time
Timestamp of last “can’t use” sound play
last_use
t_time
Timestamp of last use
use_sound
t_fta_audio *
Sound played when item is used
get_sound
t_fta_audio *
Sound played when item is picked up
icon_use_sprite
t_sprite *
Icon sprite displayed during use
_icon_sprite
t_sprite *
Original icon sprite reference
icon_sprite
t_sprite *
Current icon sprite (for HUD)
screen_use_sprite
t_sprite *
Full-screen sprite during use
screen_sprite
t_sprite *
Current screen sprite
_screen_sprite
t_sprite *
Original screen sprite reference

s_weapon

Weapon item with combat properties.
struct s_weapon
{
    t_item      item;
    int         damage;
    double      range;
    int         ammo_usage;
};
item
t_item
Base item structure
damage
int
Damage dealt per hit
range
double
Maximum effective range
ammo_usage
int
Ammunition consumed per use

s_collectible

Collectible item that modifies character stats.
struct s_collectible
{
    t_item  item;
    int     health;
    int     score;
    int     ammo;
};
item
t_item
Base item structure
health
int
Health points added when collected
score
int
Score points added when collected
ammo
int
Ammunition added when collected

Map Type Configuration

Item Configuration

w_NAME Pistol
w_DESCRIPTION A standard 9mm pistol
w_USE_DELAY 0.5
w_SINGLE_USE FALSE
w_ICON assets/sprites/pistol_icon.bmp
w_SCREEN assets/sprites/pistol_screen.bmp
w_ICON_USE assets/sprites/pistol_icon_use.bmp
w_SCREEN_USE assets/sprites/pistol_screen_use.bmp
w_USE assets/sounds/pistol_fire.wav
w_GET assets/sounds/pickup.wav
w_CANT_USE assets/sounds/empty_click.wav
NAME
string
Display name of the item
DESCRIPTION
string
Item description text
USE_DELAY
double
Delay between uses in seconds
SINGLE_USE
string
"TRUE" for consumable items, "FALSE" for reusable
ICON
string
Path to inventory icon sprite
SCREEN
string
Path to first-person screen sprite
ICON_USE
string
Path to icon sprite during use
SCREEN_USE
string
Path to screen sprite during use
USE
string
Path to use sound effect
GET
string
Path to pickup sound effect
CANT_USE
string
Path to sound when item cannot be used

Weapon Configuration

w_DAMAGE 25
w_RANGE 10.0
w_AMMO_USAGE 1
DAMAGE
int
Damage dealt per shot
RANGE
double
Maximum effective range
AMMO_USAGE
int
Ammunition consumed per use

Collectible Configuration

h_HEALTH 50
h_AMMO 0
h_SCORE 10
HEALTH
int
Health points restored (absolute value used)
AMMO
int
Ammunition added (absolute value used)
SCORE
int
Score points added (absolute value used)

Helper Functions

void free_item(void *data);
void item_use(t_item *item, t_drop *drop);
void item_drop(t_game *game, t_ftm_window *window, t_item *item, t_character *dropper);
void item_frame(t_item *item);

void weapon_use(t_item *item, t_drop *drop);
void weapon_drop(t_game *game, t_ftm_window *window, t_item *item, t_character *dropper);
void weapon_frame(t_item *item);

void collectible_use(t_item *item, t_drop *drop);
void collectible_drop(t_game *game, t_ftm_window *window, t_item *item, t_character *dropper);
void collectible_frame(t_item *item);

Example

// Create a weapon
t_weapon *pistol = weapon_new(game, window, 'w');
pistol->damage = 25;
pistol->range = 10.0;
pistol->ammo_usage = 1;
pistol->item.use_delay = 500; // 0.5 seconds

// Create a health pack
t_collectible *medkit = collectible_new(game, window, 'h');
medkit->health = 50;
medkit->item.single_use = true;

// Add to character inventory
character->inventory[0] = (t_item *)pistol;
character->inventory[1] = (t_item *)medkit;

// Use item
if (character->inventory[character->inventory_index])
{
    t_item *item = character->inventory[character->inventory_index];
    if (item->use)
        item->use(item, NULL);
}

// Drop item
if (item->drop)
    item->drop(game, window, item, character);

See Also

Build docs developers (and LLMs) love