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
11 w
.init_pudding(options
={'nochild' : True})
13 r
= pudding
.container
.HorizontalContainer(soya
.root_widget
, left
=0, top
=0, width
=200, height
=400)
16 r
.anchors
= pudding
.ANCHOR_ALL
18 soya
.root_widget
.add_child(w
.camera
)
20 # this time we just anchor one side
21 c
.anchors
= pudding
.ANCHOR_BOTTOM
23 # create a vertical container
24 c
= pudding
.container
.VerticalContainer(r
, left
=10, top
=10, width
=100, height
=100)
27 # here we' set the anchors. anchors make resizable screen components a doddle
28 # here we anchor all but the bottom to make a sort of title bar
29 c
.anchors
= pudding
.ANCHOR_RIGHT | pudding
.ANCHOR_TOP | pudding
.ANCHOR_LEFT | pudding
.ANCHOR_BOTTOM
32 # the last argument indicates if the object is free to expand with the container
33 d
= c
.add_child(pudding
.control
.Button(label
= 'Button'), 1)
34 # set the background color for show
35 d
.background_color
= (0.3, 0.5, 0.3, 0.5)
37 # add another button but this time specifiy that its not free to grow excpet in the
39 d
= c
.add_child(pudding
.control
.Input(height
= 40, initial
= 'input'), pudding
.EXPAND_HORIZ
)
40 d
.background_color
= (0.8, 0.5, 0.5, 0.5)
42 d
= c
.add_child(pudding
.control
.Button(label
= 'Button'), pudding
.EXPAND_NONE
)
43 d
.background_color
= (0.5, 0.6, 0.8, 0.5)
44 d
= c
.add_child(pudding
.control
.Button(width
= 20,height
= 20, label
= ''))
45 d
.background_color
= (0.9, 0.6, 0.8, 0.5)
52 material
= soya
.Material()
53 material
.shininess
= 0.5
54 material
.diffuse
= (0.1, 0.2, 0.5, 1.0)
55 material
.specular
= (0.2, 0.3, 0.6, 1.0)
57 material2
= soya
.Material()
58 material2
.shininess
= 0.5
59 material2
.diffuse
= (0.7,0.0, 0.2, 1.0)
60 material2
.specular
= (1.0,0.2, 0.7, 1.0)
62 shader
= soya
.Material()
63 shader
.texture
= soya
.Image
.get("shader.png")
67 cellshading
= soya
.CellShadingModelBuilder()
69 cellshading
.shader
= shader
70 cellshading
.outline_color
= (0.0, 0.0, 0.0, 0.5)
71 cellshading
.outline_width
= 7.0
72 cellshading
.outline_attenuation
= 2.0
74 box_model
= soya
.World(None)
75 w
.Box(1,1,1,material
=material
,insert_into
=box_model
)
76 box_model
.model_builder
= cellshading
77 box_mesh
= box_model
.to_model()
79 box_model2
= soya
.World(None)
80 w
.Box(1,1,1,material
=material2
,insert_into
=box_model2
)
81 box_model2
.model_builder
= cellshading
82 box_mesh2
= box_model2
.to_model()
85 box1
= b
.PhysicsBody(mesh
=box_mesh
)
91 box2
= b
.PhysicsBody(mesh
=box_mesh
)
92 box2
.set_xyz(-1.5,0,-8)
98 box3
= b
.PhysicsBody(mesh
=box_mesh
)
99 box3
.set_xyz(-1,0,-10)
107 if 1 in w
.MOUSE_BUTTON
:
108 button
= w
.MOUSE_BUTTON
[1]
109 box1
.model
= box_mesh
110 box2
.model
= box_mesh
111 box3
.model
= box_mesh
112 mouse
= w
.camera
.coord2d_to_3d(w
.MOUSE_X
, w
.MOUSE_Y
,-3)
113 result
= w
.scene
.raypick(w
.camera
, w
.camera
.vector_to(mouse
))
115 impact
, normal
= result
116 body_selected
= impact
.parent
117 body_selected
.model
= box_mesh2
119 def before_render(proportion
):
120 w
.camera
.width
= w
.camera
.get_screen_width() / 2
121 w
.camera
.left
= w
.camera
.get_screen_width() / 2
125 w
.begin_loop(callbackround
=game_logic
,callbackadvance
=before_render
, engine
="pudding")