Improved world gen and made the main menu demo world not re-generate
This commit is contained in:
parent
a6b8edcd67
commit
c5e36b6f79
|
|
@ -415,7 +415,7 @@ public class EntityPlayer extends Entity implements
|
||||||
{
|
{
|
||||||
Layer layer = Main.world.getLayer();
|
Layer layer = Main.world.getLayer();
|
||||||
Model model = getModel();
|
Model model = getModel();
|
||||||
model.setModel(Matrix4.identity());
|
model.setModel(Matrix4.translate(0, getPos().y, 0));
|
||||||
model.render();
|
model.render();
|
||||||
|
|
||||||
ItemStack holding = inventory.getItem(inventory_hand);
|
ItemStack holding = inventory.getItem(inventory_hand);
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,5 @@
|
||||||
package projectzombie.menu;
|
package projectzombie.menu;
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import gl_engine.vec.Vec2d;
|
|
||||||
import gl_engine.vec.Vec3d;
|
import gl_engine.vec.Vec3d;
|
||||||
import projectzombie.Main;
|
import projectzombie.Main;
|
||||||
import projectzombie.input.types.InputGUI;
|
import projectzombie.input.types.InputGUI;
|
||||||
|
|
@ -10,13 +7,10 @@ import projectzombie.menu.gui.GUI;
|
||||||
import projectzombie.menu.gui.GUIButtonBasic;
|
import projectzombie.menu.gui.GUIButtonBasic;
|
||||||
import projectzombie.menu.gui.GUIButtonGroup;
|
import projectzombie.menu.gui.GUIButtonGroup;
|
||||||
import projectzombie.menu.gui.GUILabelMain;
|
import projectzombie.menu.gui.GUILabelMain;
|
||||||
import projectzombie.menu.gui.GUITextBox;
|
|
||||||
import projectzombie.world.World;
|
import projectzombie.world.World;
|
||||||
|
|
||||||
public class MenuMain extends Menu
|
public class MenuMain extends Menu
|
||||||
{
|
{
|
||||||
private static final Random rand = new Random();
|
|
||||||
|
|
||||||
private GUI gui;
|
private GUI gui;
|
||||||
|
|
||||||
public MenuMain() {
|
public MenuMain() {
|
||||||
|
|
@ -47,7 +41,7 @@ public class MenuMain extends Menu
|
||||||
gui.add(group);
|
gui.add(group);
|
||||||
gui.setSelected(group.get(0));
|
gui.setSelected(group.get(0));
|
||||||
|
|
||||||
World.createWorld(null, rand.nextLong());
|
World.createDemoWorld();
|
||||||
Main.player.dead = true;
|
Main.player.dead = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,10 @@ public class World implements IBdfClassManager
|
||||||
{
|
{
|
||||||
public static final double BIOME_SIZE = 1024;
|
public static final double BIOME_SIZE = 1024;
|
||||||
|
|
||||||
|
private static long demoWorldSeed = new Random().nextLong();
|
||||||
|
private static EntityPlayer demoWorldPlayer;
|
||||||
|
private static World demoWorld;
|
||||||
|
|
||||||
private Layer loaded;
|
private Layer loaded;
|
||||||
private ArrayList<Layer> layers = new ArrayList<Layer>();
|
private ArrayList<Layer> layers = new ArrayList<Layer>();
|
||||||
private BdfFileManager file_manager;
|
private BdfFileManager file_manager;
|
||||||
|
|
@ -66,6 +70,40 @@ public class World implements IBdfClassManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void createDemoWorld()
|
||||||
|
{
|
||||||
|
long seed = demoWorldSeed;
|
||||||
|
|
||||||
|
if(demoWorld == null)
|
||||||
|
{
|
||||||
|
// Create all the layers
|
||||||
|
Layers.EARTH = new Layer(new Random(seed), LayerGenerators.EARTH);
|
||||||
|
Layers.CAVES = new Layer(new Random(seed), LayerGenerators.CAVES);
|
||||||
|
Layers.LAVA_CAVES = new Layer(new Random(seed), LayerGenerators.LAVA_CAVES);
|
||||||
|
|
||||||
|
// Create the world and set the earth as the default layer
|
||||||
|
Main.world = new World(null);
|
||||||
|
Main.world.addLayer(Layers.EARTH);
|
||||||
|
Main.world.addLayer(Layers.CAVES);
|
||||||
|
Main.world.addLayer(Layers.LAVA_CAVES);
|
||||||
|
Main.world.setLayer(0);
|
||||||
|
|
||||||
|
Main.player = new EntityPlayer();
|
||||||
|
|
||||||
|
demoWorldPlayer = Main.player;
|
||||||
|
demoWorld = Main.world;
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
Main.world = demoWorld;
|
||||||
|
Main.player = demoWorldPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize some other objects
|
||||||
|
GameTimer.resetTime();
|
||||||
|
BossBars.clear();
|
||||||
|
}
|
||||||
|
|
||||||
public static void createWorld(String path, long seed)
|
public static void createWorld(String path, long seed)
|
||||||
{
|
{
|
||||||
// Create all the layers
|
// Create all the layers
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ public class LayerGenCaves extends LayerGen
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getTemperature(Layer layer, Vec2d pos) {
|
public double getTemperature(Layer layer, Vec2d pos) {
|
||||||
return getTemperatureStatic(layer, pos);
|
return layer.getTemperature(pos.toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getHumidity(Layer layer, Vec2d pos)
|
public double getHumidity(Layer layer, Vec2d pos)
|
||||||
|
|
@ -49,11 +49,12 @@ public class LayerGenCaves extends LayerGen
|
||||||
Random lrand = new Random(layer.lseed);
|
Random lrand = new Random(layer.lseed);
|
||||||
|
|
||||||
layer.noise_gens = new NoiseGenerator[] {
|
layer.noise_gens = new NoiseGenerator[] {
|
||||||
new NoiseGeneratorSimplex(rand), // Temperature
|
new NoiseGeneratorSimplex(rand, 64), // Temperature
|
||||||
new NoiseGeneratorSimplex(rand), // Humidity
|
new NoiseGeneratorSimplex(rand, 64), // Humidity
|
||||||
new NoiseGeneratorSimplex(lrand), // Cave structure
|
|
||||||
new NoiseGeneratorSimplex(lrand), // Caverns
|
new NoiseGeneratorSimplex(lrand, 4), // Cave structure
|
||||||
new NoiseGeneratorSimplex(lrand), // Wall width
|
new NoiseGeneratorSimplex(lrand, 4), // Caverns
|
||||||
|
new NoiseGeneratorSimplex(lrand, 4), // Wall width
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -93,7 +94,7 @@ public class LayerGenCaves extends LayerGen
|
||||||
// Get the noise value and the position vector
|
// Get the noise value and the position vector
|
||||||
double noise_n = 100 - MathHelpers.positive( layer.noise_gens[2].eval(cx/16.0, cy/16.0) * 100 );
|
double noise_n = 100 - MathHelpers.positive( layer.noise_gens[2].eval(cx/16.0, cy/16.0) * 100 );
|
||||||
double noise_c = layer.noise_gens[3].eval(cx/32.0, cy/32.0);
|
double noise_c = layer.noise_gens[3].eval(cx/32.0, cy/32.0);
|
||||||
double noise_w = layer.noise_gens[4].eval(cx/32.0, cy/32.0) * 30 + 100;
|
double noise_w = layer.noise_gens[4].eval(cx/32.0, cy/32.0) * 30 + 90;
|
||||||
boolean cavern = false;
|
boolean cavern = false;
|
||||||
|
|
||||||
Tile floor = Tiles.STONE;
|
Tile floor = Tiles.STONE;
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ public class LayerGenEarth extends LayerGen
|
||||||
{
|
{
|
||||||
// Get the noise generator
|
// Get the noise generator
|
||||||
NoiseGenerator terrain_noise = layer.noise_gens[0];
|
NoiseGenerator terrain_noise = layer.noise_gens[0];
|
||||||
return MathHelpers.map(terrain_noise.eval(pos.x / World.BIOME_SIZE, pos.y / World.BIOME_SIZE), -1, 1, 0, 1);
|
return terrain_noise.eval(pos.x / World.BIOME_SIZE, pos.y / World.BIOME_SIZE) * 0.5 + 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -45,15 +45,14 @@ public class LayerGenEarth extends LayerGen
|
||||||
double light = MathHelpers.map(
|
double light = MathHelpers.map(
|
||||||
MathHelpers.sin(MathHelpers.map(GameTimer.getTime() % 720000, 0, 720000, 0, MathHelpers.TWO_PI)),
|
MathHelpers.sin(MathHelpers.map(GameTimer.getTime() % 720000, 0, 720000, 0, MathHelpers.TWO_PI)),
|
||||||
-1, 1, 0.2 * humidity, 0.2);
|
-1, 1, 0.2 * humidity, 0.2);
|
||||||
NoiseGenerator terrain_noise = layer.noise_gens[0];
|
return layer.getTemperature(pos.toInt()) * (0.5 + light);
|
||||||
return MathHelpers.map(terrain_noise.eval(pos.x / World.BIOME_SIZE, pos.y / World.BIOME_SIZE), -1, 1, 0, 0.5 + light);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getHumidity(Layer layer, Vec2d pos)
|
public double getHumidity(Layer layer, Vec2d pos)
|
||||||
{
|
{
|
||||||
// Get the noise generator
|
// Get the noise generator
|
||||||
NoiseGenerator terrain_noise = layer.noise_gens[1];
|
NoiseGenerator terrain_noise = layer.noise_gens[1];
|
||||||
return MathHelpers.map(terrain_noise.eval(pos.x / World.BIOME_SIZE, pos.y / World.BIOME_SIZE), -1, 1, 0, 1);
|
return terrain_noise.eval(pos.x / World.BIOME_SIZE, pos.y / World.BIOME_SIZE) * 0.5 + 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -71,8 +70,7 @@ public class LayerGenEarth extends LayerGen
|
||||||
new NoiseGeneratorSimplex(lrand), // Wind
|
new NoiseGeneratorSimplex(lrand), // Wind
|
||||||
new NoiseGeneratorSimplex(lrand), // Wind
|
new NoiseGeneratorSimplex(lrand), // Wind
|
||||||
new NoiseGeneratorSimplex(lrand, 4), // Water
|
new NoiseGeneratorSimplex(lrand, 4), // Water
|
||||||
new NoiseGeneratorSimplex(lrand), // Rocks
|
new NoiseGeneratorSimplex(lrand, 2), // Rocks
|
||||||
new NoiseGeneratorSimplex(lrand), // Offset
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -93,6 +91,7 @@ public class LayerGenEarth extends LayerGen
|
||||||
Vec2d pos = new Vec2d(c_pos.x * 16 + x, c_pos.y * 16 + y);
|
Vec2d pos = new Vec2d(c_pos.x * 16 + x, c_pos.y * 16 + y);
|
||||||
Vec2i tpos = pos.toInt();
|
Vec2i tpos = pos.toInt();
|
||||||
|
|
||||||
|
double rocks = layer.noise_gens[5].eval(pos.x / 16.0, pos.y / 16.0);
|
||||||
double temperature = getTemperatureStatic(layer, pos);
|
double temperature = getTemperatureStatic(layer, pos);
|
||||||
double humidity = getHumidity(layer, pos);
|
double humidity = getHumidity(layer, pos);
|
||||||
|
|
||||||
|
|
@ -106,6 +105,7 @@ public class LayerGenEarth extends LayerGen
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
byte rock_type = 0;
|
byte rock_type = 0;
|
||||||
|
boolean placed_stone = false;
|
||||||
|
|
||||||
if(temperature < 0.35)
|
if(temperature < 0.35)
|
||||||
{
|
{
|
||||||
|
|
@ -122,7 +122,12 @@ public class LayerGenEarth extends LayerGen
|
||||||
chunk.setBackTile(Tiles.SAND.getDefaultState(), tpos);
|
chunk.setBackTile(Tiles.SAND.getDefaultState(), tpos);
|
||||||
rock_type = (byte)2;
|
rock_type = (byte)2;
|
||||||
|
|
||||||
if(rand.nextDouble() > MathHelpers.map(humidity, 0, 0.5, 0.98, 0.95)) {
|
if(rocks > 0.8) {
|
||||||
|
chunk.setBackTile(Tiles.SANDSTONE_WALL.getDefaultState(), tpos);
|
||||||
|
placed_stone = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(rand.nextDouble() > MathHelpers.map(humidity, 0, 0.5, 0.98, 0.95)) {
|
||||||
chunk.setFrontTile(Tiles.CACTUS.getDefaultState(), tpos);
|
chunk.setFrontTile(Tiles.CACTUS.getDefaultState(), tpos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -131,15 +136,20 @@ public class LayerGenEarth extends LayerGen
|
||||||
{
|
{
|
||||||
chunk.setBackTile(Tiles.GRASS.getDefaultState(), tpos);
|
chunk.setBackTile(Tiles.GRASS.getDefaultState(), tpos);
|
||||||
|
|
||||||
if(rand.nextDouble() > MathHelpers.map(humidity, 0, 1, 0.99, 0.9)) {
|
if(rocks > 0.8) {
|
||||||
|
chunk.setBackTile(Tiles.WALL.getDefaultState(), tpos);
|
||||||
|
placed_stone = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(rand.nextDouble() > MathHelpers.map(humidity, 0, 1, 0.99, 0.9)) {
|
||||||
chunk.setFrontTile(Tiles.TREE.getDefaultState(), tpos);
|
chunk.setFrontTile(Tiles.TREE.getDefaultState(), tpos);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(rand.nextDouble() > 0.9) {
|
else if(rand.nextDouble() > 0.9) {
|
||||||
chunk.setFrontTile(Tiles.TALL_GRASS.getDefaultState(), tpos);
|
chunk.setFrontTile(Tiles.TALL_GRASS.getDefaultState(), tpos);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(temperature > 0.7 && humidity > 0.7 && Math.random() > 0.9998) {
|
else if(temperature > 0.7 && humidity > 0.7 && Math.random() > 0.9998) {
|
||||||
chunk.setFrontTile(Tiles.HEMP.getDefaultState(), tpos);
|
chunk.setFrontTile(Tiles.HEMP.getDefaultState(), tpos);
|
||||||
while(Math.random() < 0.8) {
|
while(Math.random() < 0.8) {
|
||||||
chunk.setFrontTile(Tiles.HEMP.getDefaultState(),
|
chunk.setFrontTile(Tiles.HEMP.getDefaultState(),
|
||||||
|
|
@ -150,7 +160,7 @@ public class LayerGenEarth extends LayerGen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(rand.nextDouble() > 0.98) {
|
if(!placed_stone && rand.nextDouble() > 0.98) {
|
||||||
chunk.setFrontTile(new TileState(Tiles.ROCK, rock_type), tpos);
|
chunk.setFrontTile(new TileState(Tiles.ROCK, rock_type), tpos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue