Defining creatures and items

Since we are using TLevel.Load, the system to load creatures and items (together called 3D resources) is actually ready to use. A nice default handling of creatures and items suitable for 3D games is ready, in CastleCreatures and CastleItems units.

Creatures and items are defined by files named resource.xml in the game data. Their contents looks like this:

<?xml version="1.0"?>
    <idle   animation_name="idle"   />
    <walk   animation_name="walk"   />
    <attack animation_name="attack" />
    <die    animation_name="die"    />
    <hurt   animation_name="hurt"   />

The url properties refer to actual 3D models defining creature animations. See examples/fps_game/ data for a real example how such file looks like. And see creating resources for a complete documentation of resource.xml files, and how to create and export creature/item animations.

The most important properties about creatures and items specified in resource.xml files are:

  • name: this is a unique internal name of the resource (creature or item). It can be used as a placeholder name to place initial creatures/items on the level using 3D modeller (like Blender).
  • type: refers to ObjectPascal class handling the actual behavior of this resource. Engine already defines various basic creatures/items behavior, you can also extend our classes to create your own types.

To make the engine aware of such resources just add


call (from unit CastleResources) to your program. This will cause all information about the creatures and items automatically loaded.

You usually want to call Resources.LoadFromFiles before loading the level, this way loading the level will be able to automatically add initial creatures/items from placeholders. It is best to list necessary creatures in level.xml file in <prepare_resources> element, to have them prepared (list there both the initial creatures and the creatures you will spawn by code during the game). See creating levels for documentation of level.xml files.

The "type" of the creatures determines it's ObjectPascal class, in turn determining creature AI, and how many 3D models (or states) it has, and various other properties. Hostile creatures are automatically hostile to our Player.

Items are automatically pickable by player, player backpack is automatically managed.