Add import to pyworlds to avoid errors.
[pyworlds.git] / tests / pudding-1.py
blob3f78b7a0454d0c47b1088305446eaa9638ce7788
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 import pyworlds.basics.body as b
7 import soya.sdlconst as c
8 import soya.pudding as pudding
9 import soya
11 w.init_pudding()
13 # create a vertical container
14 c = pudding.container.VerticalContainer(soya.root_widget, left=10, top=10, width=100, height=100)
15 c.right = 10
17 # here we' set the anchors. anchors make resizable screen components a doddle
18 # here we anchor all but the bottom to make a sort of title bar
19 c.anchors = pudding.ANCHOR_RIGHT | pudding.ANCHOR_TOP | pudding.ANCHOR_LEFT
21 # add a button
22 # the last argument indicates if the object is free to expand with the container
23 d = c.add_child(pudding.control.Button(label = 'Button'), 1)
24 # set the background color for show
25 d.background_color = (0.3, 0.5, 0.3, 0.5)
27 # add another button but this time specifiy that its not free to grow excpet in the
28 # horizontal
29 d = c.add_child(pudding.control.Input(height = 40, initial = 'input'), pudding.EXPAND_HORIZ)
30 d.background_color = (0.8, 0.5, 0.5, 0.5)
32 # add another container
33 # this time with one exapanding button and one button that doesnt expand at all
34 c = pudding.container.HorizontalContainer(soya.root_widget, left=10, top=210, width=100, height=100)
35 c.bottom = 10
37 # this time we just anchor one side
38 c.anchors = pudding.ANCHOR_BOTTOM
40 d = c.add_child(pudding.control.Button(label = 'Button'), pudding.EXPAND_NONE)
41 d.background_color = (1.0, 0.0, 0.0, 0.5)
42 d = c.add_child(pudding.control.Button(width = 20,height = 20, label = ''))
43 d.background_color = (0.0, 1.0, 0.0, 0.5)
50 material = soya.Material()
51 material.shininess = 0.5
52 material.diffuse = (0.1, 0.2, 0.5, 1.0)
53 material.specular = (0.2, 0.3, 0.6, 1.0)
55 material2 = soya.Material()
56 material2.shininess = 0.5
57 material2.diffuse = (0.7,0.0, 0.2, 1.0)
58 material2.specular = (1.0,0.2, 0.7, 1.0)
60 shader = soya.Material()
61 shader.texture = soya.Image.get("shader.png")
65 cellshading = soya.CellShadingModelBuilder()
67 cellshading.shader = shader
68 cellshading.outline_color = (0.0, 0.0, 0.0, 0.5)
69 cellshading.outline_width = 7.0
70 cellshading.outline_attenuation = 2.0
72 box_model = soya.World(None)
73 w.Box(1,1,1,material=material,insert_into=box_model)
74 box_model.model_builder = cellshading
75 box_mesh = box_model.to_model()
77 box_model2 = soya.World(None)
78 w.Box(1,1,1,material=material2,insert_into=box_model2)
79 box_model2.model_builder = cellshading
80 box_mesh2 = box_model2.to_model()
83 box1 = b.PhysicsBody(mesh=box_mesh)
84 box1.set_xyz(-2,0,-5)
85 box1.rotate_x(40)
86 box1.rotation[2]=20
87 box1.speed.y=-1
89 box2 = b.PhysicsBody(mesh=box_mesh)
90 box2.set_xyz(-1.5,0,-8)
91 box2.rotate_x(30)
92 box2.rotation[2]=50
93 box2.speed.y=-1
96 box3 = b.PhysicsBody(mesh=box_mesh)
97 box3.set_xyz(-1,0,-10)
98 box3.rotate_x(50)
99 box3.rotation[2]=30
100 box3.speed.y=-0.6
104 def game_logic():
105 if 1 in w.MOUSE_BUTTON:
106 button = w.MOUSE_BUTTON[1]
107 box1.model = box_mesh
108 box2.model = box_mesh
109 box3.model = box_mesh
110 mouse = w.camera.coord2d_to_3d(w.MOUSE_X, w.MOUSE_Y,-3)
111 result = w.scene.raypick(w.camera, w.camera.vector_to(mouse))
112 if result:
113 impact, normal = result
114 body_selected = impact.parent
115 body_selected.model = box_mesh2
120 w.begin_loop(callbackround=game_logic,engine="pudding")