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 pyworlds
.basics
.wbody
as wb
8 import soya
.sdlconst
as c
13 diffuse1
=[0.0, 0.3, 0.8, 1.00]
15 w
.scene
.atmosphere
= soya
.Atmosphere()
16 w
.scene
.atmosphere
.bg_color
= (1.0, 1.0, 1.0, 1.0)
18 material
= soya
.Material()
19 # Cellshaded materials in soya MUST have a texture.
20 material
.texture
= soya
.Image
.get("snow.png")
21 material
.shininess
= 0.5
22 material
.diffuse
= tuple(diffuse1
)
23 material
.specular
= (0.2, 0.3, 0.6, 1.0)
25 material2
= soya
.Material()
26 material2
.texture
= soya
.Image
.get("snow.png")
27 material2
.shininess
= 18
28 material2
.diffuse
= (0.8,0.4, 0.0, 1.0)
29 material2
.specular
= (0.3,0.0, 0.0, 1.0)
33 shader
= soya
.Material()
34 shader
.texture
= soya
.Image
.get("shader3.png")
36 cellshading
= soya
.CellShadingModelBuilder()
38 cellshading
.shader
= shader
39 cellshading
.outline_color
= (0.0, 0.0, 0.0, 0.5)
40 cellshading
.outline_width
= 5.0
41 cellshading
.outline_attenuation
= 1.0
45 light2
= soya
.Light(w
.scene
)
46 light2
.set_xyz(22.0, 15.0, 0.0)
48 light3
= soya
.Light(w
.scene
)
49 light3
.set_xyz(-22.0, -20.0, 15.0)
51 box_model
= soya
.World(None)
52 box_model
.model_builder
= cellshading
53 w
.Box(1,1,1,material
=material
,insert_into
=box_model
)
54 box_mesh
= box_model
.to_model()
56 box_model1
= soya
.World(None)
57 box_model1
.model_builder
= cellshading
58 w
.Box(1,1,1,material
=material
,insert_into
=box_model1
)
59 box_mesh1
= box_model1
.to_model()
63 box_model2
= soya
.World(None)
64 box_model2
.model_builder
= cellshading
65 w
.Box(1,1,1,material
=material2
,insert_into
=box_model2
)
66 box_mesh2
= box_model2
.to_model()
69 box1
= wb
.wPhysicsBody(mesh
=box_mesh
)
76 box2
= wb
.wPhysicsBody(mesh
=box_mesh
)
77 box2
.set_xyz(-1.5,0,-8)
83 box3
= wb
.wPhysicsBody(mesh
=box_mesh
)
84 box3
.set_xyz(-1,0,-10)
89 box4
= wb
.wPhysicsBody(mesh
=box_mesh
)
99 label1
= wb
.wLabel3DFlat(follows
= box1
, text
= "Pabellon 1")
101 label2
= wb
.wLabel3DFlat(follows
= box2
, text
= "Pabellon 2")
103 label3
= wb
.wLabel3DFlat(follows
= box3
, text
= "Pabellon 3")
105 label4
= wb
.wLabel3DFlat(follows
= box4
, text
= "Pabellon 4")
107 #cursor = b.PhysicsBody(mesh=box_mesh2, parent=box1)
112 if c
.K_a
in w
.KEY
: w
.camera
.rotate_y(1)
113 if c
.K_s
in w
.KEY
: w
.camera
.rotate_y(-1)
115 if c
.K_LEFT
in w
.KEY
: w
.camera
.add_xyz(-.1,0,0)
116 if c
.K_RIGHT
in w
.KEY
: w
.camera
.add_xyz(.1,0,0)
117 if c
.K_UP
in w
.KEY
: w
.camera
.add_xyz(0,.1,0)
118 if c
.K_DOWN
in w
.KEY
: w
.camera
.add_xyz(0,-.1,0)
119 if c
.K_RSHIFT
in w
.KEY
: w
.camera
.add_xyz(0,0,.1)
120 if c
.K_RCTRL
in w
.KEY
: w
.camera
.add_xyz(0,0,-.1)
122 if 1 in w
.MOUSE_BUTTON
:
123 button
= w
.MOUSE_BUTTON
[1]
124 box1
.model
= box_mesh1
125 box2
.model
= box_mesh1
126 box3
.model
= box_mesh1
127 box4
.model
= box_mesh1
128 mouse
= w
.camera
.coord2d_to_3d(w
.MOUSE_X
, w
.MOUSE_Y
,-3)
129 result
= w
.scene
.raypick(w
.camera
, w
.camera
.vector_to(mouse
))
131 impact
, normal
= result
132 body_selected
= impact
.parent
134 if body_selected
.model
== box_mesh1
:
135 body_selected
.model
= box_mesh2
142 def render_frame(proportion
):
143 global rounds
, material
146 rounds
+= proportion
/ 100.0
148 diffuse1
[0]=math
.sin(rounds
/10)/2+0.49
149 diffuse1
[1]=math
.sin(rounds
/3)/2+0.49
150 diffuse1
[2]=math
.sin(rounds
)/2+0.49
151 material
.diffuse
= tuple(diffuse1
)
153 diffuse2
[0]=math
.sin(rounds
/10)/2+0.39
154 diffuse2
[1]=math
.sin(rounds
/6)/2+0.39
155 diffuse2
[2]=math
.sin(rounds
/2)/2+0.39
156 material2
.diffuse
= tuple(diffuse2
)
159 w
.begin_loop(callbackround
=game_logic
, callbackadvance
=render_frame
)