Mercurial > parpg-source
changeset 46:bf506f739322
Removed layer as attribute of BaseBehaviour and added it as a parameter to the attachToLayer method.
author | KarstenBock@gmx.net |
---|---|
date | Wed, 07 Sep 2011 13:54:02 +0200 |
parents | b8f421f74280 |
children | dd9bd93ec81c |
files | behaviours/base.py behaviours/npc.py behaviours/player.py components/fifeagent.py gamemodel.py |
diffstat | 5 files changed, 16 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/behaviours/base.py Wed Sep 07 13:24:02 2011 +0200 +++ b/behaviours/base.py Wed Sep 07 13:54:02 2011 +0200 @@ -19,20 +19,21 @@ class BaseBehaviour (fife.InstanceActionListener): """Fife agent listener""" - def __init__(self, layer=None): + def __init__(self): fife.InstanceActionListener.__init__(self) - self.layer = layer self.agent = None self.state = None self.speed = 0 self.idle_counter = 1 - def attachToLayer(self, agent_ID): + def attachToLayer(self, agent_ID, layer): """Attaches to a certain layer @type agent_ID: String @param agent_ID: ID of the layer to attach to. + @type layer: Fife layer + @param layer: Layer of the agent to attach the behaviour to @return: None""" - self.agent = self.layer.getInstance(agent_ID) + self.agent = layer.getInstance(agent_ID) self.agent.addActionListener(self) self.state = _AGENT_STATE_NONE
--- a/behaviours/npc.py Wed Sep 07 13:24:02 2011 +0200 +++ b/behaviours/npc.py Wed Sep 07 13:54:02 2011 +0200 @@ -20,8 +20,8 @@ class NPCBehaviour(BaseBehaviour): """This is a basic NPC behaviour""" - def __init__(self, parent=None, layer=None): - super(NPCBehaviour, self).__init__(layer) + def __init__(self, parent=None): + super(NPCBehaviour, self).__init__() self.parent = parent self.state = base._AGENT_STATE_NONE
--- a/behaviours/player.py Wed Sep 07 13:24:02 2011 +0200 +++ b/behaviours/player.py Wed Sep 07 13:54:02 2011 +0200 @@ -17,8 +17,8 @@ from base import BaseBehaviour class PlayerBehaviour (BaseBehaviour): - def __init__(self, parent=None, layer=None): - super(PlayerBehaviour, self).__init__(layer) + def __init__(self, parent=None): + super(PlayerBehaviour, self).__init__() self.parent = parent self.idle_counter = 1 self.speed = 0
--- a/components/fifeagent.py Wed Sep 07 13:24:02 2011 +0200 +++ b/components/fifeagent.py Wed Sep 07 13:54:02 2011 +0200 @@ -24,5 +24,5 @@ def setup_behaviour(agent): """Attach the behaviour to the layer""" - if agent.behaviour: - agent.behaviour.attachToLayer(agent.identifier) \ No newline at end of file + if agent.behaviour: + agent.behaviour.attachToLayer(agent.identifier, agent.layer) \ No newline at end of file
--- a/gamemodel.py Wed Sep 07 13:24:02 2011 +0200 +++ b/gamemodel.py Wed Sep 07 13:54:02 2011 +0200 @@ -31,6 +31,7 @@ from parpg.dialogueparsers import YamlDialogueParser, DialogueFormatError from parpg.entities import createEntity from parpg import behaviours +from parpg.components import fifeagent try: import xml.etree.cElementTree as ElementTree @@ -677,6 +678,10 @@ if obj_type == "Character": obj.fifeagent.behaviour.parent = obj + fifeagent.setup_behaviour(obj.fifeagent) + obj.fifeagent.behaviour.speed = self.settings.parpg.PCSpeed + #Start the behaviour + obj.fifeagent.behaviour.idle() # create the agent #obj.setup() #obj.behaviour.speed = self.settings.parpg.PCSpeed