Crystal Entity Layer: 4.2.1 WalkTut Tutorial

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 4.2.1 WalkTut Tutorial

This is a tutorial to show how you can use Crystal Entity Layer in your own applications. The original game data and the Blender level and model source used to create the artwork of this tutorial can be downloaded from:

http://www.crystalspace3d.org/celtutorial.zip

The source files of this tutorial can be found in the ``apps/tutorial/walktut'` directory that is included with CEL. The world and entity file can be found in the ``data'` directory (``walktut_world'` and ``walktut_entities'`).

Remember that the first time you run this application you have to add the ``-relight'` commandline option so that the lightmaps are correctly updated.

During the game you can use the following inputs:

- ``arrow keys'`: movement.
- ``m'`: camera mode (first person, third person, ...).
- ``left mouse button'`: pick up an item and put in inventory.
- ``d'`: drop the last item picked up.

This tutorial features:

- Camera handling using the ``pcdefaultcamera'` property class.
- Movement of an actor in a game using the ``pclinearmovement'` property class.
- Visualization of the player using the ``pcmesh'` property class.
- Handling of the player inventory using the ``pcinventory'` property class.
- Handling of keyboard and mouse input using the ``pccommandinput'` property class.
- Loading world and entity file using the ``pczonemanager'` property class.
- Usage of the ``celentity'` addon to add entities from an XML map file.
- How to create behaviours in C++ for game logic.

Here is the tutorial:

#### The XML Entity File

Except for the level and player entities all other entities are defined in the ``entities'` file. Here is an example of how such an entity looks:

        <addon plugin="celentity" entityname="badone">

          <propclass name="pcmesh">
            <action name="LoadMeshPath">
    	  <par name="path" string="/this/model" />
    	  <par name="filename" string="monkey" />
    	  <par name="factoryname" string="monkey" />
    	</action>
          </propclass>

          <propclass name="pcmeshselect" />

          <propclass name="pcproperties">
            <property name="pos1" vector="9,2,8" />
            <property name="pos2" vector="6,2,8" />
            <property name="pos3" vector="6,2,12" />
            <property name="pos4" vector="7,5,10" />
            <property name="pos5" vector="8,1,7" />
            <property name="pos6" vector="9,2,8" />
            <property name="up1" vector="0,1,0" />
            <property name="up2" vector="0,1,0" />
            <property name="up3" vector="0,1,0" />
            <property name="up4" vector="0,1,0" />
            <property name="up5" vector="0,1,0" />
            <property name="up6" vector="0,1,0" />
            <property name="forward1" vector="-1,0,0" />
            <property name="forward2" vector="0,0,1" />
            <property name="forward3" vector="1,1,-1" />
            <property name="forward4" vector="1,-1,-1" />
            <property name="forward5" vector="1,1,1" />
            <property name="forward6" vector="-1,0,0" />
            <property name="time1" long="1000" />
            <property name="time2" long="1000" />
            <property name="time3" long="1000" />
            <property name="time4" long="1000" />
            <property name="time5" long="1000" />
            <property name="time6" long="1000" />
          </propclass>

          <propclass name="pctimer">
            <action name="WakeUp">
    	  <par name="time" long="5000" />
    	  <par name="repeat" bool="true" />
    	</action>
          </propclass>

          <propclass name="pclinearmovement">
            <action name="InitCD">
    	  <par name="body" vector=".2,.2,.2" />
    	  <par name="legs" vector=".2,.2,.2" />
    	  <par name="offset" vector="0,-.3,0" />
    	</action>
            <action name="SetPosition">
    	  <par name="position" vector="9,3,8" />
    	  <par name="sector" string="Scene" />
    	  <par name="yrot" float="0" />
    	</action>
          </propclass>

          <behaviour name="badone_behave" />

        </addon>

In this particular example we use the ``cel.addons.celentity'` addon (see section CelEntity Addon) to create an entity with the name ``badone'`. It has the following property classes:

- ``pcmesh'` (see section Mesh). This mesh is setup with the ``monkey'` model that was made in ``Blender'`.
- ``pcmeshselect'` Used for selection of mesh.
- ``pcproperties'` This is a generic property class for storing named properties. In this particular case the ``badone_behave'` behaviour will read out the properties to construct the path for the catmull rom spline.
- ``pctimer'` (see section Timer). This timer will be used to restart the movement along the path after 5 seconds (5000 milliseconds).
- ``pclinearmovement'` (see section Linear Movement). This is the generic movement system.

We also create the entity with the ``badone_behave'` behaviour.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ]

This document was generated using texi2html 1.76.