Mercurial > parpg-source
diff behaviours/npc.py @ 47:dd9bd93ec81c
Fixed NPC behaviour. NPCs are wandering around again.
author | KarstenBock@gmx.net |
---|---|
date | Wed, 07 Sep 2011 14:48:08 +0200 |
parents | bf506f739322 |
children | 1bdadb768bcf |
line wrap: on
line diff
--- a/behaviours/npc.py Wed Sep 07 13:54:02 2011 +0200 +++ b/behaviours/npc.py Wed Sep 07 14:48:08 2011 +0200 @@ -15,6 +15,8 @@ from random import randrange +from fife import fife + import base from base import BaseBehaviour @@ -43,7 +45,7 @@ @return: NPC's position""" x = self.getX() y = self.getY() - if self.state == _AGENT_STATE_WANDER: + if self.state == base._AGENT_STATE_WANDER: """ Random Target Location """ l = [0, 0] for i in range(len(l)): @@ -69,7 +71,7 @@ @type action: ??? @param action: ??? @return: None""" - if self.state == _AGENT_STATE_WANDER: + if self.state == base._AGENT_STATE_WANDER: self.target_loc = self.getTargetLocation() self.idle() @@ -78,21 +80,28 @@ """Controls the NPC when it is idling. Different actions based on the NPC's state. @return: None""" - if self.state == _AGENT_STATE_NONE: - self.state = _AGENT_STATE_IDLE + if self.state == base._AGENT_STATE_NONE: + self.state = base._AGENT_STATE_IDLE self.agent.act('stand', self.agent.getFacingLocation()) - elif self.state == _AGENT_STATE_IDLE: + elif self.state == base._AGENT_STATE_IDLE: if self.wanderCounter > self.wanderRate: self.wanderCounter = 0 - self.state = _AGENT_STATE_WANDER + self.state = base._AGENT_STATE_WANDER else: self.wanderCounter += 1 - self.state = _AGENT_STATE_NONE + self.state = base._AGENT_STATE_NONE self.target_loc = self.getTargetLocation() self.agent.act('stand', self.agent.getFacingLocation()) - elif self.state == _AGENT_STATE_WANDER: - self.parent.wander(self.target_loc) - self.state = _AGENT_STATE_NONE - elif self.state == _AGENT_STATE_TALK: - self.agent.act('stand', self.pc.getLocation()) \ No newline at end of file + elif self.state == base._AGENT_STATE_WANDER: + self.wander(self.target_loc) + self.state = base._AGENT_STATE_NONE + elif self.state == base._AGENT_STATE_TALK: + self.agent.act('stand', self.pc.getLocation()) + + def wander(self, location): + """Nice slow movement for random walking. + @type location: fife.Location + @param location: Where the NPC will walk to. + @return: None""" + self.agent.move('walk', location, self.speed - 1) \ No newline at end of file