Hidden labels now are non clickable
[pyworlds.git] / tests / game-skel1.py
blobd87669f5db646b0ecf5d1fac0d371d73f80f22c0
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 worlds
6 from pyworlds.worlds import sdlconst,soya
7 import soya.widget as widget
10 worlds.init()
13 class Level(soya.World):
14 """A game level.
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."""
19 def create_level():
20 """This function creates and saves the game skeleton demo level."""
22 # Create a level object
23 level = Level()
25 # Separates static and non static parts
26 # This will speed up network games, since only the non static part will be
27 # sent on the network
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)
38 terrain.y = -65.0
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)
73 sun.directional = 1
74 sun.diffuse = (1.0, 0.8, 0.4, 1.0)
75 sun.rotate_x(-45.0)
77 # Creates a sky atmosphere, with fog
78 atmosphere = soya.SkyAtmosphere()
79 atmosphere.ambient = (0.3, 0.3, 0.4, 1.0)
80 atmosphere.fog = 1
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"
93 level_static.save()
94 level.filename = level.name = "level_demo"
95 level.save()
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.
106 create_level()
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
116 def mainloop():
117 pass
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)