Mercurial > fife-parpg
comparison clients/rio_de_hola/scripts/agents/girl.py @ 98:214e3eb81eb2
better structure for techdemo scripts + svn:ignore fixes
author | jasoka@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 21 Jul 2008 13:46:15 +0000 |
parents | clients/rio_de_hola/scripts/girl.py@4a0efb7baf70 |
children | ae3b8139c7c7 |
comparison
equal
deleted
inserted
replaced
97:346738d09188 | 98:214e3eb81eb2 |
---|---|
1 from agent import Agent | |
2 import settings as TDS | |
3 import fife | |
4 | |
5 _STATE_NONE, _STATE_IDLE, _STATE_RUN, _STATE_FOLLOW = 0, 1, 2, 3 | |
6 | |
7 GIRL_SPEED = 3 * TDS.TestAgentSpeed | |
8 class Girl(Agent): | |
9 def __init__(self, model, agentName, layer, uniqInMap=True): | |
10 super(Girl, self).__init__(model, agentName, layer, uniqInMap) | |
11 self.state = _STATE_NONE | |
12 self.waypoints = ((67, 80), (75, 44)) | |
13 self.waypoint_counter = 0 | |
14 self.hero = self.layer.getInstance('PC') | |
15 | |
16 def onInstanceActionFinished(self, instance, action): | |
17 if self.state in (_STATE_RUN, _STATE_FOLLOW): | |
18 self.idle() | |
19 else: | |
20 if self.waypoint_counter % 3: | |
21 self.waypoint_counter += 1 | |
22 self.follow_hero() | |
23 else: | |
24 self.run(self.getNextWaypoint()) | |
25 | |
26 def getNextWaypoint(self): | |
27 self.waypoint_counter += 1 | |
28 l = fife.Location(self.layer) | |
29 l.setLayerCoordinates(fife.ModelCoordinate(*self.waypoints[self.waypoint_counter % len(self.waypoints)])) | |
30 return l | |
31 | |
32 def start(self): | |
33 self.follow_hero() | |
34 | |
35 def idle(self): | |
36 self.state = _STATE_IDLE | |
37 self.agent.act('stand', self.agent.getFacingLocation(), False) | |
38 | |
39 def follow_hero(self): | |
40 self.state = _STATE_FOLLOW | |
41 self.agent.follow('run', self.hero, GIRL_SPEED) | |
42 | |
43 def run(self, location): | |
44 self.state = _STATE_RUN | |
45 self.agent.move('run', location, GIRL_SPEED) | |
46 |