comparison demos/rpg/scripts/rpg.py @ 509:3951042a701e

Adding the RPG demo. This is basically empty at the moment. Currently it will start with a black screen.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 20 May 2010 19:55:19 +0000
parents
children cd959b05a262
comparison
equal deleted inserted replaced
508:c8820cc201db 509:3951042a701e
1 #!/usr/bin/env python
2
3 # -*- coding: utf-8 -*-
4
5 # ####################################################################
6 # Copyright (C) 2005-2010 by the FIFE team
7 # http://www.fifengine.net
8 # This file is part of FIFE.
9 #
10 # FIFE is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU Lesser General Public
12 # License as published by the Free Software Foundation; either
13 # version 2.1 of the License, or (at your option) any later version.
14 #
15 # This library is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 # Lesser General Public License for more details.
19 #
20 # You should have received a copy of the GNU Lesser General Public
21 # License along with this library; if not, write to the
22 # Free Software Foundation, Inc.,
23 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 # ####################################################################
25 # This is the rio de hola client for FIFE.
26
27 import sys, os, re, math, random, shutil
28
29 from fife import fife
30 from fife.extensions import *
31 from scripts.gamecontroller import GameController
32 from scripts.common import eventlistenerbase
33 from fife.extensions.basicapplication import ApplicationBase
34 from fife.extensions import pychan
35 from fife.extensions.pychan import widgets
36 from fife.extensions.fife_utils import getUserDataDirectory
37
38 class KeyFilter(fife.IKeyFilter):
39 def __init__(self, keys):
40 fife.IKeyFilter.__init__(self)
41 self._keys = keys
42
43 def isFiltered(self, event):
44 return event.getKey().getValue() in self._keys
45
46 class ApplicationListener(eventlistenerbase.EventListenerBase):
47 def __init__(self, engine, gamecontroller):
48 super(ApplicationListener, self).__init__(engine,regKeys=True,regCmd=True, regMouse=False, regConsole=True, regWidget=True)
49 self._engine = engine
50 self._gamecontroller = gamecontroller
51
52 keyfilter = KeyFilter([fife.Key.ESCAPE])
53 keyfilter.__disown__()
54
55 self._engine.getEventManager().setKeyFilter(keyfilter)
56
57 self.quit = False
58
59 def keyPressed(self, evt):
60 keyval = evt.getKey().getValue()
61 keystr = evt.getKey().getAsString().lower()
62 consumed = False
63 if keyval == fife.Key.ESCAPE:
64 self.quit = True
65 evt.consume()
66 elif keyval == fife.Key.F10:
67 self.engine.getGuiManager().getConsole().toggleShowHide()
68 evt.consume()
69 elif keystr == 'p':
70 self.engine.getRenderBackend().captureScreen('screenshot.png')
71 evt.consume()
72
73 def onCommand(self, command):
74 self.quit = (command.getCommandType() == fife.CMD_QUIT_GAME)
75 if self.quit:
76 command.consume()
77
78 def onConsoleCommand(self, command):
79 result = ''
80 if command.lower() in ('quit', 'exit'):
81 self.quit = True
82 result = 'quitting'
83 elif command.lower() in ( 'help', 'help()' ):
84 self.engine.getGuiManager().getConsole().println( open( 'misc/infotext.txt', 'r' ).read() )
85 result = "-- End of help --"
86 else:
87 pass
88 #result = self.world.onConsoleCommand(command)
89 if not result:
90 try:
91 result = str(eval(command))
92 except:
93 pass
94 if not result:
95 result = 'no result'
96 return result
97
98 class RPGApplication(ApplicationBase):
99 def __init__(self, TDS):
100 super(RPGApplication,self).__init__(TDS)
101 self._settings = TDS
102
103 pychan.init(self.engine, debug=self._settings.get("FIFE", "PychanDebug", False))
104
105 self._gamecontroller = GameController(self, self.engine, self._settings)
106
107 def createListener(self):
108 """
109 @note: This function had to be overloaded otherwise the default
110 listener would have been created.
111 """
112 self._listener = ApplicationListener(self.engine, self._gamecontroller)
113 return self._listener
114
115 def requestQuit(self):
116 cmd = fife.Command()
117 cmd.setSource(None)
118 cmd.setCommandType(fife.CMD_QUIT_GAME)
119 self.engine.getEventManager().dispatchCommand(cmd)
120
121 def _pump(self):
122 if self._listener.quit:
123 self.breakRequested = True
124 else:
125 self._gamecontroller.pump()