File Formats

This outline provides information about the file formats used in the OGLR project, specifically for level files.

Level Files

Level files are stored in a simple text-based format, with each line representing a different object or element in the game world.

File Structure:

Each line in a level file consists of a comma-separated list of values. The first value represents the object type, followed by a series of parameters specific to that object.

Example:

// Example level file with comments
          # This is a comment
          Box, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, red, 0.5
          Sphere, 2.0, 0.0, 0.0, 0.5, blue, 0.8
          Light, 1.0, 1.0, 1.0, white, 1.0
          

Object Types:

The following table lists the available object types, their parameters, and their purpose.

Object Type Parameters Description
Box x, y, z, width, height, depth, color, transparency Creates a rectangular box
Sphere x, y, z, radius, color, transparency Creates a sphere
Light x, y, z, color, intensity Creates a light source

Parameters:

  • x, y, z: Position coordinates in 3D space.
  • width, height, depth: Dimensions of the box.
  • radius: Radius of the sphere.
  • color: Color of the object, specified as a string (e.g., “red”, “blue”, “white”).
  • transparency: Transparency value between 0.0 (fully opaque) and 1.0 (fully transparent).
  • intensity: Intensity of the light source.

Loading Level Files:

Level files are loaded using the load_level() function, which takes the filename as an argument.

// Example of loading a level file
          level_data = load_level("level.txt"); 
          

Creating Objects from Level Files:

The loaded level data is then used to create game objects. The create_object() function is used to instantiate objects based on the object type and parameters defined in the level file.

// Example of creating a box from level data
          create_object(level_data["box"], "Box", 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, "red", 0.5);
          

Further Information: