rev |
line source |
nuclear@1
|
1 #include "level.h"
|
nuclear@1
|
2
|
nuclear@1
|
3 #include "opt.h"
|
nuclear@1
|
4
|
nuclear@1
|
5 Level::Level()
|
nuclear@1
|
6 {
|
nuclear@1
|
7 terrain = 0;
|
nuclear@1
|
8 }
|
nuclear@1
|
9
|
nuclear@1
|
10 Level::~Level()
|
nuclear@1
|
11 {
|
nuclear@1
|
12 delete terrain;
|
nuclear@1
|
13 }
|
nuclear@1
|
14
|
nuclear@1
|
15 void Level::generate()
|
nuclear@1
|
16 {
|
nuclear@1
|
17 delete terrain;
|
nuclear@1
|
18
|
nuclear@1
|
19 int xsz = opt.world_size[0];
|
nuclear@1
|
20 int ysz = opt.world_size[1];
|
nuclear@1
|
21 int zsz = opt.world_size[2];
|
nuclear@1
|
22
|
nuclear@1
|
23 terrain = new Volume(xsz, ysz, zsz);
|
nuclear@1
|
24
|
nuclear@1
|
25 for(int i=0; i<xsz; i++) {
|
nuclear@1
|
26 for(int j=0; j<ysz; j++) {
|
nuclear@1
|
27 float x = opt.gen_noise_scale * (float)i / (float)xsz;
|
nuclear@1
|
28 float y = opt.gen_noise_scale * (float)j / (float)ysz;
|
nuclear@1
|
29 float peak = 0.4 * noise2(x, y) * 0.5 + 0.5;
|
nuclear@1
|
30
|
nuclear@1
|
31 for(int k=0; k<zsz; k++) {
|
nuclear@1
|
32 Vector4 voxel(1, 1, 1, 1);
|
nuclear@1
|
33 float z = (float)k / (float)zsz;
|
nuclear@1
|
34
|
nuclear@1
|
35 if(z < 0.1) {
|
nuclear@1
|
36 // lava
|
nuclear@1
|
37 static const Vector4 col1(0.96, 0.3, 0.1, 1);
|
nuclear@1
|
38 static const Vector4 col2(0.96, 0.75, 0.1, 1);
|
nuclear@1
|
39 float t = noise3(x, y, z);
|
nuclear@1
|
40 voxel = lerp(col1, col2, t);
|
nuclear@1
|
41 } else if(z < peak - 0.05) {
|
nuclear@1
|
42 // mud
|
nuclear@1
|
43 voxel = Vector4(0.57, 0.43, 0.29, 1);
|
nuclear@1
|
44 } else if(z < 0.85) {
|
nuclear@1
|
45 // grass
|
nuclear@1
|
46 voxel = Vector4(0.68, 0.95, 0.38);
|
nuclear@1
|
47 } // else snow (default)
|
nuclear@1
|
48
|
nuclear@1
|
49 voxel.w = z < peak ? 1.0 : 0.0;
|
nuclear@1
|
50 terrain->set_voxel(i, j, k, voxel);
|
nuclear@1
|
51 }
|
nuclear@1
|
52 }
|
nuclear@1
|
53 }
|
nuclear@1
|
54 }
|
nuclear@1
|
55
|
nuclear@1
|
56 bool Level::load(const char *fname)
|
nuclear@1
|
57 {
|
nuclear@1
|
58 return false;
|
nuclear@1
|
59 }
|
nuclear@1
|
60
|
nuclear@1
|
61 bool Level::save(const char *fname) const
|
nuclear@1
|
62 {
|
nuclear@1
|
63 return false;
|
nuclear@1
|
64 }
|