annotate demos/rpg/scripts/gamecontroller.py @ 560:69d50e751c9a

Lots of changes. - Added the Serializer class - Made exceptions a little more usable - Added actor attributes (not used yet but will be with the combat engine) - Made the quest dialogs more customizable - Many other small changes
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Wed, 23 Jun 2010 19:20:24 +0000
parents 718e154a43c8
children f85762e634c5
rev   line source
509
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
1 #!/usr/bin/env python
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
2
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
3 # -*- coding: utf-8 -*-
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
4
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
5 # ####################################################################
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
6 # Copyright (C) 2005-2010 by the FIFE team
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
7 # http://www.fifengine.net
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
8 # This file is part of FIFE.
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
9 #
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
10 # FIFE is free software; you can redistribute it and/or
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
11 # modify it under the terms of the GNU Lesser General Public
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
12 # License as published by the Free Software Foundation; either
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
13 # version 2.1 of the License, or (at your option) any later version.
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
14 #
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
15 # This library is distributed in the hope that it will be useful,
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
18 # Lesser General Public License for more details.
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
19 #
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
20 # You should have received a copy of the GNU Lesser General Public
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
21 # License along with this library; if not, write to the
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
22 # Free Software Foundation, Inc.,
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
23 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
24 # ####################################################################
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
25
547
e59ece21ab3e Item serialization will now assume some default values if they are not found in the save files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 546
diff changeset
26 import sys, os, re, math, random, shutil, glob, uuid
509
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
27
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
28 from fife import fife
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
29
517
c3a026cdd91b Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 516
diff changeset
30 from fife.extensions.soundmanager import SoundManager
c3a026cdd91b Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 516
diff changeset
31 from fife.extensions.loaders import loadImportFile
c3a026cdd91b Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 516
diff changeset
32
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: 510
diff changeset
33 from scripts.scene import Scene
510
cd959b05a262 There is now a main menu. You can also view the credits. Taking a screenshot and opening the console should also work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 509
diff changeset
34 from scripts.guicontroller import GUIController
540
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
35 from scripts.actors.baseactor import TalkAction, PickUpItemAction, EnterPortalAction
520
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 519
diff changeset
36 from scripts.objects.baseobject import GameObjectTypes
536
1afe46247ab1 Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 535
diff changeset
37 from scripts.misc.exceptions import ObjectNotFoundError, ObjectAlreadyInSceneError
550
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
38 from scripts.quests.questmanager import QuestManager
517
c3a026cdd91b Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 516
diff changeset
39
510
cd959b05a262 There is now a main menu. You can also view the credits. Taking a screenshot and opening the console should also work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 509
diff changeset
40
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
41 class KeyState(object):
550
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
42 """
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
43 Holds the current state of the keys on the keyboard (down or up).
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
44 False = down, True = up.
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
45 """
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
46 def __init__(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
47 self._keystate = { }
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
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 def updateKey(self, key, state):
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._keystate[key] = state
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
51
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
52 def checkKey(self, key):
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
53 if key in self._keystate:
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
54 return self._keystate[key]
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
55 else:
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
56 return False
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
57
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
58 def reset(self):
550
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
59 """
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
60 Empties the keystate dictionary (assumes all keys are False)
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
61 """
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
62 self._keystate.clear()
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
63
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: 510
diff changeset
64 class GameListener(fife.IKeyListener, fife.IMouseListener):
550
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
65 """
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
66 Main game listener. Listens for Mouse and Keyboard events.
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
67
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
68 This class also has the ability to attach and detach itself from
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
69 the event manager in cases where you do not want input processed (i.e. when
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
70 the main menu is visible). It is NOT attached by default.
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
71 """
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: 510
diff changeset
72 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: 510
diff changeset
73 self._engine = 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: 510
diff changeset
74 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: 510
diff changeset
75 self._settings = gamecontroller.settings
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
76 self._eventmanager = self._engine.getEventManager()
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
77
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
78 fife.IMouseListener.__init__(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: 510
diff changeset
79 fife.IKeyListener.__init__(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: 510
diff changeset
80
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
81 self._attached = False
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
82
524
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
83 self._lastmousepos = (0.0,0.0)
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
84
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: 510
diff changeset
85 def attach(self):
550
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
86 """
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
87 Attaches to the event manager.
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
88 """
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: 510
diff changeset
89 if not self._attached:
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
90 self._gamecontroller.keystate.reset()
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: 510
diff changeset
91 self._eventmanager.addMouseListenerFront(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: 510
diff changeset
92 self._eventmanager.addKeyListenerFront(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: 510
diff changeset
93 self._attached = True
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
94
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
95 def detach(self):
550
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
96 """
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
97 Detaches from the event manager.
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
98 """
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: 510
diff changeset
99 if self._attached:
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
100 self._eventmanager.removeMouseListener(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: 510
diff changeset
101 self._eventmanager.removeKeyListener(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: 510
diff changeset
102 self._attached = False
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
103
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
104 def mousePressed(self, event):
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
105 #mouse press was consumed by some pychan widget
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
106 if event.isConsumedByWidgets():
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
107 return
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
108
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
109 clickpoint = fife.ScreenPoint(event.getX(), event.getY())
524
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
110
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
111 if (event.getButton() == fife.MouseEvent.LEFT):
524
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
112 self._lastmousepos = (clickpoint.x, clickpoint.y)
552
718e154a43c8 When you click on an object behind the player the click is no longer ignored.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
113
718e154a43c8 When you click on an object behind the player the click is no longer ignored.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
114 #cancel last action
718e154a43c8 When you click on an object behind the player the click is no longer ignored.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
115 self._gamecontroller.scene.player.nextaction = None
718e154a43c8 When you click on an object behind the player the click is no longer ignored.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
116
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
117 self._gamecontroller.scene.player.walk( self._gamecontroller.scene.getLocationAt(clickpoint) )
552
718e154a43c8 When you click on an object behind the player the click is no longer ignored.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
118
528
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
119 actor_instances = self._gamecontroller.scene.getInstancesAt(clickpoint, self._gamecontroller.scene.actorlayer)
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
120 item_instances = self._gamecontroller.scene.getInstancesAt(clickpoint, self._gamecontroller.scene.itemlayer)
552
718e154a43c8 When you click on an object behind the player the click is no longer ignored.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
121
528
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
122 if actor_instances:
552
718e154a43c8 When you click on an object behind the player the click is no longer ignored.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
123 actor_instance = None
718e154a43c8 When you click on an object behind the player the click is no longer ignored.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
124 for actor in actor_instances:
718e154a43c8 When you click on an object behind the player the click is no longer ignored.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
125 if actor.getId() == "player":
718e154a43c8 When you click on an object behind the player the click is no longer ignored.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
126 continue
718e154a43c8 When you click on an object behind the player the click is no longer ignored.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
127 else:
718e154a43c8 When you click on an object behind the player the click is no longer ignored.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
128 actor_instance = actor
718e154a43c8 When you click on an object behind the player the click is no longer ignored.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
129 break
718e154a43c8 When you click on an object behind the player the click is no longer ignored.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
130
718e154a43c8 When you click on an object behind the player the click is no longer ignored.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
131 if actor_instance:
718e154a43c8 When you click on an object behind the player the click is no longer ignored.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
132 obj = self._gamecontroller.scene.objectlist[actor_instance.getId()]
718e154a43c8 When you click on an object behind the player the click is no longer ignored.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
133 if obj.type == GameObjectTypes["QUESTGIVER"]:
718e154a43c8 When you click on an object behind the player the click is no longer ignored.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
134 action = TalkAction(self._gamecontroller.scene.player, obj)
718e154a43c8 When you click on an object behind the player the click is no longer ignored.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
135 self._gamecontroller.scene.player.nextaction = action
528
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
136
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
137 if item_instances:
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
138 obj = self._gamecontroller.scene.objectlist[item_instances[0].getId()]
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
139 if obj.type == GameObjectTypes["ITEM"]:
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
140 action = PickUpItemAction(self._gamecontroller.scene.player, obj)
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
141 self._gamecontroller.scene.player.nextaction = action
540
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
142 elif obj.type == GameObjectTypes["PORTAL"]:
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
143 action = EnterPortalAction(self._gamecontroller.scene.player, obj)
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
144 self._gamecontroller.scene.player.nextaction = action
528
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
145
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
146 if (event.getButton() == fife.MouseEvent.RIGHT):
536
1afe46247ab1 Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 535
diff changeset
147 instances = self._gamecontroller.scene.getInstancesAt(clickpoint, self._gamecontroller.scene.actorlayer)
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
148 if instances:
536
1afe46247ab1 Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 535
diff changeset
149 self._gamecontroller.logger.log_debug("Selected instance on actor layer: " + instances[0].getId())
1afe46247ab1 Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 535
diff changeset
150
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
151
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: 510
diff changeset
152 def mouseReleased(self, event):
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
153 pass
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
154
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
155 def mouseMoved(self, event):
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
156 renderer = self._gamecontroller.instancerenderer
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
157 if renderer:
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
158 renderer.removeAllOutlines()
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
159 else:
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
160 return
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
161
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
162 pt = fife.ScreenPoint(event.getX(), event.getY())
528
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
163 actor_instances = self._gamecontroller.scene.getInstancesAt(pt, self._gamecontroller.scene.actorlayer)
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
164 item_instances = self._gamecontroller.scene.getInstancesAt(pt, self._gamecontroller.scene.itemlayer)
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
165 for i in actor_instances:
536
1afe46247ab1 Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 535
diff changeset
166 if i.getId() != "player":
1afe46247ab1 Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 535
diff changeset
167 renderer.addOutlined(i, 173, 255, 47, 2)
528
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
168
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
169 for j in item_instances:
536
1afe46247ab1 Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 535
diff changeset
170 renderer.addOutlined(j, 255, 173, 47, 2)
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
171
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: 510
diff changeset
172 def mouseEntered(self, event):
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
173 pass
517
c3a026cdd91b Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 516
diff changeset
174
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: 510
diff changeset
175 def mouseExited(self, event):
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
176 pass
517
c3a026cdd91b Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 516
diff changeset
177
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: 510
diff changeset
178 def mouseClicked(self, event):
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
179 pass
517
c3a026cdd91b Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 516
diff changeset
180
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: 510
diff changeset
181 def mouseWheelMovedUp(self, event):
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
182 pass
517
c3a026cdd91b Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 516
diff changeset
183
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: 510
diff changeset
184 def mouseWheelMovedDown(self, event):
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
185 pass
517
c3a026cdd91b Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 516
diff changeset
186
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: 510
diff changeset
187 def mouseDragged(self, event):
524
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
188 if event.isConsumedByWidgets():
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
189 return
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
190
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
191 clickpoint = fife.ScreenPoint(event.getX(), event.getY())
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
192 if (event.getButton() == fife.MouseEvent.LEFT):
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
193 if clickpoint.x > self._lastmousepos[0] + 5 or clickpoint.x < self._lastmousepos[0] - 5 or clickpoint.y > self._lastmousepos[1] + 5 or clickpoint.y < self._lastmousepos[1] - 5:
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
194 self._gamecontroller.scene.player.walk( self._gamecontroller.scene.getLocationAt(clickpoint) )
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
195
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
196 self._lastmousepos = (clickpoint.x, clickpoint.y)
517
c3a026cdd91b Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 516
diff changeset
197
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: 510
diff changeset
198 def keyPressed(self, event):
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
199 keyval = event.getKey().getValue()
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
200 keystr = event.getKey().getAsString().lower()
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
201 if keyval == fife.Key.ESCAPE:
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
202 self.detach()
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
203 self._gamecontroller.guicontroller.showMainMenu()
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
204 event.consume()
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
205
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
206 self._gamecontroller.keystate.updateKey(keyval, True)
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: 510
diff changeset
207
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
208 def keyReleased(self, event):
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
209 keyval = event.getKey().getValue()
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
210 keystr = event.getKey().getAsString().lower()
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
211
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
212 self._gamecontroller.keystate.updateKey(keyval, False)
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
213
509
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
214 class GameController(object):
550
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
215 """
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
216 The main game class.
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
217
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
218 This handles all game related code including setting up the scene, displaying user
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
219 interfaces, managing sound, etc etc.
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
220 """
509
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
221 def __init__(self, application, engine, settings):
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
222 self._application = application
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
223 self._engine = engine
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
224 self._settings = settings
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
225
540
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
226 self._soundmanager = SoundManager(self._engine)
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
227
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
228 self._keystate = KeyState()
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
229
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: 510
diff changeset
230 self._guicontroller = GUIController(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: 510
diff changeset
231
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
232 self._listener = GameListener(self)
510
cd959b05a262 There is now a main menu. You can also view the credits. Taking a screenshot and opening the console should also work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 509
diff changeset
233
cd959b05a262 There is now a main menu. You can also view the credits. Taking a screenshot and opening the console should also work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 509
diff changeset
234 self._guicontroller.showMainMenu()
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: 510
diff changeset
235
550
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
236 self._questmanager = QuestManager(self)
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
237
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: 510
diff changeset
238 self._scene = 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
239 self._instancerenderer = None
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
240 self._floatingtextrenderer = None
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
241
540
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
242 self._switchmaprequested = False
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
243 self._newmap = None
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
244
510
cd959b05a262 There is now a main menu. You can also view the credits. Taking a screenshot and opening the console should also work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 509
diff changeset
245 def onConsoleCommand(self, command):
cd959b05a262 There is now a main menu. You can also view the credits. Taking a screenshot and opening the console should also work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 509
diff changeset
246 """
550
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
247 Parses game related console commands.
510
cd959b05a262 There is now a main menu. You can also view the credits. Taking a screenshot and opening the console should also work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 509
diff changeset
248 """
530
ea26e7b6f56c Added the loadActor and loadItem functions so you can load single items at any time.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 528
diff changeset
249
510
cd959b05a262 There is now a main menu. You can also view the credits. Taking a screenshot and opening the console should also work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 509
diff changeset
250 result = ""
530
ea26e7b6f56c Added the loadActor and loadItem functions so you can load single items at any time.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 528
diff changeset
251
ea26e7b6f56c Added the loadActor and loadItem functions so you can load single items at any time.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 528
diff changeset
252 args = command.split(" ")
531
801746c5bb9a Added the spawn console command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 530
diff changeset
253 cmd = []
530
ea26e7b6f56c Added the loadActor and loadItem functions so you can load single items at any time.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 528
diff changeset
254 for arg in args:
ea26e7b6f56c Added the loadActor and loadItem functions so you can load single items at any time.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 528
diff changeset
255 arg = arg.strip()
531
801746c5bb9a Added the spawn console command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 530
diff changeset
256 if arg != "":
801746c5bb9a Added the spawn console command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 530
diff changeset
257 cmd.append(arg)
801746c5bb9a Added the spawn console command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 530
diff changeset
258
801746c5bb9a Added the spawn console command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 530
diff changeset
259 if cmd[0] == "spawn":
547
e59ece21ab3e Item serialization will now assume some default values if they are not found in the save files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 546
diff changeset
260 result = "Usage: spawn [object template] [posx] [posy] "
546
8fee2d2286e9 Rewrote the object serializing routines to use a "template" idea for loading an object from disk. This allows for multiple objects to load the same base object template but be unique on the scene AND have different values. Useful for say more than one gold stack on the ground with different gold values. TODO: fix the "spawn" console command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 545
diff changeset
261 if len(cmd) != 4:
531
801746c5bb9a Added the spawn console command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 530
diff changeset
262 return result
530
ea26e7b6f56c Added the loadActor and loadItem functions so you can load single items at any time.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 528
diff changeset
263 else:
535
9fbe3dce925a Added custom exceptions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 534
diff changeset
264 try:
547
e59ece21ab3e Item serialization will now assume some default values if they are not found in the save files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 546
diff changeset
265 id = str(uuid.uuid1())
e59ece21ab3e Item serialization will now assume some default values if they are not found in the save files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 546
diff changeset
266 valdict = { "posx" : float(cmd[2]), "posy" : float(cmd[3]) }
e59ece21ab3e Item serialization will now assume some default values if they are not found in the save files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 546
diff changeset
267 obj = self._scene.loadObject(cmd[1], id, valdict)
535
9fbe3dce925a Added custom exceptions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 534
diff changeset
268 except ObjectNotFoundError, e:
546
8fee2d2286e9 Rewrote the object serializing routines to use a "template" idea for loading an object from disk. This allows for multiple objects to load the same base object template but be unique on the scene AND have different values. Useful for say more than one gold stack on the ground with different gold values. TODO: fix the "spawn" console command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 545
diff changeset
269 result = "Error: Cannot load [" + cmd[1] + "]. It could not be found!"
535
9fbe3dce925a Added custom exceptions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 534
diff changeset
270 obj = None
9fbe3dce925a Added custom exceptions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 534
diff changeset
271
531
801746c5bb9a Added the spawn console command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 530
diff changeset
272 if obj:
536
1afe46247ab1 Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 535
diff changeset
273 try:
1afe46247ab1 Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 535
diff changeset
274 self._scene.addObjectToScene(obj)
546
8fee2d2286e9 Rewrote the object serializing routines to use a "template" idea for loading an object from disk. This allows for multiple objects to load the same base object template but be unique on the scene AND have different values. Useful for say more than one gold stack on the ground with different gold values. TODO: fix the "spawn" console command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 545
diff changeset
275 obj.position = (float(cmd[2]), float(cmd[3]))
536
1afe46247ab1 Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 535
diff changeset
276 result = "--OK--"
1afe46247ab1 Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 535
diff changeset
277 except ObjectAlreadyInSceneError, e:
546
8fee2d2286e9 Rewrote the object serializing routines to use a "template" idea for loading an object from disk. This allows for multiple objects to load the same base object template but be unique on the scene AND have different values. Useful for say more than one gold stack on the ground with different gold values. TODO: fix the "spawn" console command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 545
diff changeset
278 result = "Error: [" + cmd[1] + "] is already on the scene."
537
764510a6d2f9 Added the move command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 536
diff changeset
279
764510a6d2f9 Added the move command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 536
diff changeset
280 elif cmd[0] == "move":
764510a6d2f9 Added the move command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 536
diff changeset
281 result = "Usage: move [object id] [posx] [posy]"
764510a6d2f9 Added the move command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 536
diff changeset
282 if len(cmd) != 4:
764510a6d2f9 Added the move command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 536
diff changeset
283 return result
764510a6d2f9 Added the move command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 536
diff changeset
284 else:
764510a6d2f9 Added the move command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 536
diff changeset
285 obj = self._scene.getObject(cmd[1])
764510a6d2f9 Added the move command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 536
diff changeset
286 if obj:
764510a6d2f9 Added the move command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 536
diff changeset
287 obj.position = (float(cmd[2]), float(cmd[3]))
764510a6d2f9 Added the move command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 536
diff changeset
288 result = "--OK--"
764510a6d2f9 Added the move command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 536
diff changeset
289 else:
764510a6d2f9 Added the move command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 536
diff changeset
290 result = "Error: [" + cmd[1] + "] does not exist on the scene."
546
8fee2d2286e9 Rewrote the object serializing routines to use a "template" idea for loading an object from disk. This allows for multiple objects to load the same base object template but be unique on the scene AND have different values. Useful for say more than one gold stack on the ground with different gold values. TODO: fix the "spawn" console command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 545
diff changeset
291
8fee2d2286e9 Rewrote the object serializing routines to use a "template" idea for loading an object from disk. This allows for multiple objects to load the same base object template but be unique on the scene AND have different values. Useful for say more than one gold stack on the ground with different gold values. TODO: fix the "spawn" console command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 545
diff changeset
292 elif cmd[0] == "loadmap":
8fee2d2286e9 Rewrote the object serializing routines to use a "template" idea for loading an object from disk. This allows for multiple objects to load the same base object template but be unique on the scene AND have different values. Useful for say more than one gold stack on the ground with different gold values. TODO: fix the "spawn" console command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 545
diff changeset
293 result = "Usage: loadmap [map name]"
8fee2d2286e9 Rewrote the object serializing routines to use a "template" idea for loading an object from disk. This allows for multiple objects to load the same base object template but be unique on the scene AND have different values. Useful for say more than one gold stack on the ground with different gold values. TODO: fix the "spawn" console command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 545
diff changeset
294
530
ea26e7b6f56c Added the loadActor and loadItem functions so you can load single items at any time.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 528
diff changeset
295
510
cd959b05a262 There is now a main menu. You can also view the credits. Taking a screenshot and opening the console should also work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 509
diff changeset
296 return result
cd959b05a262 There is now a main menu. You can also view the credits. Taking a screenshot and opening the console should also work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 509
diff changeset
297
cd959b05a262 There is now a main menu. You can also view the credits. Taking a screenshot and opening the console should also work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 509
diff changeset
298 def newGame(self):
550
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
299 """
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
300 Removes any save games and starts a new game.
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
301 """
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
302
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: 510
diff changeset
303 self._guicontroller.hideMainMenu()
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
304
545
bc7e3c3122d7 The save xml files are now deleted correctly on the Mac platform.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
305 for filename in glob.glob(os.path.join("saves" , "*.xml")):
543
cb7ec12214a9 Items can now be serialized/deserialized to/from disk. I haven't finished actors yet. This allows for persistent states when you enter/leave maps.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
diff changeset
306 os.remove(filename)
560
69d50e751c9a Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 552
diff changeset
307
69d50e751c9a Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 552
diff changeset
308
69d50e751c9a Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 552
diff changeset
309 self._questmanager.reset()
69d50e751c9a Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 552
diff changeset
310 self._questmanager.deserialize()
543
cb7ec12214a9 Items can now be serialized/deserialized to/from disk. I haven't finished actors yet. This allows for persistent states when you enter/leave maps.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
diff changeset
311
540
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
312 mapname = self._settings.get("RPG", "TownMapFile", "town")
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
313 self.loadMap(mapname)
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
314
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
315
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
316 def loadMap(self, mapname):
550
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
317 """
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
318 Creates the scene for the map and attaches the listener.
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
319 """
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
320
540
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
321 if self._listener:
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
322 self._listener.detach()
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
323
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
324 self._keystate.reset()
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
325
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: 510
diff changeset
326 if self._scene:
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
327 self._scene.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: 510
diff changeset
328 self._scene = None
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
329
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
330 self._scene = Scene(self)
543
cb7ec12214a9 Items can now be serialized/deserialized to/from disk. I haven't finished actors yet. This allows for persistent states when you enter/leave maps.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
diff changeset
331
cb7ec12214a9 Items can now be serialized/deserialized to/from disk. I haven't finished actors yet. This allows for persistent states when you enter/leave maps.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
diff changeset
332 self._scene.createScene(mapname)
540
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
333
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
334 self._instancerenderer = fife.InstanceRenderer.getInstance(self._scene.cameras[self._settings.get("RPG", "DefaultCameraName", "camera1")])
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
335 self._floatingtextrenderer = fife.FloatingTextRenderer.getInstance(self._scene.cameras[self._settings.get("RPG", "DefaultCameraName", "camera1")])
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
336 self._floatingtextrenderer.addActiveLayer(self._scene.actorlayer)
540
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
337
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
338 if self._listener:
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
339 self._listener.attach()
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
340
540
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
341 def switchMap(self, newmapname):
550
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
342 """
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
343 Queues a map switch for next frame. This must be done next frame to ensure
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
344 all events pertaining to the current frame have finished being processed.
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
345 """
540
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
346 self._switchmaprequested = True
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
347 self._newmap = newmapname
543
cb7ec12214a9 Items can now be serialized/deserialized to/from disk. I haven't finished actors yet. This allows for persistent states when you enter/leave maps.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
diff changeset
348
546
8fee2d2286e9 Rewrote the object serializing routines to use a "template" idea for loading an object from disk. This allows for multiple objects to load the same base object template but be unique on the scene AND have different values. Useful for say more than one gold stack on the ground with different gold values. TODO: fix the "spawn" console command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 545
diff changeset
349 #save before switching scenes
543
cb7ec12214a9 Items can now be serialized/deserialized to/from disk. I haven't finished actors yet. This allows for persistent states when you enter/leave maps.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
diff changeset
350 self._scene.serialize()
540
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
351
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
352 def endGame(self):
550
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
353 """
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
354 Saves the game state and destroys the scene.
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
355 """
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
356 if self._scene:
543
cb7ec12214a9 Items can now be serialized/deserialized to/from disk. I haven't finished actors yet. This allows for persistent states when you enter/leave maps.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 540
diff changeset
357 self._scene.serialize()
551
3b933753cba8 QuestManager now loads all quests.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 550
diff changeset
358
540
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
359 self._listener.detach()
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
360 self._scene.destroyScene()
560
69d50e751c9a Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 552
diff changeset
361 self._questmanager.reset()
552
718e154a43c8 When you click on an object behind the player the click is no longer ignored.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 551
diff changeset
362
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
363 self._scene = None
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
364 self._instancerenderer = None
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
365 self._floatingtextrenderer = 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
366
510
cd959b05a262 There is now a main menu. You can also view the credits. Taking a screenshot and opening the console should also work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 509
diff changeset
367 def quit(self):
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
368 self.endGame()
510
cd959b05a262 There is now a main menu. You can also view the credits. Taking a screenshot and opening the console should also work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 509
diff changeset
369 self._application.requestQuit()
cd959b05a262 There is now a main menu. You can also view the credits. Taking a screenshot and opening the console should also work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 509
diff changeset
370
509
3951042a701e Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
371 def pump(self):
540
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
372 if self._switchmaprequested:
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
373 self.loadMap(self._newmap)
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
374 self._newmap = None
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
375 self._switchmaprequested = False
2e739ae9a8bc Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 537
diff changeset
376
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: 510
diff changeset
377 if self._scene:
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
378 self._scene.updateScene()
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
379
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
380
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
381 def _getGUIController(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: 510
diff changeset
382 return self._guicontroller
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
383
550
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
384 def _getQuestManager(self):
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
385 return self._questmanager
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
386
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: 510
diff changeset
387 def _getEngine(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: 510
diff changeset
388 return self._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: 510
diff changeset
389
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
390 def _getSettings(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: 510
diff changeset
391 return self._settings
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
392
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
393 def _getScene(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
394 return self._scene
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
395
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
396 def _getKeyState(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
397 return self._keystate
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
398
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
399 def _getInstanceRenderer(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
400 return self._instancerenderer
536
1afe46247ab1 Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 535
diff changeset
401
1afe46247ab1 Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 535
diff changeset
402 def _getLogManager(self):
1afe46247ab1 Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 535
diff changeset
403 return self._application.logger
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
404
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: 510
diff changeset
405 guicontroller = property(_getGUIController)
550
d0282579668c Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 547
diff changeset
406 questmanager = property(_getQuestManager)
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: 510
diff changeset
407 engine = property(_getEngine)
6ddb1eb9dfa6 Added the Scene which loads the town map. It is no longer a black screen demo.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 510
diff changeset
408 settings = property(_getSettings)
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
409 scene = property(_getScene)
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
410 keystate = property(_getKeyState)
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
411 instancerenderer = property(_getInstanceRenderer)
536
1afe46247ab1 Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 535
diff changeset
412 logger = property(_getLogManager)