Creating celstart games using python

From Blender2crystal

Jump to: navigation, search

Contents

[edit] Introduction

export tab with celexport property set (at the right)
export tab with celexport property set (at the right)

This tutorial is about starting a simple python scripting world, and exporting for celstart.

Celstart allows to run scripting maps that come packed in a special .celzip file. With blender2crystal its possible to create and assign all of the content to be placed inside, as well as running celstart directly from the run button.

To do this we will need to follow the following steps:

  • set celexport mode
  • add a player entity
  • add a behaviour to the player
  • run

[edit] Celexport mode

celexport toggle
celexport toggle

First of all its necessary to activate cel export mode at the export Image:Icons-export.png tab of blender2crystal.

Now for an xml game we would be setting the behaviourlayer property in the world settings tab (Image:Icons-world.png), but blpython is the default in b2cs so for this tutorial we dont need to touch that. Note even though this tutorial is for setting up python games the only real difference lies in this property. Also there arent many predefined behaviours for blxml at this point.

[edit] Application behaviour

There is one further thing to note about celexport python mode, it requires an application behaviour that starts the map and sets the camera to the player entity. This is defined in the world settings Image:Icons-world.png tab by the pythonapp property. Blender2crystal provides a predefined script that you can modify called celstrap, this is the default.

[edit] The player

Now b2cs requires one further thing to be able to export the map: the player entity. This is the entity celstart will look for when it runs your map. It can be any mesh in the map, so just add some object, and go to the cel Image:Icons-cel.png tab, there set the player property to true. This makes the object also a cel entity, and so some new options will appear in the interface.

Now we can export the map from the export Image:Icons-export.png tab by hitting on the run button. As we havent assigned any behaviour to the player, though, there is not much we can see or do.

[edit] Adding a behaviour

behaviour assigned to the player
behaviour assigned to the player

Each object can be assigned a python or xml script to control it, this is called the behaviour. In blender2crystal you can assign behaviours from the predefined ones, from inside the blender text tab, and from a user defined scripts dir.

For now we will assign the actor behaviour, by clicking over the behaviour property value a popup allows to select from the available ones.

By running the map we can see now its possible to move the object by using the arrow keys, also camera mode can be changed with the m key. This keybindings are defined in a special file that must lie next to the behaviour with .cfg file extension. This files will be put into the map by the exporter if found and celstrap will load them so each behaviour can use it. By modifying the cfg file you can change the keys that control the behaviour or remove some completely.

NOTE: If you notice the object rotating in a weird direction then you have to apply its rotation (ctrl a), as otherwise it means its placed rotated in the map initially, and local coordinates wont be set right resulting in the object rotating in a different axis than expected (like the camera rotating down when using the left key).

[edit] Adding more entities

entity property
entity property

All other blender objects can be made into entities that will control their behaviour.

To allow an object to hold behaviours or other interaction facilities from cel it is necessary to set the entity property to true. Then all the entity tabs appear and we can set behaviours, quests and different properties to them, thats not the scope of this tutorial though, check the Cel Overlay Interface and Cel Reference for more details about this.

As an example we can add some objects floating around and set one of the example behaviours to them.

Some of the simple example behaviours provided that can be used as base for greater things:

  • lookat: makes the object always look at the player (will rotate to always face it).
  • followpath: makes the object follow a random path in the air.
  • blink: makes the object appear and dissapear.
  • npc: the object will wander around as a character.
  • ...

[edit] Resulting file

World celzip file contents
World celzip file contents

You will find the generated zip file in your temporary folder (or elsewhere if you have set this in world settings).

As default it will be called world.zip. By inspecting it we can see it includes the following:

  • celstart.cfg: this is the celstart configuration file, holds all necessary options to run the application behaviour.
  • world: all cs related xml data is put here
  • entities_world: all cel related xml data is put here
  • level.xml: this is the file the celstart zonemanager actually loads, it has references to the xml previous files.
  • *.py: all behaviours are put here.
  • factories/: all cs factories are exported here as library files.
  • config/: all behaviour config files are put here.
  • textures/: all images will be put here.

most of this paths can be overriden in world properties.

[edit] Further editing of behaviours

To edit the scripts there are two options:

  • import them into blender and edit from its inline editor
  • export to a folder and edit from there.

The second is more practical as it allows editing the scripts with an external editor, so we will setup for that.

To do this create a folder called scripts alongside the .blend file, and set the scriptsdir property at the world settingsImage:Icons-world.png tab to //scripts. The double // before the folder name means the path that follows is under the same dir as the .blend file.

Now you can place scripts you are using here to modify them and blender2crystal will pack from this folder.

When there are scripts with the same name in different places blender2crystal will use the following order of preference to select the one to use:

1. From scriptsdir folder defined in world settings.

2. From blender text tab.

3. From blender2crystal predefined behaviours.

This way you can start hacking any script right away just by placing it inside the selected scripts directory.

Personal tools
Documentation