changeset 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 c8820cc201db
children cd959b05a262
files demos/rpg/fonts/FreeSans.ttf demos/rpg/maps/level1.xml demos/rpg/maps/town.xml demos/rpg/objects/ground/grass/01/45.png demos/rpg/objects/ground/grass/01/object.xml demos/rpg/run.py demos/rpg/scripts/__init__.py demos/rpg/scripts/common/__init__.py demos/rpg/scripts/common/eventlistenerbase.py demos/rpg/scripts/gamecontroller.py demos/rpg/scripts/rpg.py demos/rpg/settings-dist.xml
diffstat 10 files changed, 432 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
Binary file demos/rpg/fonts/FreeSans.ttf has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demos/rpg/maps/level1.xml	Thu May 20 19:55:19 2010 +0000
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="ascii"?>
+<map id="testrpg" format="1.0">
+	<import file="objects/grass_and_water/object.xml"></import>
+	<layer y_scale="1.0" y_offset="0.0" pathing="cell_edges_only" grid_type="square" id="sdf" rotation="45.0" x_scale="1.0" x_offset="0.0" transparency="0">
+		<instances>
+			<i o="grass01" ns="http://www.fifengine.de/xml/rpg" x="-2.0" r="0" y="0.0" z="0.0"></i>
+			<i r="0" x="-2.0" o="grass01" z="0.0" y="1.0"></i>
+			<i r="0" x="-1.0" o="grass01" z="0.0" y="1.0"></i>
+			<i r="0" x="-1.0" o="grass01" z="0.0" y="2.0"></i>
+			<i r="0" x="0.0" o="grass01" z="0.0" y="2.0"></i>
+			<i r="0" x="0.0" o="grass01" z="0.0" y="1.0"></i>
+			<i r="0" x="1.0" o="grass01" z="0.0" y="1.0"></i>
+			<i r="0" x="1.0" o="grass01" z="0.0" y="0.0"></i>
+			<i r="0" x="-1.0" o="grass01" z="0.0" y="-1.0"></i>
+			<i r="0" x="-1.0" o="grass01" z="0.0" y="0.0"></i>
+			<i r="0" x="-2.0" o="grass01" z="0.0" y="2.0"></i>
+			<i r="0" x="-3.0" o="grass01" z="0.0" y="1.0"></i>
+			<i r="0" x="-1.0" o="grass01" z="0.0" y="-2.0"></i>
+			<i r="0" x="-2.0" o="grass01" z="0.0" y="-2.0"></i>
+			<i r="0" x="-2.0" o="grass01" z="0.0" y="-1.0"></i>
+			<i r="0" x="0.0" o="grass01" z="0.0" y="0.0"></i>
+			<i r="0" x="0.0" o="grass01" z="0.0" y="-1.0"></i>
+			<i r="0" x="-1.0" o="grass01" z="0.0" y="3.0"></i>
+			<i r="0" x="0.0" o="grass01" z="0.0" y="3.0"></i>
+			<i r="0" x="1.0" o="grass01" z="0.0" y="2.0"></i>
+			<i r="0" x="1.0" o="grass01" z="0.0" y="3.0"></i>
+			<i r="0" x="2.0" o="grass01" z="0.0" y="1.0"></i>
+			<i r="0" x="1.0" o="grass01" z="0.0" y="-1.0"></i>
+			<i r="0" x="-2.0" o="grass01" z="0.0" y="3.0"></i>
+			<i r="0" x="-1.0" o="grass01" z="0.0" y="4.0"></i>
+			<i r="0" x="0.0" o="grass01" z="0.0" y="4.0"></i>
+			<i r="0" x="-3.0" o="grass01" z="0.0" y="0.0"></i>
+			<i r="0" x="-3.0" o="grass01" z="0.0" y="2.0"></i>
+			<i r="0" x="1.0" o="grass01" z="0.0" y="-2.0"></i>
+			<i r="0" x="1.0" o="grass01" z="0.0" y="4.0"></i>
+			<i r="0" x="0.0" o="grass01" z="0.0" y="-2.0"></i>
+			<i r="0" x="0.0" o="grass01" z="0.0" y="-3.0"></i>
+			<i r="0" x="-1.0" o="grass01" z="0.0" y="-3.0"></i>
+			<i r="0" x="-3.0" o="grass01" z="0.0" y="-1.0"></i>
+			<i r="0" x="-3.0" o="grass01" z="0.0" y="3.0"></i>
+			<i r="0" x="-2.0" o="grass01" z="0.0" y="4.0"></i>
+		</instances>
+	</layer>
+	<camera ref_cell_height="64" zoom="1.0" rotation="45.0" ref_layer_id="sdf" ref_cell_width="64" id="sdf" tilt="60.0">
+	</camera>
+</map>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demos/rpg/maps/town.xml	Thu May 20 19:55:19 2010 +0000
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="ascii"?>
+<map id="testrpg" format="1.0">
+	<import file="objects/grass_and_water/object.xml"></import>
+	<layer y_scale="1.0" y_offset="0.0" pathing="cell_edges_only" grid_type="square" id="sdf" rotation="45.0" x_scale="1.0" x_offset="0.0" transparency="0">
+		<instances>
+			<i o="grass01" ns="http://www.fifengine.de/xml/rpg" x="-2.0" r="0" y="0.0" z="0.0"></i>
+			<i r="0" x="-2.0" o="grass01" z="0.0" y="1.0"></i>
+			<i r="0" x="-1.0" o="grass01" z="0.0" y="1.0"></i>
+			<i r="0" x="-1.0" o="grass01" z="0.0" y="2.0"></i>
+			<i r="0" x="0.0" o="grass01" z="0.0" y="2.0"></i>
+			<i r="0" x="0.0" o="grass01" z="0.0" y="1.0"></i>
+			<i r="0" x="1.0" o="grass01" z="0.0" y="1.0"></i>
+			<i r="0" x="1.0" o="grass01" z="0.0" y="0.0"></i>
+			<i r="0" x="-1.0" o="grass01" z="0.0" y="-1.0"></i>
+			<i r="0" x="-1.0" o="grass01" z="0.0" y="0.0"></i>
+			<i r="0" x="-2.0" o="grass01" z="0.0" y="2.0"></i>
+			<i r="0" x="-3.0" o="grass01" z="0.0" y="1.0"></i>
+			<i r="0" x="-1.0" o="grass01" z="0.0" y="-2.0"></i>
+			<i r="0" x="-2.0" o="grass01" z="0.0" y="-2.0"></i>
+			<i r="0" x="-2.0" o="grass01" z="0.0" y="-1.0"></i>
+			<i r="0" x="0.0" o="grass01" z="0.0" y="0.0"></i>
+			<i r="0" x="0.0" o="grass01" z="0.0" y="-1.0"></i>
+			<i r="0" x="-1.0" o="grass01" z="0.0" y="3.0"></i>
+			<i r="0" x="0.0" o="grass01" z="0.0" y="3.0"></i>
+			<i r="0" x="1.0" o="grass01" z="0.0" y="2.0"></i>
+			<i r="0" x="1.0" o="grass01" z="0.0" y="3.0"></i>
+			<i r="0" x="2.0" o="grass01" z="0.0" y="1.0"></i>
+			<i r="0" x="1.0" o="grass01" z="0.0" y="-1.0"></i>
+			<i r="0" x="-2.0" o="grass01" z="0.0" y="3.0"></i>
+			<i r="0" x="-1.0" o="grass01" z="0.0" y="4.0"></i>
+			<i r="0" x="0.0" o="grass01" z="0.0" y="4.0"></i>
+			<i r="0" x="-3.0" o="grass01" z="0.0" y="0.0"></i>
+			<i r="0" x="-3.0" o="grass01" z="0.0" y="2.0"></i>
+			<i r="0" x="1.0" o="grass01" z="0.0" y="-2.0"></i>
+			<i r="0" x="1.0" o="grass01" z="0.0" y="4.0"></i>
+			<i r="0" x="0.0" o="grass01" z="0.0" y="-2.0"></i>
+			<i r="0" x="0.0" o="grass01" z="0.0" y="-3.0"></i>
+			<i r="0" x="-1.0" o="grass01" z="0.0" y="-3.0"></i>
+			<i r="0" x="-3.0" o="grass01" z="0.0" y="-1.0"></i>
+			<i r="0" x="-3.0" o="grass01" z="0.0" y="3.0"></i>
+			<i r="0" x="-2.0" o="grass01" z="0.0" y="4.0"></i>
+		</instances>
+	</layer>
+	<camera ref_cell_height="64" zoom="1.0" rotation="45.0" ref_layer_id="sdf" ref_cell_width="64" id="sdf" tilt="60.0">
+	</camera>
+</map>
Binary file demos/rpg/objects/ground/grass/01/45.png has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demos/rpg/objects/ground/grass/01/object.xml	Thu May 20 19:55:19 2010 +0000
@@ -0,0 +1,4 @@
+<?fife type="object"?>
+<object id="grass:01" namespace="http://www.fifengine.de/xml/rpg" blocking="0" static="1">
+	<image source="45.png" direction="45" />
+</object>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demos/rpg/run.py	Thu May 20 19:55:19 2010 +0000
@@ -0,0 +1,71 @@
+#!/usr/bin/env python
+
+# -*- coding: utf-8 -*-
+
+# ####################################################################
+#  Copyright (C) 2005-2010 by the FIFE team
+#  http://www.fifengine.net
+#  This file is part of FIFE.
+#
+#  FIFE is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU Lesser General Public
+#  License as published by the Free Software Foundation; either
+#  version 2.1 of the License, or (at your option) any later version.
+#
+#  This library is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  Lesser General Public License for more details.
+#
+#  You should have received a copy of the GNU Lesser General Public
+#  License along with this library; if not, write to the
+#  Free Software Foundation, Inc.,
+#  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+# ####################################################################
+# This is the rio de hola client for FIFE.
+
+import sys, os, re, math, random, shutil
+
+fife_path = os.path.join('..','..','engine','python')
+if os.path.isdir(fife_path) and fife_path not in sys.path:
+	sys.path.insert(0,fife_path)
+
+from fife import fife
+print "Using the FIFE python module found here: ", os.path.dirname(fife.__file__)
+
+from fife.extensions.fife_settings import Setting
+from scripts.rpg import RPGApplication
+
+
+TDS = Setting(app_name="rpg",
+              settings_file="./settings.xml", 
+              settings_gui_xml="")
+
+def main():
+	app = RPGApplication(TDS)
+	app.run()
+
+if __name__ == '__main__':
+	if TDS.get("FIFE", "ProfilingOn"):
+		import hotshot, hotshot.stats
+		print "Starting profiler"
+		prof = hotshot.Profile("fife.prof")
+		prof.runcall(main)
+		prof.close()
+		print "analysing profiling results"
+		stats = hotshot.stats.load("fife.prof")
+		stats.strip_dirs()
+		stats.sort_stats('time', 'calls')
+		stats.print_stats(20)
+	else:
+		if TDS.get("FIFE", "UsePsyco"):
+			# Import Psyco if available
+			try:
+				import psyco
+				psyco.full()
+				print "Psyco acceleration in use"
+			except ImportError:
+				print "Psyco acceleration not used"
+		else:
+			print "Psyco acceleration not used"
+		main()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demos/rpg/scripts/common/eventlistenerbase.py	Thu May 20 19:55:19 2010 +0000
@@ -0,0 +1,73 @@
+# -*- coding: utf-8 -*-
+
+# ####################################################################
+#  Copyright (C) 2005-2010 by the FIFE team
+#  http://www.fifengine.net
+#  This file is part of FIFE.
+#
+#  FIFE is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU Lesser General Public
+#  License as published by the Free Software Foundation; either
+#  version 2.1 of the License, or (at your option) any later version.
+#
+#  This library is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  Lesser General Public License for more details.
+#
+#  You should have received a copy of the GNU Lesser General Public
+#  License along with this library; if not, write to the
+#  Free Software Foundation, Inc.,
+#  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+# ####################################################################
+
+from fife import fife
+
+class EventListenerBase(fife.IKeyListener, fife.ICommandListener, fife.IMouseListener, fife.ConsoleExecuter):
+	def __init__(self, engine, regKeys=False, regCmd=False, regMouse=False, regConsole=False, regWidget=False):
+		self.eventmanager = engine.getEventManager()
+
+		fife.IKeyListener.__init__(self)
+		if regKeys:
+			self.eventmanager.addKeyListener(self)
+		fife.ICommandListener.__init__(self)
+		if regCmd:
+			self.eventmanager.addCommandListener(self)
+		fife.IMouseListener.__init__(self)
+		if regMouse:
+			self.eventmanager.addMouseListener(self)
+		fife.ConsoleExecuter.__init__(self)
+		if regConsole:
+			engine.getGuiManager().getConsole().setConsoleExecuter(self)
+
+
+	def mousePressed(self, evt):
+		pass
+	def mouseReleased(self, evt):
+		pass	
+	def mouseEntered(self, evt):
+		pass
+	def mouseExited(self, evt):
+		pass
+	def mouseClicked(self, evt):
+		pass
+	def mouseWheelMovedUp(self, evt):
+		pass	
+	def mouseWheelMovedDown(self, evt):
+		pass
+	def mouseMoved(self, evt):
+		pass
+	def mouseDragged(self, evt):
+		pass
+	def keyPressed(self, evt):
+		pass
+	def keyReleased(self, evt):
+		pass
+	def onCommand(self, command):
+		pass
+	def onToolsClick(self):
+		print "No tools set up yet"
+	def onConsoleCommand(self, command):
+		pass
+	def onWidgetAction(self, evt):
+		pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demos/rpg/scripts/gamecontroller.py	Thu May 20 19:55:19 2010 +0000
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+
+# -*- coding: utf-8 -*-
+
+# ####################################################################
+#  Copyright (C) 2005-2010 by the FIFE team
+#  http://www.fifengine.net
+#  This file is part of FIFE.
+#
+#  FIFE is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU Lesser General Public
+#  License as published by the Free Software Foundation; either
+#  version 2.1 of the License, or (at your option) any later version.
+#
+#  This library is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  Lesser General Public License for more details.
+#
+#  You should have received a copy of the GNU Lesser General Public
+#  License along with this library; if not, write to the
+#  Free Software Foundation, Inc.,
+#  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+# ####################################################################
+# This is the rio de hola client for FIFE.
+
+import sys, os, re, math, random, shutil
+
+from fife import fife
+
+class GameController(object):
+	def __init__(self, application, engine, settings):
+		self._application = application
+		self._engine = engine
+		self._settings = settings
+		
+	def pump(self):
+		pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demos/rpg/scripts/rpg.py	Thu May 20 19:55:19 2010 +0000
@@ -0,0 +1,125 @@
+#!/usr/bin/env python
+
+# -*- coding: utf-8 -*-
+
+# ####################################################################
+#  Copyright (C) 2005-2010 by the FIFE team
+#  http://www.fifengine.net
+#  This file is part of FIFE.
+#
+#  FIFE is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU Lesser General Public
+#  License as published by the Free Software Foundation; either
+#  version 2.1 of the License, or (at your option) any later version.
+#
+#  This library is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  Lesser General Public License for more details.
+#
+#  You should have received a copy of the GNU Lesser General Public
+#  License along with this library; if not, write to the
+#  Free Software Foundation, Inc.,
+#  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+# ####################################################################
+# This is the rio de hola client for FIFE.
+
+import sys, os, re, math, random, shutil
+
+from fife import fife
+from fife.extensions import *
+from scripts.gamecontroller import GameController
+from scripts.common import eventlistenerbase
+from fife.extensions.basicapplication import ApplicationBase
+from fife.extensions import pychan
+from fife.extensions.pychan import widgets
+from fife.extensions.fife_utils import getUserDataDirectory
+
+class KeyFilter(fife.IKeyFilter):
+	def __init__(self, keys):
+		fife.IKeyFilter.__init__(self)
+		self._keys = keys
+
+	def isFiltered(self, event):
+		return event.getKey().getValue() in self._keys
+
+class ApplicationListener(eventlistenerbase.EventListenerBase):
+	def __init__(self, engine, gamecontroller):
+		super(ApplicationListener, self).__init__(engine,regKeys=True,regCmd=True, regMouse=False, regConsole=True, regWidget=True)
+		self._engine = engine
+		self._gamecontroller = gamecontroller
+		
+		keyfilter = KeyFilter([fife.Key.ESCAPE])
+		keyfilter.__disown__()
+		
+		self._engine.getEventManager().setKeyFilter(keyfilter)
+
+		self.quit = False
+
+	def keyPressed(self, evt):
+		keyval = evt.getKey().getValue()
+		keystr = evt.getKey().getAsString().lower()
+		consumed = False
+		if keyval == fife.Key.ESCAPE:
+			self.quit = True
+			evt.consume()
+		elif keyval == fife.Key.F10:
+			self.engine.getGuiManager().getConsole().toggleShowHide()
+			evt.consume()
+		elif keystr == 'p':
+			self.engine.getRenderBackend().captureScreen('screenshot.png')
+			evt.consume()
+
+	def onCommand(self, command):
+		self.quit = (command.getCommandType() == fife.CMD_QUIT_GAME)
+		if self.quit:
+			command.consume()
+
+	def onConsoleCommand(self, command):
+		result = ''
+		if command.lower() in ('quit', 'exit'):
+			self.quit = True
+			result = 'quitting'
+		elif command.lower() in ( 'help', 'help()' ):
+			self.engine.getGuiManager().getConsole().println( open( 'misc/infotext.txt', 'r' ).read() )
+			result = "-- End of help --"
+		else:
+			pass
+			#result = self.world.onConsoleCommand(command)
+		if not result:
+			try:
+				result = str(eval(command))
+			except:
+				pass
+		if not result:
+			result = 'no result'
+		return result
+
+class RPGApplication(ApplicationBase):
+	def __init__(self, TDS):
+		super(RPGApplication,self).__init__(TDS)
+		self._settings = TDS
+		
+		pychan.init(self.engine, debug=self._settings.get("FIFE", "PychanDebug", False))
+		
+		self._gamecontroller = GameController(self, self.engine, self._settings)
+
+	def createListener(self):
+		"""
+		@note: This function had to be overloaded otherwise the default
+		listener would have been created.
+		"""
+		self._listener = ApplicationListener(self.engine, self._gamecontroller)
+		return self._listener
+		
+	def requestQuit(self):
+		cmd = fife.Command()
+		cmd.setSource(None)
+		cmd.setCommandType(fife.CMD_QUIT_GAME)
+		self.engine.getEventManager().dispatchCommand(cmd)
+
+	def _pump(self):
+		if self._listener.quit:
+			self.breakRequested = True
+		else:
+			self._gamecontroller.pump()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demos/rpg/settings-dist.xml	Thu May 20 19:55:19 2010 +0000
@@ -0,0 +1,29 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<Settings>
+	<Module name="FIFE">
+		<Setting name="FullScreen" type="int"> 0 </Setting>
+		<Setting name="PlaySounds" type="int"> 1 </Setting>
+		<Setting name="RenderBackend" type="str"> OpenGL </Setting>
+		<Setting name="ScreenWidth" type="int"> 1024 </Setting>
+		<Setting name="ScreenHeight" type="int"> 768 </Setting>
+		<Setting name="BitsPerPixel" type="int"> 0 </Setting>
+		<Setting name="InitialVolume" type="float"> 5.0 </Setting>
+		<Setting name="SDLRemoveFakeAlpha" type="int"> 1 </Setting>
+		<Setting name="WindowTitle" type="str"> FIFE - RPG Demo </Setting>
+		<Setting name="WindowIcon" type="str"> </Setting>
+		<Setting name="Font" type="str"> fonts/FreeSans.ttf </Setting>
+		<Setting name="FontGlyphs" strip="0" type="str"> abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%&amp;`'*#=[]\"</Setting>
+		<Setting name="DefaultFontSize" type="int"> 16 </Setting>
+		<Setting name="LogModules" type="list"> controller </Setting>
+		<Setting name="PychanDebug" type="bool"> False </Setting>
+		<Setting name="LogToPrompt" type="int"> 1 </Setting>
+ 		<Setting name="UsePsyco" type="bool"> False </Setting>
+		<Setting name="ProfilingOn" type="bool"> False </Setting>
+		<Setting name="LogToFile" type="int"> 0 </Setting>
+	</Module>
+
+	<Module name="RPG">
+		<Setting name="TownMapFile" type="str"> maps/town.xml </Setting>
+		<Setting name="Level1MapFile" type="str"> maps/level1.xml </Setting>
+	</Module>
+</Settings>