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
13 # create a vertical container
14 c
= pudding
.container
.VerticalContainer(soya
.root_widget
, left
=10, top
=10, width
=100, height
=100)
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
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
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)
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
)
89 box2
= b
.PhysicsBody(mesh
=box_mesh
)
90 box2
.set_xyz(-1.5,0,-8)
96 box3
= b
.PhysicsBody(mesh
=box_mesh
)
97 box3
.set_xyz(-1,0,-10)
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
))
113 impact
, normal
= result
114 body_selected
= impact
.parent
115 body_selected
.model
= box_mesh2
120 w
.begin_loop(callbackround
=game_logic
,engine
="pudding")