Mercurial > fife-parpg
comparison demos/rio_de_hola/scripts/agents/girl.py @ 378:64738befdf3b
bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
author | vtchill@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 11 Jan 2010 23:34:52 +0000 |
parents | |
children | 70697641fca3 |
comparison
equal
deleted
inserted
replaced
377:fe6fb0e0ed23 | 378:64738befdf3b |
---|---|
1 from agent import Agent | |
2 from fife import fife | |
3 from settings import Setting | |
4 | |
5 TDS = Setting() | |
6 | |
7 _STATE_NONE, _STATE_IDLE, _STATE_RUN, _STATE_FOLLOW = 0, 1, 2, 3 | |
8 | |
9 GIRL_SPEED = 3 * float(TDS.readSetting("TestAgentSpeed")) | |
10 class Girl(Agent): | |
11 def __init__(self, model, agentName, layer, uniqInMap=True): | |
12 super(Girl, self).__init__(model, agentName, layer, uniqInMap) | |
13 self.state = _STATE_NONE | |
14 self.waypoints = ((67, 80), (75, 44)) | |
15 self.waypoint_counter = 0 | |
16 self.hero = self.layer.getInstance('PC') | |
17 | |
18 def onInstanceActionFinished(self, instance, action): | |
19 if self.state in (_STATE_RUN, _STATE_FOLLOW): | |
20 self.idle() | |
21 else: | |
22 if self.waypoint_counter % 3: | |
23 self.waypoint_counter += 1 | |
24 self.follow_hero() | |
25 else: | |
26 self.run(self.getNextWaypoint()) | |
27 | |
28 def getNextWaypoint(self): | |
29 self.waypoint_counter += 1 | |
30 l = fife.Location(self.layer) | |
31 l.setLayerCoordinates(fife.ModelCoordinate(*self.waypoints[self.waypoint_counter % len(self.waypoints)])) | |
32 return l | |
33 | |
34 def start(self): | |
35 self.follow_hero() | |
36 | |
37 def idle(self): | |
38 self.state = _STATE_IDLE | |
39 self.agent.act('stand', self.agent.getFacingLocation(), False) | |
40 | |
41 def follow_hero(self): | |
42 self.state = _STATE_FOLLOW | |
43 self.agent.follow('run', self.hero, GIRL_SPEED) | |
44 | |
45 def run(self, location): | |
46 self.state = _STATE_RUN | |
47 self.agent.move('run', location, GIRL_SPEED) |