comparison demos/rio_de_hola/scripts/agents/hero.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 import random
2 from agent import Agent
3 from settings import Setting
4
5 TDS = Setting()
6
7 _STATE_NONE, _STATE_IDLE, _STATE_RUN, _STATE_KICK, _STATE_TALK = xrange(5)
8
9 class Hero(Agent):
10 def __init__(self, model, agentName, layer, uniqInMap=True):
11 super(Hero, self).__init__(model, agentName, layer, uniqInMap)
12 self.state = _STATE_NONE
13 self.idlecounter = 1
14
15 def onInstanceActionFinished(self, instance, action):
16 self.idle()
17 if action.getId() != 'stand':
18 self.idlecounter = 1
19 else:
20 self.idlecounter += 1
21 if self.idlecounter % 7 == 0:
22 heroTexts = TDS.readSetting("heroTexts", type='list', text=True)
23 txtindex = random.randint(0, len(heroTexts) - 1)
24 instance.say(heroTexts[txtindex], 2500)
25
26 def start(self):
27 self.idle()
28
29 def idle(self):
30 self.state = _STATE_IDLE
31 self.agent.act('stand', self.agent.getFacingLocation())
32
33 def run(self, location):
34 self.state = _STATE_RUN
35 self.agent.move('run', location, 4 * float(TDS.readSetting("TestAgentSpeed")))
36
37 def kick(self, target):
38 self.state = _STATE_KICK
39 self.agent.act('kick', target)
40
41 def talk(self, target):
42 self.state = _STATE_TALK
43 self.agent.act('talk', target)