Mercurial > fife-parpg
comparison demos/rpg/scripts/scene.py @ 518:e4cd18a179af
Added the PlayerActionListener.
Added the ability to load NPCs from the settings file (this may be temporary). The idea of putting the NPCs in the settings file is to allow for custom attributes to be added without modification to the editor.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Wed, 26 May 2010 21:29:46 +0000 |
parents | d70fc46c8aa5 |
children | 14f777be6b94 |
comparison
equal
deleted
inserted
replaced
517:c3a026cdd91b | 518:e4cd18a179af |
---|---|
27 import sys, os, re, math, random, shutil | 27 import sys, os, re, math, random, shutil |
28 | 28 |
29 from fife import fife | 29 from fife import fife |
30 from fife.extensions.loaders import loadMapFile | 30 from fife.extensions.loaders import loadMapFile |
31 | 31 |
32 from scripts.actors.baseactor import Actor | |
32 from scripts.actors.player import Player | 33 from scripts.actors.player import Player |
33 | 34 |
34 class Scene(object): | 35 class Scene(object): |
35 def __init__(self, gamecontroller): | 36 def __init__(self, gamecontroller): |
36 self._gamecontroller = gamecontroller | 37 self._gamecontroller = gamecontroller |
40 self._cameras = {} | 41 self._cameras = {} |
41 | 42 |
42 self._actorlayer = None | 43 self._actorlayer = None |
43 | 44 |
44 self._player = None | 45 self._player = None |
46 self._npclist = [] | |
45 | 47 |
46 def createScene(self, mapfilename): | 48 def createScene(self, mapfilename): |
47 if not self._map: | 49 if not self._map: |
48 self._map = loadMapFile(mapfilename, self._gamecontroller.engine) | 50 self._map = loadMapFile(mapfilename, self._gamecontroller.engine) |
49 else: | 51 else: |
56 | 58 |
57 self._actorlayer = self._map.getLayer(self._gamecontroller.settings.get("RPG", "ActorLayer", "actor_layer")) | 59 self._actorlayer = self._map.getLayer(self._gamecontroller.settings.get("RPG", "ActorLayer", "actor_layer")) |
58 | 60 |
59 self._player = Player(self._gamecontroller, "warrior") | 61 self._player = Player(self._gamecontroller, "warrior") |
60 | 62 |
63 mapname = os.path.splitext(os.path.basename(mapfilename)) | |
64 for npc in self._gamecontroller.settings.get(mapname[0], "npclist", []): | |
65 (modelname, posx, posy) = self._gamecontroller.settings.get(mapname[0], npc, ["warrior", "0", "0"]) | |
66 actor = Actor(self._gamecontroller, modelname, npc, True) | |
67 actor.setMapPosition(float(posx), float(posy)) | |
68 self._npclist.append(actor) | |
69 | |
70 | |
61 def destroyScene(self): | 71 def destroyScene(self): |
62 self._cameras.clear() | 72 self._cameras.clear() |
63 | 73 |
74 self._player.destroy() | |
75 | |
76 for npc in self._npclist: | |
77 npc.destroy() | |
78 | |
64 if self._map: | 79 if self._map: |
65 self._gamecontroller.engine.getModel().deleteMap(self._map) | 80 self._gamecontroller.engine.getModel().deleteMap(self._map) |
66 | 81 |
67 self._map = None | 82 self._map = None |
68 self._actorlayer = None | 83 self._actorlayer = None |
84 | |
85 self._player = None | |
86 self._npclist = [] | |
69 | 87 |
70 def getInstancesAt(self, clickpoint): | 88 def getInstancesAt(self, clickpoint): |
71 """ | 89 """ |
72 Query the main camera for instances on our actor layer. | 90 Query the main camera for instances on our actor layer. |
73 """ | 91 """ |