comparison clients/rio_de_hola/scripts/cloud.py @ 0:4a0efb7baf70

* Datasets becomes the new trunk and retires after that :-)
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 29 Jun 2008 18:44:17 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4a0efb7baf70
1 from agent import Agent
2 import settings as TDS
3 import fife
4 import random
5
6 _STATE_NONE, _STATE_FLOATING, _STATE_DISAPPEAR, _STATE_APPEAR = 0, 1, 2, 3
7
8 class Cloud(Agent):
9 def __init__(self, model, agentName, layer, uniqInMap=False):
10 super(Cloud, self).__init__(model, agentName, layer, uniqInMap)
11 self.state = _STATE_NONE
12
13 def isOutOfBounds(self, c):
14 return (c.x < 0) or (c.x > 100) or (c.y < 0) or (c.y > 100)
15
16 def onInstanceActionFinished(self, instance, action):
17 if self.state == _STATE_APPEAR:
18 self.move()
19 elif self.state == _STATE_FLOATING:
20 c = self.agent.getLocationRef().getExactLayerCoordinatesRef()
21 c.x += self.x_dir
22 c.y += self.y_dir
23 if self.isOutOfBounds(c):
24 self.disappear()
25 else:
26 self.move()
27 elif self.state == _STATE_DISAPPEAR:
28 self.agent.getLocationRef().setExactLayerCoordinates(self.initialCoords)
29 self.appear()
30
31 def start(self, x_dir, y_dir):
32 self.x_dir = x_dir
33 self.y_dir = y_dir
34 self.loc = self.agent.getLocation()
35 self.initialCoords = self.agent.getLocation().getExactLayerCoordinates()
36 self.appear()
37
38 def appear(self):
39 self.state = _STATE_APPEAR
40 self.agent.act('appear', self.loc, False)
41
42 def disappear(self):
43 self.state = _STATE_DISAPPEAR
44 self.agent.act('disappear', self.loc, False)
45
46 def move(self):
47 self.state = _STATE_FLOATING
48 self.agent.act('default', self.loc, False)
49