Mercurial > fife-parpg
comparison demos/rpg/scripts/actors/baseactor.py @ 513:edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
Added a help file for the console.
Added a KeyState class for keeping track of the state of the keys.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Fri, 21 May 2010 20:33:43 +0000 |
parents | |
children | d70fc46c8aa5 |
comparison
equal
deleted
inserted
replaced
512:6ddb1eb9dfa6 | 513:edf5c0cf52f3 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 # -*- coding: utf-8 -*- | |
4 | |
5 # #################################################################### | |
6 # Copyright (C) 2005-2010 by the FIFE team | |
7 # http://www.fifengine.net | |
8 # This file is part of FIFE. | |
9 # | |
10 # FIFE is free software; you can redistribute it and/or | |
11 # modify it under the terms of the GNU Lesser General Public | |
12 # License as published by the Free Software Foundation; either | |
13 # version 2.1 of the License, or (at your option) any later version. | |
14 # | |
15 # This library is distributed in the hope that it will be useful, | |
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 # Lesser General Public License for more details. | |
19 # | |
20 # You should have received a copy of the GNU Lesser General Public | |
21 # License along with this library; if not, write to the | |
22 # Free Software Foundation, Inc., | |
23 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
24 # #################################################################### | |
25 # This is the rio de hola client for FIFE. | |
26 | |
27 import sys, os, re, math, random, shutil | |
28 | |
29 from fife import fife | |
30 from fife.extensions.loaders import loadMapFile | |
31 | |
32 class Actor(object): | |
33 def __init__(self, gamecontroller, instancename, instanceid=None, createInstance=False): | |
34 """ | |
35 @param gamecontroller: A reference to the master game controller | |
36 @param instancename: The name of the object to load. The object's XML file must | |
37 be part of the map file or added with fife.extensions.loaders.loadImportFile | |
38 @param instanceid: used if you want to give a specific ID to the instance to | |
39 differenciate it from other instances | |
40 @param createInstance: If this is True it will attempt to be loaded from disk and not | |
41 use one that has already been loaded from the map file. See the note about the | |
42 instancename paramater above. | |
43 """ | |
44 self._gamecontroller = gamecontroller | |
45 self._fifeobject = None | |
46 self._name = instancename | |
47 if instanceid: | |
48 self._id = instanceid | |
49 else: | |
50 self._id = self._name | |
51 | |
52 self._instance = None | |
53 | |
54 if createInstance: | |
55 self._createFIFEInstance(self._name) | |
56 else: | |
57 self._instance = self._gamecontroller.scene.layer.getInstance(self._id) | |
58 self._instance.thisown = 0 | |
59 | |
60 def destroy(self): | |
61 """ | |
62 Deletes the FIFE instance from the actor layer on the map. | |
63 """ | |
64 if self._instance : | |
65 self._gamecontroller.scene.actorlayer.deleteInstance(self._instance) | |
66 self._instance = None | |
67 | |
68 def _createFIFEInstance(self): | |
69 """ | |
70 Should not be called directly. Use the constructor! | |
71 """ | |
72 mapmodel = self._gamecontroller.engine.getModel() | |
73 self._fifeobject = mapmodel.getObject(self._name, self._gamecontroller.settings.get("RPG", "ObjectNamespace", "http://www.fifengine.de/xml/rpg")) | |
74 | |
75 self._instance = self._gamecontroller.scene.actorlayer.createInstance(self._fifeobject, fife.ModelCoordinate(0,0), self._id) | |
76 fife.InstanceVisual.create(self._instance) | |
77 self._instance.thisown = 0 | |
78 | |
79 def _getLocation(self): | |
80 return self._instance.getLocation() | |
81 | |
82 def _setLocation(self, loc): | |
83 self._instance.setLocation(loc) | |
84 | |
85 location = property(_getLocation,_setLocation) |