| 1 |
/* |
| 2 |
$Id$ |
| 3 |
|
| 4 |
Copyright (C) 2001 Alexandre Courbot |
| 5 |
Part of the Adonthell Project http://adonthell.linuxgames.com |
| 6 |
|
| 7 |
This program is free software; you can redistribute it and/or modify |
| 8 |
it under the terms of the GNU General Public License. |
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY. |
| 11 |
|
| 12 |
See the COPYING file for more details. |
| 13 |
*/ |
| 14 |
|
| 15 |
/*! |
| 16 |
|
| 17 |
\page page7 Python Scripting |
| 18 |
|
| 19 |
Adonthell makes use of Python (http://www.python.org) as a scripting |
| 20 |
language. Small modules of Python code are used to controll %game |
| 21 |
elements like mapcharacters, mapviews and events or to perform special |
| 22 |
tasks like animated cutscenes, etc.. |
| 23 |
|
| 24 |
\section whypython Why use a scripting language? |
| 25 |
There is an important difference between %game engine and %game %data. |
| 26 |
Adonthell's goal is the ability to run different %games without any |
| 27 |
modification to the actual %game engine. This requires that %games |
| 28 |
using the Adonthell engine can be created without writing a single |
| 29 |
line of C++ code. |
| 30 |
|
| 31 |
Most %game %data (maps, characters, etc...) can be easily created with |
| 32 |
the help of the respective editor. But some elements need to be controlled |
| 33 |
by a program. For example, Non-Player Characters (NPC's) or mapviews. Rather |
| 34 |
than having a limited set of behaviors in the engine, it's better to directly |
| 35 |
program them using a easy to use, platform independant, interpreted language. |
| 36 |
And that is where Python comes in. Using Python, you can easily create your |
| 37 |
own behavior scripts (also called \e schedules) for the characters, as |
| 38 |
well as other parts of the %game (cutscenes, etc...). Actually, the entire |
| 39 |
C++ API is available from Python - so when you create Python scripts |
| 40 |
you have exactly the same possibilities you would have when writting them |
| 41 |
in C++. |
| 42 |
|
| 43 |
\section usingpython Using Python with Adonthell |
| 44 |
The complete Adonthell API is available through the \e adonthell |
| 45 |
module, which is imported at startup. There is a little customized |
| 46 |
Python interpreter in \e src/tools/pydonthell/ you can use for testing |
| 47 |
purposes: go into a valid %game directory, run \e pydonthell from |
| 48 |
here and try this little example program: |
| 49 |
|
| 50 |
\verbatim |
| 51 |
>>> from adonthell import * |
| 52 |
>>> im = image () |
| 53 |
>>> im.resize (100, 100) |
| 54 |
>>> im.fillrect_rgb (0, 0, im.length (), im.height (), 255, 0, 0) |
| 55 |
>>> im.draw (10, 10) |
| 56 |
>>> screen_show () |
| 57 |
\endverbatim |
| 58 |
|
| 59 |
All the classes and methods used in this little script are explained |
| 60 |
in the API reference. |
| 61 |
|
| 62 |
|
| 63 |
\section Running Python scripts |
| 64 |
The py_object class is designed to handle most of the Python scripting. |
| 65 |
It imports a Python module which should only contain Python classes. |
| 66 |
An instance of the selected class is created and you can freely call |
| 67 |
it's methods. See the \link py_object py_object class reference \endlink |
| 68 |
for more details concerning it's use. |
| 69 |
|
| 70 |
*/ |