comparison tests/swig_tests/action_tests.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 d2f1e81fbe2c
comparison
equal deleted inserted replaced
-1:000000000000 0:4a0efb7baf70
1 #!/usr/bin/env python
2 from swig_test_utils import *
3 import pythonize
4 from serializers.xmlanimation import XMLAnimationLoader
5
6 class ActionTests(unittest.TestCase):
7 def setUp(self):
8 template = 'tests/data/wolf_walk/wolf_walk_%s.xml'
9 dirnames = ['e', 'ne', 'n', 'nw', 'w', 'sw', 's', 'se']
10 files = map(lambda dirname: template % dirname, dirnames)
11
12 self.engine = getEngine()
13 pool = self.engine.getAnimationPool()
14 self.animationloader = XMLAnimationLoader(self.engine.getImagePool(), self.engine.getVFS())
15 pool.addResourceLoader(self.animationloader)
16
17 _map = self.engine.getModel().createMap("map001")
18
19 self.grid = fife.SquareGrid(True)
20 self.layer = _map.createLayer("Layer001", self.grid)
21
22 self.target = fife.Location(self.layer)
23
24 self.obj = fife.Object("object001", 'plaa')
25 fife.ObjectVisual.create(self.obj)
26 self.pather = fife.LinearPather()
27 self.obj.setPather(self.pather)
28 self.action = self.obj.createAction('walk')
29 fife.ActionVisual.create(self.action)
30 addResource = self.engine.animationPool.addResourceFromFile
31 for index, direction in enumerate(dirnames):
32 degree = 45 * index
33 self.action.get2dGfxVisual().addAnimation(degree, addResource(files[index]))
34
35 self.ground = fife.Object("ground", 'plaa')
36 imgid = self.engine.imagePool.addResourceFromFile('tests/data/earth_1.png')
37 fife.ObjectVisual.create(self.ground)
38 self.ground.get2dGfxVisual().addStaticImage(0, imgid)
39 self.ground.img = self.engine.getImagePool().getImage(imgid)
40 for y in xrange(-2,3):
41 for x in xrange(-2,3):
42 inst = self.layer.createInstance(self.ground, fife.ModelCoordinate(x,y))
43 fife.InstanceVisual.create(inst)
44 self.inst = self.layer.createInstance(self.obj, fife.ModelCoordinate(-2,-2))
45 fife.InstanceVisual.create(self.inst)
46
47 def tearDown(self):
48 del self.engine
49
50 def _testWalkingAction(self):
51 print 'test1'
52 getAnimation = self.engine.animationPool.getAnimation
53 print 'test2'
54 self.inst.move('walk', self.target, 0.05)
55 self.engine.initializePumping()
56 backend = self.engine.renderBackend
57 for i in xrange(360):
58 self.inst.getLocation().getLayerCoordinates()
59 self.target.getLayerCoordinates()
60 if self.inst.getLocation().getLayerCoordinates() == self.target.getLayerCoordinates():
61 break
62 self.inst.update()
63 action = self.inst.currentAction
64 angle = 0 #self.inst.orientation
65 animation = getAnimation( action.getAnimationIndexByAngle(angle) )
66 timestamp = self.inst.actionRuntime % animation.duration
67 image = animation.getFrameByTimestamp( timestamp )
68 if image:
69 image.render(fife.Rect(0,0,image.width,image.height),255)
70 self.engine.pump()
71 self.engine.finalizePumping()
72
73 def testWalkAround(self):
74
75 rb = self.engine.getRenderBackend()
76 viewport = fife.Rect(0, 0, rb.getWidth(), rb.getHeight())
77
78 cam = self.engine.getView().addCamera("foo", self.layer, viewport, fife.ExactModelCoordinate(0,0) )
79 cam.setCellImageDimensions(self.ground.img.getWidth(), self.ground.img.getHeight())
80 cam.setRotation(45)
81 cam.setTilt(40)
82
83 self.engine.getView().resetRenderers()
84 self.engine.initializePumping()
85 self.target.setLayerCoordinates(fife.ModelCoordinate(2,-2))
86 self.inst.move('walk', self.target, 0.9)
87 targets = (
88 (2,0), (2,-1), (2,-2), (1,-2),
89 (0,-2), (-1,-2), (-2,-2), (-2,-1),
90 (-2,0), (-2,1), (-2,2), (-1,2),
91 (0,2), (1,2), (2,2), (2,1))
92 for target in targets:
93 l = self.inst.getLocation()
94 l.setLayerCoordinates(fife.ModelCoordinate(0,0))
95 self.inst.setLocation(l)
96 self.target.setLayerCoordinates(fife.ModelCoordinate(*target))
97 self.inst.move('walk', self.target, 0.9)
98 for i in xrange(10):
99 self.engine.pump()
100
101 self.engine.finalizePumping()
102 self.engine.getView().removeCamera(cam)
103
104
105
106 TEST_CLASSES = [ActionTests]
107
108 if __name__ == '__main__':
109 unittest.main()