3 sys
.path
.insert(0, os
.path
.abspath(os
.path
.join(os
.getcwd(), '..', 'src')))
5 import pyworlds
.worlds
as worlds
6 from pyworlds
.worlds
import sdlconst
,soya
7 import soya
.widget
as widget
13 class Level(soya
.World
):
15 Level is a subclass of soya.World.
16 According to the game you are working on, you'll probably want to add
17 attributes and methods to the level class."""
20 """This function creates and saves the game skeleton demo level."""
22 # Create a level object
25 # Separates static and non static parts
26 # This will speed up network games, since only the non static part will be
28 level_static
= soya
.World(level
)
30 # Load 3 materials (= textures) for files ./materials{grass|ground|snow}.data
31 grass
= soya
.Material
.get("grass")
32 ground
= soya
.Material
.get("ground")
33 snow
= soya
.Material
.get("snow")
35 # Creates a terrain, from the heighmap "./images/map.png"
36 # The terrain is in the static part (=level_static), because it won't change along the game.
37 terrain
= soya
.Terrain(level_static
)
39 terrain
.from_image(soya
.Image
.get("map_hfields2.jpg"))
41 # Sets how high is the terrain
42 terrain
.multiply_height(200.0)
44 # These values are trade of between quality and speed
45 terrain
.scale_factor
= 3
46 terrain
.texture_factor
= 0.05
48 # Set the texture on the terrain, according to the height
49 # (i.e. height 0.0 to 15.0 are textured with grass, ...)
50 terrain
.set_material_layer(grass
, 0.0, 50.0)
51 terrain
.set_material_layer(ground
, 40.0, 90.0)
52 terrain
.set_material_layer(snow
, 80.0, 200.0)
54 # Loads the model "./models/ferme.data"
55 # This model has been created in Blender
57 o_scene
= worlds
.scene
58 worlds
.scene
= level_static
59 # Adds 2 houses in the level
61 house1
= worlds
.Body("ferme")
62 house1
.set_xyz(250.0, -7.2, 182.0)
63 house1
.velocity
.z
= -0.1
64 house1
.rotation
[1] = -1
67 house2
= worlds
.Body("ferme")
68 house2
.set_xyz(216.0, -11.25, 200.0)
69 house2
.rotate_y(100.0) # degrees
71 # Creates a light in the level, similar to a sun (=a directional light)
72 sun
= soya
.Light(level_static
)
74 sun
.diffuse
= (1.0, 0.8, 0.4, 1.0)
77 # Creates a sky atmosphere, with fog
78 atmosphere
= soya
.SkyAtmosphere()
79 atmosphere
.ambient
= (0.3, 0.3, 0.4, 1.0)
81 atmosphere
.fog_type
= 0
82 atmosphere
.fog_start
= 50.0
83 atmosphere
.fog_end
= 500.0
84 atmosphere
.fog_color
= atmosphere
.bg_color
= (0.2, 0.5, 0.7, 1.0)
85 atmosphere
.skyplane
= 1
86 atmosphere
.sky_color
= (1.5, 1.0, 0.8, 1.0)
88 # Set the atmosphere to the level
89 level
.atmosphere
= atmosphere
91 # Save the level as "./worlds/level_demo.data" (remember, levels are subclasses of worlds)
92 level_static
.filename
= level
.name
= "level_demo_static"
94 level
.filename
= level
.name
= "level_demo"
97 worlds
.scene
= o_scene
100 # Now we just display the level
104 # This function must be called the first time you run game_skel.
105 # Then, you can comment it, since the level has been saved.
108 # Loads the level, and put it in the scene
109 level
= soya
.World
.get("level_demo")
110 worlds
.scene
.add(level
)
112 worlds
.camera
.set_xyz(697.0,5.0,545.0)
113 worlds
.camera
.back
= 500
114 worlds
.enable_fps
= True
118 # print worlds.camera.x,worlds.camera.y,worlds.camera.z
121 def renderloop(proportion
):
122 if sdlconst
.K_UP
in worlds
.KEY
: worlds
.camera
.z
-= 1 * proportion
123 if sdlconst
.K_DOWN
in worlds
.KEY
: worlds
.camera
.z
+= 1 * proportion
124 if sdlconst
.K_LEFT
in worlds
.KEY
: worlds
.camera
.x
-= 1 * proportion
125 if sdlconst
.K_RIGHT
in worlds
.KEY
: worlds
.camera
.x
+= 1 * proportion
126 if sdlconst
.K_SPACE
in worlds
.KEY
: worlds
.camera
.y
+= .5 * proportion
127 if sdlconst
.K_LCTRL
in worlds
.KEY
: worlds
.camera
.y
-= .5 * proportion
129 worlds
.begin_loop(mainloop
,renderloop
)