# HG changeset patch # User prock@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1274823719 0 # Node ID d70fc46c8aa5429ce509483665a0e7b5a9ea9480 # Parent 520bd1621644aae03a1e691b368439855973e155 Added some placeholder graphics for the warrior. The player can now walk around the map. diff -r 520bd1621644 -r d70fc46c8aa5 demos/rpg/maps/town.xml --- a/demos/rpg/maps/town.xml Tue May 25 15:02:16 2010 +0000 +++ b/demos/rpg/maps/town.xml Tue May 25 21:41:59 2010 +0000 @@ -1,10 +1,6 @@ - - - - @@ -153,6 +149,10 @@ + + + + diff -r 520bd1621644 -r d70fc46c8aa5 demos/rpg/objects/actors/player/warrior/object.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demos/rpg/objects/actors/player/warrior/object.xml Tue May 25 21:41:59 2010 +0000 @@ -0,0 +1,6 @@ + + + + + + diff -r 520bd1621644 -r d70fc46c8aa5 demos/rpg/objects/actors/player/warrior/walk/045.png Binary file demos/rpg/objects/actors/player/warrior/walk/045.png has changed diff -r 520bd1621644 -r d70fc46c8aa5 demos/rpg/objects/actors/player/warrior/walk/animation.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demos/rpg/objects/actors/player/warrior/walk/animation.xml Tue May 25 21:41:59 2010 +0000 @@ -0,0 +1,4 @@ + + + + diff -r 520bd1621644 -r d70fc46c8aa5 demos/rpg/objects/ground/grass/01/135.png Binary file demos/rpg/objects/ground/grass/01/135.png has changed diff -r 520bd1621644 -r d70fc46c8aa5 demos/rpg/objects/ground/grass/01/225.png Binary file demos/rpg/objects/ground/grass/01/225.png has changed diff -r 520bd1621644 -r d70fc46c8aa5 demos/rpg/objects/ground/grass/01/315.png Binary file demos/rpg/objects/ground/grass/01/315.png has changed diff -r 520bd1621644 -r d70fc46c8aa5 demos/rpg/objects/ground/grass/01/45.png Binary file demos/rpg/objects/ground/grass/01/45.png has changed diff -r 520bd1621644 -r d70fc46c8aa5 demos/rpg/objects/ground/grass/01/object.xml --- a/demos/rpg/objects/ground/grass/01/object.xml Tue May 25 15:02:16 2010 +0000 +++ b/demos/rpg/objects/ground/grass/01/object.xml Tue May 25 21:41:59 2010 +0000 @@ -1,4 +1,7 @@ + + + diff -r 520bd1621644 -r d70fc46c8aa5 demos/rpg/scripts/actors/baseactor.py --- a/demos/rpg/scripts/actors/baseactor.py Tue May 25 15:02:16 2010 +0000 +++ b/demos/rpg/scripts/actors/baseactor.py Tue May 25 21:41:59 2010 +0000 @@ -29,6 +29,10 @@ from fife import fife from fife.extensions.loaders import loadMapFile +ActorStates = {'IDLE':0, + 'WALK':1, + 'ATTACK':2} + class Actor(object): def __init__(self, gamecontroller, instancename, instanceid=None, createInstance=False): """ @@ -52,10 +56,13 @@ self._instance = None if createInstance: - self._createFIFEInstance(self._name) + self._createFIFEInstance() else: - self._instance = self._gamecontroller.scene.layer.getInstance(self._id) - self._instance.thisown = 0 + self._instance = self._gamecontroller.scene.actorlayer.getInstance(self._id) + self._instance.thisown = 0 + + self._walkspeed = self._gamecontroller.settings.get("RPG", "DefaultActorWalkSpeed", 4.0) + self._state = ActorStates["IDLE"] def destroy(self): """ @@ -64,6 +71,10 @@ if self._instance : self._gamecontroller.scene.actorlayer.deleteInstance(self._instance) self._instance = None + + def walk(self, location): + self._state = ActorStates["WALK"] + self._instance.move('walk', location, self._walkspeed) def _createFIFEInstance(self): """ diff -r 520bd1621644 -r d70fc46c8aa5 demos/rpg/scripts/actors/player.py --- a/demos/rpg/scripts/actors/player.py Tue May 25 15:02:16 2010 +0000 +++ b/demos/rpg/scripts/actors/player.py Tue May 25 21:41:59 2010 +0000 @@ -27,7 +27,7 @@ import sys, os, re, math, random, shutil from fife import fife -from scripts.actors.baseactor import Actor +from scripts.actors.baseactor import Actor, ActorStates class Player(Actor): def __init__(self, gamecontroller, playermodelname): diff -r 520bd1621644 -r d70fc46c8aa5 demos/rpg/scripts/gamecontroller.py --- a/demos/rpg/scripts/gamecontroller.py Tue May 25 15:02:16 2010 +0000 +++ b/demos/rpg/scripts/gamecontroller.py Tue May 25 21:41:59 2010 +0000 @@ -30,6 +30,7 @@ from scripts.scene import Scene from scripts.guicontroller import GUIController +from fife.extensions.loaders import loadImportFile class KeyState(object): def __init__(self): @@ -55,15 +56,13 @@ self._eventmanager = self._engine.getEventManager() fife.IMouseListener.__init__(self) - self._eventmanager.addMouseListener(self) - fife.IKeyListener.__init__(self) - self._eventmanager.addKeyListener(self) self._attached = False def attach(self): if not self._attached: + self._gamecontroller.keystate.reset() self._eventmanager.addMouseListenerFront(self) self._eventmanager.addKeyListenerFront(self) self._attached = True @@ -75,9 +74,37 @@ self._attached = False def mousePressed(self, event): - pass + #mouse press was consumed by some pychan widget + if event.isConsumedByWidgets(): + return + + clickpoint = fife.ScreenPoint(event.getX(), event.getY()) + if (event.getButton() == fife.MouseEvent.LEFT): + self._gamecontroller.scene.player.walk( self._gamecontroller.scene.getLocationAt(clickpoint) ) + #self.hero.run( self.getLocationAt(clickpoint) ) + + if (event.getButton() == fife.MouseEvent.RIGHT): + instances = self._gamecontroller.scene.getInstancesAt(clickpoint) + print "selected instances on actor layer: ", [i.getObject().getId() for i in instances] + if instances: + #do something + pass + def mouseReleased(self, event): - pass + pass + + def mouseMoved(self, event): + renderer = self._gamecontroller.instancerenderer + if renderer: + renderer.removeAllOutlines() + else: + return + + pt = fife.ScreenPoint(event.getX(), event.getY()) + instances = self.getInstancesAt(pt); + for i in instances: + renderer.addOutlined(i, 173, 255, 47, 2) + def mouseEntered(self, event): pass def mouseExited(self, event): @@ -108,7 +135,6 @@ self._gamecontroller.keystate.updateKey(keyval, False) - class GameController(object): def __init__(self, application, engine, settings): self._application = application @@ -124,6 +150,7 @@ self._guicontroller.showMainMenu() self._scene = None + self._instancerenderer = None def onConsoleCommand(self, command): """ @@ -141,17 +168,22 @@ if self._scene: self._scene.destroyScene() self._scene = None + + loadImportFile("objects/actors/player/warrior/object.xml", self._engine) self._scene = Scene(self) self._scene.createScene(self._settings.get("RPG", "TownMapFile", "maps/town.xml")) + self._instancerenderer = fife.InstanceRenderer.getInstance(self._scene.cameras[self._settings.get("RPG", "DefaultCameraName", "camera1")]) + #start listening to events self._listener.attach() def endGame(self): if self._scene: self._scene.destroyScene() - self._scene = None + self._scene = None + self._instancerenderer = None def quit(self): self.endGame() @@ -177,8 +209,12 @@ def _getKeyState(self): return self._keystate + def _getInstanceRenderer(self): + return self._instancerenderer + guicontroller = property(_getGUIController) engine = property(_getEngine) settings = property(_getSettings) scene = property(_getScene) keystate = property(_getKeyState) + instancerenderer = property(_getInstanceRenderer) diff -r 520bd1621644 -r d70fc46c8aa5 demos/rpg/scripts/scene.py --- a/demos/rpg/scripts/scene.py Tue May 25 15:02:16 2010 +0000 +++ b/demos/rpg/scripts/scene.py Tue May 25 21:41:59 2010 +0000 @@ -36,6 +36,7 @@ self._gamecontroller = gamecontroller self._map = None + self._maincameraname = self._gamecontroller.settings.get("RPG", "DefaultCameraName", "camera1") self._cameras = {} self._actorlayer = None @@ -51,10 +52,12 @@ for cam in self._map.getCameras(): self._cameras[cam.getId()] = cam - self._cameras[self._gamecontroller.settings.get("RPG", "DefaultCameraName", "camera1")].setZoom(1.0) + self._cameras[self._maincameraname].setZoom(self._gamecontroller.settings.get("RPG", "DefaultZoom", 2.0)) self._actorlayer = self._map.getLayer(self._gamecontroller.settings.get("RPG", "ActorLayer", "actor_layer")) + self._player = Player(self._gamecontroller, "warrior") + def destroyScene(self): self._cameras.clear() @@ -63,12 +66,37 @@ self._map = None self._actorlayer = None + + def getInstancesAt(self, clickpoint): + """ + Query the main camera for instances on our actor layer. + """ + return self.cameras[self._maincameraname].getMatchingInstances(clickpoint, self._actorlayer) + + def getLocationAt(self, clickpoint): + """ + Query the main camera for the Map location (on the agent layer) + that a screen point refers to. + """ + target_mapcoord = self._cameras[self._maincameraname].toMapCoordinates(clickpoint, False) + target_mapcoord.z = 0 + location = fife.Location(self._actorlayer) + location.setMapCoordinates(target_mapcoord) + return location def updateScene(self): pass def _getActorLayer(self): return self._actorlayer - + + def _getCameras(self): + return self._cameras + + def _getPlayer(self): + return self._player + actorlayer = property(_getActorLayer) + cameras = property(_getCameras) + player = property(_getPlayer) diff -r 520bd1621644 -r d70fc46c8aa5 demos/rpg/settings-dist.xml --- a/demos/rpg/settings-dist.xml Tue May 25 15:02:16 2010 +0000 +++ b/demos/rpg/settings-dist.xml Tue May 25 21:41:59 2010 +0000 @@ -26,8 +26,11 @@ maps/town.xml maps/level1.xml camera1 + 2.0 http://www.fifengine.de/xml/rpg actor_layer misc/help.txt + + 2.5