Adonthell 0.4
|
00001 /* 00002 $Id: python.dxt,v 1.1 2001/10/15 15:00:06 gnurou Exp $ 00003 00004 Copyright (C) 2001 Alexandre Courbot 00005 Part of the Adonthell Project http://adonthell.linuxgames.com 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License. 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY. 00011 00012 See the COPYING file for more details. 00013 */ 00014 00015 /*! 00016 00017 \page page7 Python Scripting 00018 00019 Adonthell makes use of Python (http://www.python.org) as a scripting 00020 language. Small modules of Python code are used to controll %game 00021 elements like mapcharacters, mapviews and events or to perform special 00022 tasks like animated cutscenes, etc.. 00023 00024 \section whypython Why use a scripting language? 00025 There is an important difference between %game engine and %game %data. 00026 Adonthell's goal is the ability to run different %games without any 00027 modification to the actual %game engine. This requires that %games 00028 using the Adonthell engine can be created without writing a single 00029 line of C++ code. 00030 00031 Most %game %data (maps, characters, etc...) can be easily created with 00032 the help of the respective editor. But some elements need to be controlled 00033 by a program. For example, Non-Player Characters (NPC's) or mapviews. Rather 00034 than having a limited set of behaviors in the engine, it's better to directly 00035 program them using a easy to use, platform independant, interpreted language. 00036 And that is where Python comes in. Using Python, you can easily create your 00037 own behavior scripts (also called \e schedules) for the characters, as 00038 well as other parts of the %game (cutscenes, etc...). Actually, the entire 00039 C++ API is available from Python - so when you create Python scripts 00040 you have exactly the same possibilities you would have when writting them 00041 in C++. 00042 00043 \section usingpython Using Python with Adonthell 00044 The complete Adonthell API is available through the \e adonthell 00045 module, which is imported at startup. There is a little customized 00046 Python interpreter in \e src/tools/pydonthell/ you can use for testing 00047 purposes: go into a valid %game directory, run \e pydonthell from 00048 here and try this little example program: 00049 00050 \verbatim 00051 >>> from adonthell import * 00052 >>> im = image () 00053 >>> im.resize (100, 100) 00054 >>> im.fillrect_rgb (0, 0, im.length (), im.height (), 255, 0, 0) 00055 >>> im.draw (10, 10) 00056 >>> screen_show () 00057 \endverbatim 00058 00059 All the classes and methods used in this little script are explained 00060 in the API reference. 00061 00062 00063 \section Running Python scripts 00064 The py_object class is designed to handle most of the Python scripting. 00065 It imports a Python module which should only contain Python classes. 00066 An instance of the selected class is created and you can freely call 00067 it's methods. See the \link py_object py_object class reference \endlink 00068 for more details concerning it's use. 00069 00070 */