95 lines
3.1 KiB
Java
95 lines
3.1 KiB
Java
package shootergame.world.layer.layergen;
|
|
|
|
import java.util.Random;
|
|
|
|
import shootergame.Main;
|
|
import shootergame.entity.Entity;
|
|
import shootergame.entity.EntityDummy;
|
|
import shootergame.entity.EntityZombie;
|
|
import shootergame.init.Tiles;
|
|
import shootergame.util.math.TileState;
|
|
import shootergame.util.math.random.OpenSimplexNoise;
|
|
import shootergame.util.math.random.RandomHelpers;
|
|
import shootergame.util.math.vec.Vec2d;
|
|
import shootergame.util.math.vec.Vec2i;
|
|
import shootergame.world.chunk.Chunk;
|
|
import shootergame.world.layer.Layer;
|
|
|
|
public class LayerGenEarth extends LayerGen
|
|
{
|
|
|
|
@Override
|
|
public void generateChunk(Chunk chunk, Layer layer, long seed, Random rand, Vec2i c_pos)
|
|
{
|
|
// Is there going to be a portal in this chunk
|
|
boolean portal = PortalSpawnrates.WorldCavePortal(rand);
|
|
Vec2i portal_pos = null;
|
|
if(portal) portal_pos = new Vec2i(
|
|
RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.mx),
|
|
RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.my));
|
|
|
|
// Get the noise generator
|
|
OpenSimplexNoise noisegen_n = new OpenSimplexNoise(new Random(seed + layer.id).nextLong());
|
|
|
|
// Loop over the layer dimensions and create land
|
|
for(int x=0;x<Chunk.CHUNK_SIZE.mx;x++) {
|
|
for(int y=0;y<Chunk.CHUNK_SIZE.my;y++)
|
|
{
|
|
// Get the x and y in the world
|
|
int cx = x + c_pos.x * Chunk.CHUNK_SIZE.mx;
|
|
int cy = y + c_pos.y * Chunk.CHUNK_SIZE.my;
|
|
|
|
// Get the noise value and the position vector
|
|
double noise_n = (noisegen_n.eval(cx/10.0, cy/10.0) + 1) * 50;
|
|
Vec2i pos = new Vec2i(x, y);
|
|
|
|
// Tree and rock generation
|
|
if(rand.nextDouble() > 0.9) chunk.setFrontTile(new TileState(Tiles.TREE,
|
|
(short)RandomHelpers.randrange(rand, Short.MAX_VALUE)), pos);
|
|
else if(rand.nextDouble() > 0.99) chunk.setFrontTile(new TileState(Tiles.ROCK,
|
|
(short)RandomHelpers.randrange(rand, Short.MAX_VALUE)), pos);
|
|
else chunk.setFrontTile(Tiles.VOID.getDefaultState(), pos);
|
|
|
|
// Terrain generation
|
|
if(noise_n < 40) {
|
|
chunk.setFrontTile(Tiles.WATER.getDefaultState(), pos);
|
|
chunk.setBackTile(Tiles.DIRT.getDefaultState(), pos);
|
|
}
|
|
else if(noise_n < 70) chunk.setBackTile(Tiles.GRASS.getDefaultState(), pos);
|
|
else if(noise_n < 90) chunk.setBackTile(Tiles.DIRT.getDefaultState(), pos);
|
|
else chunk.setBackTile(Tiles.STONE.getDefaultState(), pos);
|
|
}
|
|
}
|
|
|
|
if(portal) {
|
|
chunk.setBackTile(new TileState(Tiles.PORTAL_DOWN, (short)1), portal_pos);
|
|
chunk.setFrontTile(Tiles.LADDER.getDefaultState(), portal_pos);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void spawnEntities(Layer layer, Random rand)
|
|
{
|
|
if(rand.nextDouble() > 0.98)
|
|
{
|
|
Entity zombie = new EntityZombie();
|
|
zombie.pos = new Vec2d(
|
|
RandomHelpers.randrange(rand, (int)Main.player.pos.x - 128, (int)Main.player.pos.x + 128),
|
|
RandomHelpers.randrange(rand, (int)Main.player.pos.y - 128, (int)Main.player.pos.y + 128));
|
|
|
|
if(zombie.pos.squareDistance(Main.player.pos) > 64)
|
|
layer.spawnEntity(zombie);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public TileState getTileDestroyed() {
|
|
return Tiles.DIRT.getDefaultState();
|
|
}
|
|
|
|
@Override
|
|
public double getLightLevel() {
|
|
return 0.3;
|
|
}
|
|
}
|