File: python.dxt

package info (click to toggle)
adonthell 0.3.8-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,416 kB
  • sloc: cpp: 50,659; sh: 5,142; python: 3,307; makefile: 338; lex: 216; sed: 16
file content (70 lines) | stat: -rw-r--r-- 2,777 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
   $Id$

   Copyright (C) 2001   Alexandre Courbot
   Part of the Adonthell Project http://adonthell.linuxgames.com

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License.
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY.

   See the COPYING file for more details.
*/

/*!

\page page7 Python Scripting

Adonthell makes use of Python (http://www.python.org) as a scripting
language. Small modules of Python code are used to controll %game
elements like mapcharacters, mapviews and events or to perform special
tasks like animated cutscenes, etc..

\section whypython Why use a scripting language?
There is an important difference between %game engine and %game %data.
Adonthell's goal is the ability to run different %games without any
modification to the actual %game engine. This requires that %games
using the Adonthell engine can be created without writing a single
line of C++ code.

Most %game %data (maps, characters, etc...) can be easily created with
the help of the respective editor. But some elements need to be controlled
by a program. For example, Non-Player Characters (NPC's) or mapviews. Rather
than having a limited set of behaviors in the engine, it's better to directly
program them using a easy to use, platform independant, interpreted language.
And that is where Python comes in. Using Python, you can easily create your
own behavior scripts (also called \e schedules) for the characters, as
well as other parts of the %game (cutscenes, etc...). Actually, the entire
C++ API is available from Python - so when you create Python scripts
you have exactly the same possibilities you would have when writting them
in C++.

\section usingpython Using Python with Adonthell
The complete Adonthell API is available through the \e adonthell
module, which is imported at startup. There is a little customized
Python interpreter in \e src/tools/pydonthell/ you can use for testing
purposes: go into a valid %game directory, run \e pydonthell from
here and try this little example program:

\verbatim
>>> from adonthell import *
>>> im = image ()
>>> im.resize (100, 100)
>>> im.fillrect_rgb (0, 0, im.length (), im.height (), 255, 0, 0)
>>> im.draw (10, 10)
>>> screen_show ()
\endverbatim

All the classes and methods used in this little script are explained
in the API reference.


\section Running Python scripts
The py_object class is designed to handle most of the Python scripting.
It imports a Python module which should only contain Python classes.
An instance of the selected class is created and you can freely call
it's methods. See the \link py_object py_object class reference \endlink
for more details concerning it's use.

*/