bloboland

view src/level.cc @ 1:cfe68befb7cc

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