annotate demos/rpg/scripts/scene.py @ 529:d0bce896a526

Changed the quest format in the object xml file. Quests can now required gold or items to complete.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Fri, 28 May 2010 16:25:00 +0000
parents 796d49ab9380
children ea26e7b6f56c
rev   line source
512
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
1 #!/usr/bin/env python
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
2
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
3 # -*- coding: utf-8 -*-
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
4
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
5 # ####################################################################
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
6 # Copyright (C) 2005-2010 by the FIFE team
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
7 # http://www.fifengine.net
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
8 # This file is part of FIFE.
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
9 #
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
10 # FIFE is free software; you can redistribute it and/or
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
11 # modify it under the terms of the GNU Lesser General Public
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
12 # License as published by the Free Software Foundation; either
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
13 # version 2.1 of the License, or (at your option) any later version.
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
14 #
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
15 # This library is distributed in the hope that it will be useful,
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
18 # Lesser General Public License for more details.
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
19 #
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
20 # You should have received a copy of the GNU Lesser General Public
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
21 # License along with this library; if not, write to the
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
22 # Free Software Foundation, Inc.,
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
23 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
24 # ####################################################################
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
25 # This is the rio de hola client for FIFE.
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
26
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
27 import sys, os, re, math, random, shutil
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
28
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
29 from fife import fife
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
30 from fife.extensions.loaders import loadMapFile
528
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
31 from fife.extensions.loaders import loadImportFile
520
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 519
diff changeset
32 from fife.extensions.fife_settings import Setting
512
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
33
518
e4cd18a179af Added the PlayerActionListener.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 516
diff changeset
34 from scripts.actors.baseactor import Actor
521
494c60cf61cf Player can now receive a quest, accept it, and complete it. Quests do not have any requirements (i.e. bring me back an item.. etc etc) to be completed at this time.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 520
diff changeset
35 from scripts.actors.baseactor import QuestGiver, Quest
513
edf5c0cf52f3 Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 512
diff changeset
36 from scripts.actors.player import Player
520
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 519
diff changeset
37 from scripts.objects.baseobject import GameObjectTypes
525
19db5a8619a4 Added the GoldStack item class. The scene now loads the goldstack and assigns it's value based on the maps objects file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
38 from scripts.objects.items import BaseItem, GoldStack
513
edf5c0cf52f3 Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 512
diff changeset
39
512
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
40 class Scene(object):
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
41 def __init__(self, gamecontroller):
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
42 self._gamecontroller = gamecontroller
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
43
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
44 self._map = None
516
d70fc46c8aa5 Added some placeholder graphics for the warrior. The player can now walk around the map.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
45 self._maincameraname = self._gamecontroller.settings.get("RPG", "DefaultCameraName", "camera1")
512
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
46 self._cameras = {}
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
47
513
edf5c0cf52f3 Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 512
diff changeset
48 self._actorlayer = None
edf5c0cf52f3 Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 512
diff changeset
49
edf5c0cf52f3 Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 512
diff changeset
50 self._player = None
520
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 519
diff changeset
51 self._objectlist = {}
524
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
52
528
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
53 def loadItems(self, mapfilename):
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
54 """
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
55 @todo: create a new function "loadItem(self, itemname)" which takes care of
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
56 loading an individual item in case at some point in the game you want to
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
57 load one at some point.
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
58 """
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
59 mapname = os.path.splitext(os.path.basename(mapfilename))
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
60 objectfile = "maps/" + mapname[0] + "_objects.xml"
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
61 modelfile = self._gamecontroller.settings.get("RPG", "AllObjectFile", "maps/allobjects.xml")
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
62
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
63 objectsettings = Setting(app_name="",settings_file=objectfile)
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
64 modelsettings = Setting(app_name="", settings_file=modelfile)
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
65
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
66 for item in objectsettings.get("items", "itemlist", []):
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
67 itemdict = objectsettings.get("items", item, {})
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
68 modeldict = modelsettings.get("models", itemdict["typename"], {})
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
69
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
70 loadImportFile(modeldict["file"], self._gamecontroller.engine)
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
71
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
72 if itemdict["typename"] == "GoldStack":
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
73 newitem = GoldStack(self._gamecontroller, modeldict["model"], item)
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
74 newitem.value = itemdict["value"]
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
75 else:
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
76 newitem = BaseItem(self._gamecontroller, modeldict["model"], item)
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
77
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
78 newitem.setMapPosition(float(itemdict["posx"]), float(itemdict["posy"]))
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
79 self._objectlist[newitem.instance.getId()] = newitem
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
80
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
81 def loadActors(self, mapfilename):
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
82 """
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
83 @todo: create a new function "loadActor(self, actorname)" which takes care of
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
84 loading an individual actor in case at some point in the game you want to
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
85 load one at some point.
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
86 """
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
87 mapname = os.path.splitext(os.path.basename(mapfilename))
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
88 objectfile = "maps/" + mapname[0] + "_objects.xml"
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
89 modelfile = self._gamecontroller.settings.get("RPG", "AllObjectFile", "maps/allobjects.xml")
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
90
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
91 objectsettings = Setting(app_name="",settings_file=objectfile)
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
92 modelsettings = Setting(app_name="", settings_file=modelfile)
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
93
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
94 for npc in objectsettings.get("npcs", "npclist", []):
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
95 objdict = objectsettings.get("npcs", npc, {})
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
96 modeldict = modelsettings.get("models", objdict["typename"], {})
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
97
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
98 loadImportFile(modeldict["file"], self._gamecontroller.engine)
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
99
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
100 if modeldict["type"] == "QUESTGIVER":
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
101 actor = QuestGiver(self._gamecontroller, modeldict["model"], npc, True)
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
102 questcount = modelsettings.get(npc, "questcount", 0)
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
103 for x in range(1,questcount+1):
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
104 quest = "quest" + str(x)
529
d0bce896a526 Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 528
diff changeset
105 questdict = modelsettings.get(npc, quest, {})
d0bce896a526 Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 528
diff changeset
106 quest = Quest(actor, questdict['name'], questdict['desc'])
d0bce896a526 Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 528
diff changeset
107
d0bce896a526 Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 528
diff changeset
108 for ritem in questdict['items'].split(" , "):
d0bce896a526 Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 528
diff changeset
109 if ritem == "GoldStack":
d0bce896a526 Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 528
diff changeset
110 quest.addRequiredGold(int(questdict['value']))
d0bce896a526 Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 528
diff changeset
111 else:
d0bce896a526 Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 528
diff changeset
112 quest.addRequiredItem(ritem)
d0bce896a526 Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 528
diff changeset
113
d0bce896a526 Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 528
diff changeset
114 actor.addQuest(quest)
528
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
115
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
116 elif modeldict["type"] == "NPC":
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
117 actor = Actor(self._gamecontroller, modeldict["model"], npc, True)
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
118
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
119 actor.setMapPosition(float(objdict["posx"]), float(objdict["posy"]))
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
120 self._objectlist[actor.instance.getId()] = actor
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
121
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
122 def loadPlayer(self):
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
123 """
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
124 @todo: once we have all art assets this should be able to load one of 3 player models
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
125 """
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
126 modelfile = self._gamecontroller.settings.get("RPG", "AllObjectFile", "maps/allobjects.xml")
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
127 modelsettings = Setting(app_name="", settings_file=modelfile)
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
128 modeldict = modelsettings.get("models", "Player", {})
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
129
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
130 loadImportFile(modeldict["file"], self._gamecontroller.engine)
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
131 self._player = Player(self._gamecontroller, "warrior")
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
132
512
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
133 def createScene(self, mapfilename):
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
134 if not self._map:
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
135 self._map = loadMapFile(mapfilename, self._gamecontroller.engine)
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
136 else:
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
137 self.destroyScene()
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
138
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
139 for cam in self._map.getCameras():
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
140 self._cameras[cam.getId()] = cam
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
141
516
d70fc46c8aa5 Added some placeholder graphics for the warrior. The player can now walk around the map.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
142 self._cameras[self._maincameraname].setZoom(self._gamecontroller.settings.get("RPG", "DefaultZoom", 2.0))
512
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
143
513
edf5c0cf52f3 Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 512
diff changeset
144 self._actorlayer = self._map.getLayer(self._gamecontroller.settings.get("RPG", "ActorLayer", "actor_layer"))
524
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
145 self._itemlayer = self._map.getLayer(self._gamecontroller.settings.get("RPG", "ItemLayer", "item_layer"))
513
edf5c0cf52f3 Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 512
diff changeset
146
528
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
147 self.loadItems(mapfilename)
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
148 self.loadActors(mapfilename)
520
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 519
diff changeset
149
528
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
150 #finally load the player
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
151 self.loadPlayer()
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
152
518
e4cd18a179af Added the PlayerActionListener.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 516
diff changeset
153
512
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
154 def destroyScene(self):
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
155 self._cameras.clear()
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
156
518
e4cd18a179af Added the PlayerActionListener.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 516
diff changeset
157 self._player.destroy()
e4cd18a179af Added the PlayerActionListener.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 516
diff changeset
158
520
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 519
diff changeset
159 for obj in self._objectlist.values():
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 519
diff changeset
160 obj.destroy()
518
e4cd18a179af Added the PlayerActionListener.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 516
diff changeset
161
512
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
162 if self._map:
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
163 self._gamecontroller.engine.getModel().deleteMap(self._map)
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
164
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
165 self._map = None
513
edf5c0cf52f3 Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 512
diff changeset
166 self._actorlayer = None
516
d70fc46c8aa5 Added some placeholder graphics for the warrior. The player can now walk around the map.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
167
518
e4cd18a179af Added the PlayerActionListener.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 516
diff changeset
168 self._player = None
520
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 519
diff changeset
169 self._objectlist.clear()
518
e4cd18a179af Added the PlayerActionListener.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 516
diff changeset
170
528
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
171 def getInstancesAt(self, clickpoint, layer):
516
d70fc46c8aa5 Added some placeholder graphics for the warrior. The player can now walk around the map.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
172 """
528
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
173 Query the main camera for instances on the specified layer.
516
d70fc46c8aa5 Added some placeholder graphics for the warrior. The player can now walk around the map.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
174 """
528
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 525
diff changeset
175 return self.cameras[self._maincameraname].getMatchingInstances(clickpoint, layer)
516
d70fc46c8aa5 Added some placeholder graphics for the warrior. The player can now walk around the map.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
176
d70fc46c8aa5 Added some placeholder graphics for the warrior. The player can now walk around the map.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
177 def getLocationAt(self, clickpoint):
d70fc46c8aa5 Added some placeholder graphics for the warrior. The player can now walk around the map.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
178 """
519
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 518
diff changeset
179 Query the main camera for the Map location (on the actor layer)
516
d70fc46c8aa5 Added some placeholder graphics for the warrior. The player can now walk around the map.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
180 that a screen point refers to.
d70fc46c8aa5 Added some placeholder graphics for the warrior. The player can now walk around the map.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
181 """
d70fc46c8aa5 Added some placeholder graphics for the warrior. The player can now walk around the map.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
182 target_mapcoord = self._cameras[self._maincameraname].toMapCoordinates(clickpoint, False)
d70fc46c8aa5 Added some placeholder graphics for the warrior. The player can now walk around the map.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
183 target_mapcoord.z = 0
d70fc46c8aa5 Added some placeholder graphics for the warrior. The player can now walk around the map.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
184 location = fife.Location(self._actorlayer)
d70fc46c8aa5 Added some placeholder graphics for the warrior. The player can now walk around the map.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
185 location.setMapCoordinates(target_mapcoord)
d70fc46c8aa5 Added some placeholder graphics for the warrior. The player can now walk around the map.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
186 return location
529
d0bce896a526 Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 528
diff changeset
187
d0bce896a526 Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 528
diff changeset
188 def addObjectToScene(self, obj):
d0bce896a526 Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 528
diff changeset
189 self._objectlist[obj.id] = obj
d0bce896a526 Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 528
diff changeset
190
d0bce896a526 Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 528
diff changeset
191 def removeObjectFromScene(self, obj):
d0bce896a526 Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 528
diff changeset
192 obj.destroy()
d0bce896a526 Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 528
diff changeset
193 del self._objectlist[obj.id]
d0bce896a526 Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 528
diff changeset
194
512
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
195 def updateScene(self):
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
196 pass
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
197
513
edf5c0cf52f3 Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 512
diff changeset
198 def _getActorLayer(self):
edf5c0cf52f3 Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 512
diff changeset
199 return self._actorlayer
524
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
200
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
201 def _getItemLayer(self):
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
202 return self._itemlayer
516
d70fc46c8aa5 Added some placeholder graphics for the warrior. The player can now walk around the map.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
203
d70fc46c8aa5 Added some placeholder graphics for the warrior. The player can now walk around the map.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
204 def _getCameras(self):
d70fc46c8aa5 Added some placeholder graphics for the warrior. The player can now walk around the map.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
205 return self._cameras
d70fc46c8aa5 Added some placeholder graphics for the warrior. The player can now walk around the map.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
206
d70fc46c8aa5 Added some placeholder graphics for the warrior. The player can now walk around the map.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
207 def _getPlayer(self):
d70fc46c8aa5 Added some placeholder graphics for the warrior. The player can now walk around the map.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
208 return self._player
d70fc46c8aa5 Added some placeholder graphics for the warrior. The player can now walk around the map.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
209
520
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 519
diff changeset
210 def _getObjectList(self):
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 519
diff changeset
211 return self._objectlist
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 519
diff changeset
212
523
d01eb65b2726 Enabling the FloatingTextRenderer for the RPG demo. The NPC now complains at you if he doesn't have a quest to give you.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 521
diff changeset
213 def _getMap(self):
d01eb65b2726 Enabling the FloatingTextRenderer for the RPG demo. The NPC now complains at you if he doesn't have a quest to give you.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 521
diff changeset
214 return self._map
d01eb65b2726 Enabling the FloatingTextRenderer for the RPG demo. The NPC now complains at you if he doesn't have a quest to give you.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 521
diff changeset
215
513
edf5c0cf52f3 Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 512
diff changeset
216 actorlayer = property(_getActorLayer)
524
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
217 itemlayer = property(_getItemLayer)
516
d70fc46c8aa5 Added some placeholder graphics for the warrior. The player can now walk around the map.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
218 cameras = property(_getCameras)
d70fc46c8aa5 Added some placeholder graphics for the warrior. The player can now walk around the map.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 513
diff changeset
219 player = property(_getPlayer)
520
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 519
diff changeset
220 objectlist = property(_getObjectList)
523
d01eb65b2726 Enabling the FloatingTextRenderer for the RPG demo. The NPC now complains at you if he doesn't have a quest to give you.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 521
diff changeset
221 map = property(_getMap)
513
edf5c0cf52f3 Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 512
diff changeset
222