# HG changeset patch # User prock@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1274887705 0 # Node ID c3a026cdd91b70c6516422db64297ea62ecedf8b # Parent d70fc46c8aa5429ce509483665a0e7b5a9ea9480 Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners. diff -r d70fc46c8aa5 -r c3a026cdd91b demos/rpg/objects/actors/player/warrior/object.xml --- a/demos/rpg/objects/actors/player/warrior/object.xml Tue May 25 21:41:59 2010 +0000 +++ b/demos/rpg/objects/actors/player/warrior/object.xml Wed May 26 15:28:25 2010 +0000 @@ -1,5 +1,8 @@ + + + diff -r d70fc46c8aa5 -r c3a026cdd91b demos/rpg/objects/actors/player/warrior/stand/045.png Binary file demos/rpg/objects/actors/player/warrior/stand/045.png has changed diff -r d70fc46c8aa5 -r c3a026cdd91b demos/rpg/objects/actors/player/warrior/stand/animation.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demos/rpg/objects/actors/player/warrior/stand/animation.xml Wed May 26 15:28:25 2010 +0000 @@ -0,0 +1,4 @@ + + + + diff -r d70fc46c8aa5 -r c3a026cdd91b demos/rpg/scripts/actors/baseactor.py --- a/demos/rpg/scripts/actors/baseactor.py Tue May 25 21:41:59 2010 +0000 +++ b/demos/rpg/scripts/actors/baseactor.py Wed May 26 15:28:25 2010 +0000 @@ -29,68 +29,42 @@ from fife import fife from fife.extensions.loaders import loadMapFile -ActorStates = {'IDLE':0, +from scripts.objects.baseobject import ObjectActionListener, BaseGameObject + +ActorStates = {'STAND':0, 'WALK':1, 'ATTACK':2} -class Actor(object): +class ActorActionListener(ObjectActionListener): + def __init__(self, gamecontroller, obj): + super(ActorActionListener, self).__init__(gamecontroller, obj) + + def onInstanceActionFinished(self, instance, action): + if action.getId() == 'walk': + self._object.stand() + +class Actor(BaseGameObject): 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 + super(Actor, self).__init__(gamecontroller, instancename, instanceid, createInstance) + + self._walkspeed = self._gamecontroller.settings.get("RPG", "DefaultActorWalkSpeed", 4.0) + + self._actionlistener = ActorActionListener(self._gamecontroller, self) - if createInstance: - self._createFIFEInstance() - else: - 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"] + self.stand() + + def stand(self): + self._state = ActorStates["STAND"] + self._instance.act('stand', self._instance.getFacingLocation()) - 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 walk(self, location): self._state = ActorStates["WALK"] self._instance.move('walk', location, self._walkspeed) - - 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")) + + def _getState(self): + return self._state - 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) + def _setState(self, state): + self._state = state + + state = property(_getState, _setState) diff -r d70fc46c8aa5 -r c3a026cdd91b demos/rpg/scripts/gamecontroller.py --- a/demos/rpg/scripts/gamecontroller.py Tue May 25 21:41:59 2010 +0000 +++ b/demos/rpg/scripts/gamecontroller.py Wed May 26 15:28:25 2010 +0000 @@ -28,9 +28,12 @@ from fife import fife +from fife.extensions.soundmanager import SoundManager +from fife.extensions.loaders import loadImportFile + from scripts.scene import Scene from scripts.guicontroller import GUIController -from fife.extensions.loaders import loadImportFile + class KeyState(object): def __init__(self): @@ -54,6 +57,7 @@ self._gamecontroller = gamecontroller self._settings = gamecontroller.settings self._eventmanager = self._engine.getEventManager() + self._soundmanager = SoundManager(self._engine) fife.IMouseListener.__init__(self) fife.IKeyListener.__init__(self) @@ -101,24 +105,29 @@ return pt = fife.ScreenPoint(event.getX(), event.getY()) - instances = self.getInstancesAt(pt); + instances = self._gamecontroller.scene.getInstancesAt(pt); + for i in instances: renderer.addOutlined(i, 173, 255, 47, 2) def mouseEntered(self, event): pass + def mouseExited(self, event): pass + def mouseClicked(self, event): pass + def mouseWheelMovedUp(self, event): pass + def mouseWheelMovedDown(self, event): pass - def mouseMoved(self, event): - pass + def mouseDragged(self, event): pass + def keyPressed(self, event): keyval = event.getKey().getValue() keystr = event.getKey().getAsString().lower() diff -r d70fc46c8aa5 -r c3a026cdd91b demos/rpg/scripts/objects/__init__.py diff -r d70fc46c8aa5 -r c3a026cdd91b demos/rpg/scripts/objects/baseobject.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demos/rpg/scripts/objects/baseobject.py Wed May 26 15:28:25 2010 +0000 @@ -0,0 +1,100 @@ +#!/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 ObjectActionListener(fife.InstanceActionListener): + def __init__(self, gamecontroller, obj): + fife.InstanceActionListener.__init__(self) + obj.instance.addActionListener(self) + self._gamecontroller = gamecontroller + self._object = obj + + def onInstanceActionFinished(self, instance, action): + pass + + +class BaseGameObject(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() + else: + self._instance = self._gamecontroller.scene.actorlayer.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) + + def _getInstance(self): + return self._instance + + location = property(_getLocation, _setLocation) + instance = property(_getInstance)