Overview
Entities are the fundamental game objects in Cub3D. Everything that exists in the game world - from walls and doors to players and enemies - is an entity. The entity system provides a flexible, type-based architecture for creating diverse game objects.Entity Types
headers/cub3d.h
Base Entity Structure
All entities inherit from the baset_entity structure:
headers/cub3d.h
The entity system uses function pointers for polymorphic behavior - each entity type can override
frame, action, shot, and clear methods.Entity Properties
Core Properties
- coords: Position (x, y) and facing angle (yaw) in the world
- size: Width and height of the entity hitbox
- identifier: Single character used in map files
- active: Whether the entity is currently in the game
- type: The specific entity type enum
Interaction Flags
- targetable: Can be targeted by players (for shooting/interaction)
- actionable: Can be interacted with (use key)
- hard: Blocks movement (collision detection)
Visual Properties
- transparent: Can be seen through (like windows)
- ultra_mega_transparent: Always transparent, rays pass through
- no_transparency_for_bill: Blocks billboards but not raycasts
Combat Properties
- health: Current health points
- max_health: Maximum health points
- invencible: Cannot take damage
Wall Entities
Walls are the basic solid entities that define level geometry.headers/cub3d.h
Wall Features
Wall Features
- Four directional textures (one for each cardinal direction)
- Block movement and raycasts by default
- Can be made transparent for windows
- Foundation for door and elevator types
Wall Configuration
headers/cub3d.h
Door Entities
Doors extend walls with opening/closing mechanics.headers/cub3d.h
Door Configuration
headers/cub3d.h
Doors animate at 6 FPS by default. Custom animation speeds can be set per-door via the
ANIMATION_DELAY property in map files.Door States
- opened: Current state (open/closed)
- closeable: Can be closed after opening
- cant_close: Stays open permanently once opened
- auto_close_delay: Time before automatic closing (if set)
Billboard Entities
Billboards are 2D sprites that always face the camera (sprite rendering).headers/cub3d.h
Billboard Configuration
headers/cub3d.h
8-Directional Sprites
Billboards support 8 directional sprites for viewing from different angles:Character Entities
Characters extend billboards with health, inventory, and AI capabilities.headers/cub3d.h
Character Configuration
headers/cub3d.h
Character Features
Character Capabilities
Character Capabilities
- Inventory system: 9 item slots
- Health and damage: 100 HP by default
- Animation states: Walking, using items, hit, death
- AI targeting: Can target and track other entities
- Item drops: Drop items on death
- Sound effects: Hit sounds and death screams
- Combat cooldowns: 100ms delay between hits
Player Entities
Players are characters with additional rendering and control properties.headers/cub3d.h
Player Configuration
headers/cub3d.h
Cub3D supports up to 4 simultaneous players with split-screen rendering.
Player Movement
- Walk speed: 4.0 units/second
- Sprint speed: 6.0 units/second
- Rotation speed: 180°/second (keyboard), 20°/second (mouse)
Drop Entities
Drops are pickupable items placed in the world.headers/cub3d.h
- auto_pickup: Automatically picked up when touched
- auto_use: Automatically used when picked up
- Contains an
t_itempointer for the actual item data
Elevator Entities
Elevators teleport players to different maps.headers/cub3d.h
map_path.
Entity Controller
The controller handles entity input and AI behavior.headers/cub3d.h
Controllers can be used for both player input and AI behavior. The same controller structure handles keyboard/mouse input for players and decision-making for NPCs.
Entity Management
Entities are stored and managed by the game:headers/cub3d.h
Entity Frame Updates
Every frame, all entities are updated:src/utils/loop/loop.c
- call_entity_frames: Calls the
frame()function for each entity - update_walls_matrix: Updates the 2D wall grid for raycasting
- update_billboards_vec: Updates the billboard array for rendering
Entity Creation
Entities are created via factory functions:headers/cub3d.h
- Allocates memory for the entity
- Initializes base entity properties
- Loads configuration from map identifiers
- Sets up sprites, sounds, and other assets
- Returns the configured entity
Entity Lifecycle
- Creation: Entity is created from map data
- Initialization: Properties loaded from identifier configuration
- Frame Updates:
frame()called every game tick - Interactions:
action()orshot()called when interacted with - Cleanup:
clear()frees resources, entity removed from game
Transparency System
Cub3D supports multiple levels of transparency:headers/cub3d.h
Transparency Behavior
Transparency Behavior
- transparent: Rays check texture alpha channel at hit point
- ultra_mega_transparent: Rays always pass through, useful for thin decorative walls
- no_transparency_for_bill: Walls that block billboards but not raycasts (optimization)
src/utils/render/camera/walls/render.c
Collision Detection
Entities withhard = true block movement. Collision is checked using entity size:
headers/cub3d.h
Related Topics
- Map Format - How to define entities in .cub files
- Raycasting - How entities are rendered
- Game Engine - Entity update loop