# HG changeset patch
# User prock@33b003aa-7bff-0310-803a-e67f0ece8222
# Date 1274474023 0
# Node ID edf5c0cf52f33192fe481b3a59eaa8026824f4ea
# Parent 6ddb1eb9dfa6e4ebb1e09d3a4b22fe7697a72789
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
Added a help file for the console.
Added a KeyState class for keeping track of the state of the keys.
diff -r 6ddb1eb9dfa6 -r edf5c0cf52f3 demos/rpg/maps/level1.xml
--- a/demos/rpg/maps/level1.xml Fri May 21 17:31:08 2010 +0000
+++ b/demos/rpg/maps/level1.xml Fri May 21 20:33:43 2010 +0000
@@ -1,6 +1,10 @@
diff -r 6ddb1eb9dfa6 -r edf5c0cf52f3 demos/rpg/maps/town.xml
--- a/demos/rpg/maps/town.xml Fri May 21 17:31:08 2010 +0000
+++ b/demos/rpg/maps/town.xml Fri May 21 20:33:43 2010 +0000
@@ -1,6 +1,10 @@
diff -r 6ddb1eb9dfa6 -r edf5c0cf52f3 demos/rpg/misc/help.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/demos/rpg/misc/help.txt Fri May 21 20:33:43 2010 +0000
@@ -0,0 +1,3 @@
+help - This message
+exit - Quit the game
+quit - Quit the game
diff -r 6ddb1eb9dfa6 -r edf5c0cf52f3 demos/rpg/scripts/actors/__init__.py
diff -r 6ddb1eb9dfa6 -r edf5c0cf52f3 demos/rpg/scripts/actors/baseactor.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/demos/rpg/scripts/actors/baseactor.py Fri May 21 20:33:43 2010 +0000
@@ -0,0 +1,85 @@
+#!/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.loaders import loadMapFile
+
+class Actor(object):
+ def __init__(self, gamecontroller, instancename, instanceid=None, createInstance=False):
+ """
+ @param gamecontroller: A reference to the master game controller
+ @param instancename: The name of the object to load. The object's XML file must
+ be part of the map file or added with fife.extensions.loaders.loadImportFile
+ @param instanceid: used if you want to give a specific ID to the instance to
+ differenciate it from other instances
+ @param createInstance: If this is True it will attempt to be loaded from disk and not
+ use one that has already been loaded from the map file. See the note about the
+ instancename paramater above.
+ """
+ self._gamecontroller = gamecontroller
+ self._fifeobject = None
+ self._name = instancename
+ if instanceid:
+ self._id = instanceid
+ else:
+ self._id = self._name
+
+ self._instance = None
+
+ if createInstance:
+ self._createFIFEInstance(self._name)
+ else:
+ self._instance = self._gamecontroller.scene.layer.getInstance(self._id)
+ self._instance.thisown = 0
+
+ def destroy(self):
+ """
+ Deletes the FIFE instance from the actor layer on the map.
+ """
+ if self._instance :
+ self._gamecontroller.scene.actorlayer.deleteInstance(self._instance)
+ self._instance = None
+
+ def _createFIFEInstance(self):
+ """
+ Should not be called directly. Use the constructor!
+ """
+ mapmodel = self._gamecontroller.engine.getModel()
+ self._fifeobject = mapmodel.getObject(self._name, self._gamecontroller.settings.get("RPG", "ObjectNamespace", "http://www.fifengine.de/xml/rpg"))
+
+ self._instance = self._gamecontroller.scene.actorlayer.createInstance(self._fifeobject, fife.ModelCoordinate(0,0), self._id)
+ fife.InstanceVisual.create(self._instance)
+ self._instance.thisown = 0
+
+ def _getLocation(self):
+ return self._instance.getLocation()
+
+ def _setLocation(self, loc):
+ self._instance.setLocation(loc)
+
+ location = property(_getLocation,_setLocation)
diff -r 6ddb1eb9dfa6 -r edf5c0cf52f3 demos/rpg/scripts/actors/player.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/demos/rpg/scripts/actors/player.py Fri May 21 20:33:43 2010 +0000
@@ -0,0 +1,35 @@
+#!/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 scripts.actors.baseactor import Actor
+
+class Player(Actor):
+ def __init__(self, gamecontroller, playermodelname):
+ super(Player, self).__init__(gamecontroller, playermodelname, "player", True)
+ self._playermodelname = playermodelname
diff -r 6ddb1eb9dfa6 -r edf5c0cf52f3 demos/rpg/scripts/gamecontroller.py
--- a/demos/rpg/scripts/gamecontroller.py Fri May 21 17:31:08 2010 +0000
+++ b/demos/rpg/scripts/gamecontroller.py Fri May 21 20:33:43 2010 +0000
@@ -31,6 +31,22 @@
from scripts.scene import Scene
from scripts.guicontroller import GUIController
+class KeyState(object):
+ def __init__(self):
+ self._keystate = { }
+
+ def updateKey(self, key, state):
+ self._keystate[key] = state
+
+ def checkKey(self, key):
+ if key in self._keystate:
+ return self._keystate[key]
+ else:
+ return False
+
+ def reset(self):
+ self._keystate.clear()
+
class GameListener(fife.IKeyListener, fife.IMouseListener):
def __init__(self, gamecontroller):
self._engine = gamecontroller.engine
@@ -83,9 +99,15 @@
self.detach()
self._gamecontroller.guicontroller.showMainMenu()
event.consume()
+
+ self._gamecontroller.keystate.updateKey(keyval, True)
def keyReleased(self, event):
- pass
+ keyval = event.getKey().getValue()
+ keystr = event.getKey().getAsString().lower()
+
+ self._gamecontroller.keystate.updateKey(keyval, False)
+
class GameController(object):
def __init__(self, application, engine, settings):
@@ -93,6 +115,8 @@
self._engine = engine
self._settings = settings
+ self._keystate = KeyState()
+
self._guicontroller = GUIController(self)
self._listener = GameListener(self)
@@ -112,6 +136,8 @@
def newGame(self):
self._guicontroller.hideMainMenu()
+ self._keystate.reset()
+
if self._scene:
self._scene.destroyScene()
self._scene = None
@@ -122,7 +148,13 @@
#start listening to events
self._listener.attach()
+ def endGame(self):
+ if self._scene:
+ self._scene.destroyScene()
+ self._scene = None
+
def quit(self):
+ self.endGame()
self._application.requestQuit()
def pump(self):
@@ -139,6 +171,14 @@
def _getSettings(self):
return self._settings
+ def _getScene(self):
+ return self._scene
+
+ def _getKeyState(self):
+ return self._keystate
+
guicontroller = property(_getGUIController)
engine = property(_getEngine)
settings = property(_getSettings)
+ scene = property(_getScene)
+ keystate = property(_getKeyState)
diff -r 6ddb1eb9dfa6 -r edf5c0cf52f3 demos/rpg/scripts/rpg.py
--- a/demos/rpg/scripts/rpg.py Fri May 21 17:31:08 2010 +0000
+++ b/demos/rpg/scripts/rpg.py Fri May 21 20:33:43 2010 +0000
@@ -96,10 +96,10 @@
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 --"
+ helptextfile = self._gamecontroller.settings.get("RPG", "HelpText", "misc/help.txt")
+ self._engine.getGuiManager().getConsole().println( open( helptextfile, 'r' ).read() )
+ result = "-OK-"
else:
- pass
result = self._gamecontroller.onConsoleCommand(command)
if not result:
try:
@@ -107,7 +107,7 @@
except:
pass
if not result:
- result = 'no result'
+ result = 'Command Not Found...'
return result
def onToolsClick(self):
@@ -139,5 +139,6 @@
def _pump(self):
if self._listener.quit:
self.breakRequested = True
+ self._gamecontroller.endGame()
else:
self._gamecontroller.pump()
diff -r 6ddb1eb9dfa6 -r edf5c0cf52f3 demos/rpg/scripts/scene.py
--- a/demos/rpg/scripts/scene.py Fri May 21 17:31:08 2010 +0000
+++ b/demos/rpg/scripts/scene.py Fri May 21 20:33:43 2010 +0000
@@ -29,6 +29,8 @@
from fife import fife
from fife.extensions.loaders import loadMapFile
+from scripts.actors.player import Player
+
class Scene(object):
def __init__(self, gamecontroller):
self._gamecontroller = gamecontroller
@@ -36,6 +38,10 @@
self._map = None
self._cameras = {}
+ self._actorlayer = None
+
+ self._player = None
+
def createScene(self, mapfilename):
if not self._map:
self._map = loadMapFile(mapfilename, self._gamecontroller.engine)
@@ -47,6 +53,8 @@
self._cameras[self._gamecontroller.settings.get("RPG", "DefaultCameraName", "camera1")].setZoom(1.0)
+ self._actorlayer = self._map.getLayer(self._gamecontroller.settings.get("RPG", "ActorLayer", "actor_layer"))
+
def destroyScene(self):
self._cameras.clear()
@@ -54,7 +62,13 @@
self._gamecontroller.engine.getModel().deleteMap(self._map)
self._map = None
+ self._actorlayer = None
def updateScene(self):
pass
+ def _getActorLayer(self):
+ return self._actorlayer
+
+ actorlayer = property(_getActorLayer)
+
diff -r 6ddb1eb9dfa6 -r edf5c0cf52f3 demos/rpg/settings-dist.xml
--- a/demos/rpg/settings-dist.xml Fri May 21 17:31:08 2010 +0000
+++ b/demos/rpg/settings-dist.xml Fri May 21 20:33:43 2010 +0000
@@ -26,5 +26,8 @@
maps/town.xml
maps/level1.xml
camera1
+ http://www.fifengine.de/xml/rpg
+ actor_layer
+ misc/help.txt