Mercurial > fife-parpg
comparison demos/rio_de_hola/scripts/agents/cloud.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 import random | |
4 | |
5 _STATE_NONE, _STATE_FLOATING, _STATE_DISAPPEAR, _STATE_APPEAR = 0, 1, 2, 3 | |
6 | |
7 class Cloud(Agent): | |
8 def __init__(self, model, agentName, layer, uniqInMap=False): | |
9 super(Cloud, self).__init__(model, agentName, layer, uniqInMap) | |
10 self.state = _STATE_NONE | |
11 | |
12 def isOutOfBounds(self, c): | |
13 return (c.x < 0) or (c.x > 100) or (c.y < 0) or (c.y > 100) | |
14 | |
15 def onInstanceActionFinished(self, instance, action): | |
16 if self.state == _STATE_APPEAR: | |
17 self.move() | |
18 elif self.state == _STATE_FLOATING: | |
19 c = self.agent.getLocationRef().getExactLayerCoordinatesRef() | |
20 c.x += self.x_dir | |
21 c.y += self.y_dir | |
22 if self.isOutOfBounds(c): | |
23 self.disappear() | |
24 else: | |
25 self.move() | |
26 elif self.state == _STATE_DISAPPEAR: | |
27 self.agent.getLocationRef().setExactLayerCoordinates(self.initialCoords) | |
28 self.appear() | |
29 | |
30 def start(self, x_dir, y_dir): | |
31 self.x_dir = x_dir | |
32 self.y_dir = y_dir | |
33 self.loc = self.agent.getLocation() | |
34 self.initialCoords = self.agent.getLocation().getExactLayerCoordinates() | |
35 self.appear() | |
36 | |
37 def appear(self): | |
38 self.state = _STATE_APPEAR | |
39 self.agent.act('appear', self.loc, False) | |
40 | |
41 def disappear(self): | |
42 self.state = _STATE_DISAPPEAR | |
43 self.agent.act('disappear', self.loc, False) | |
44 | |
45 def move(self): | |
46 self.state = _STATE_FLOATING | |
47 self.agent.act('default', self.loc, False) |