Add import to pyworlds to avoid errors.
[pyworlds.git] / tests / basic-5.py
blob70bf7d88c7c67da2b7acdbbb911d33d6bc6beca4
1 #!/usr/bin/python
2 import sys,os
3 sys.path.insert(0, os.path.abspath(os.path.join(os.getcwd(), '..', 'src')))
5 import pyworlds.worlds as w
6 from pyworlds.basics.body import *
7 import soya
9 w.init()
11 head = PhysicsBody(mesh_file="sword")
13 head.rotation[1]=5.0
14 head.speed.z=-0.1
16 new_springfactor = springfactor = 16
18 pieces = {}
19 previous = head
20 for i in range(100):
21 pieces[i] = w.FollowBody("sword",previous)
22 previous = pieces[i]
24 w.camera.set_xyz(0,35,25)
25 w.camera.look_at(head)
27 def mainloop():
28 global head, new_springfactor, springfactor
29 if soya.sdlconst.K_UP in w.KEY:
30 head.speed.z-=1; head.speed.z*=0.99
31 else:
32 head.speed.z/=1.1
33 if soya.sdlconst.K_DOWN in w.KEY:
34 head.speed.z+=0.05;
35 if soya.sdlconst.K_LEFT in w.KEY: head.rotation[1]+=200
36 if soya.sdlconst.K_RIGHT in w.KEY: head.rotation[1]-=200
37 head.rotation[1]/=1.5
39 if soya.sdlconst.K_1 in w.KEY: new_springfactor=0.1
40 if soya.sdlconst.K_2 in w.KEY: new_springfactor=0.2
41 if soya.sdlconst.K_3 in w.KEY: new_springfactor=0.4
42 if soya.sdlconst.K_4 in w.KEY: new_springfactor=0.8
43 if soya.sdlconst.K_5 in w.KEY: new_springfactor=1.6
44 if soya.sdlconst.K_0 in w.KEY: new_springfactor=0
46 if new_springfactor != springfactor:
47 global pieces
48 for i in pieces:
49 pieces[i].set_springfactor(new_springfactor)
51 new_springfactor = springfactor
53 def renderloop(proportion):
54 global head
55 w.camera.look_at(head)
56 pass
62 w.begin_loop(mainloop, renderloop)