76 lines
2.3 KiB
Java
76 lines
2.3 KiB
Java
package shootergame.world.layer.layergen;
|
|
|
|
import java.util.Random;
|
|
|
|
import shootergame.Main;
|
|
import shootergame.entity.Entity;
|
|
import shootergame.entity.EntityBullet;
|
|
import shootergame.entity.EntityZombie;
|
|
import shootergame.init.Tiles;
|
|
import shootergame.tiles.Tile;
|
|
import shootergame.util.math.random.OpenSimplexNoise;
|
|
import shootergame.util.math.random.RandomHelpers;
|
|
import shootergame.util.math.range.Range2i;
|
|
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 Chunk generateChunk(Layer layer, Random rand, Vec2i c_pos)
|
|
{
|
|
// Create the new chunk
|
|
Chunk chunk = new Chunk(layer, c_pos, rand);
|
|
|
|
// Get the noise generator
|
|
OpenSimplexNoise noisegen_n = new OpenSimplexNoise(rand.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(Tiles.TREE, pos);
|
|
else if(rand.nextDouble() > 0.99) chunk.setFrontTile(Tiles.ROCK, pos);
|
|
else chunk.setFrontTile(Tiles.VOID, pos);
|
|
|
|
// Terrain generation
|
|
if(noise_n < 20) {
|
|
chunk.setFrontTile(Tiles.WATER, pos);
|
|
chunk.setBackTile(Tiles.DIRT, pos);
|
|
}
|
|
else if(noise_n < 60) chunk.setBackTile(Tiles.GRASS, pos);
|
|
else if(noise_n < 80) chunk.setBackTile(Tiles.DIRT, pos);
|
|
else chunk.setBackTile(Tiles.STONE, pos);
|
|
}
|
|
}
|
|
|
|
// Send back the new chunk
|
|
return chunk;
|
|
}
|
|
|
|
@Override
|
|
public void spawnEntities(Layer layer, Random rand)
|
|
{
|
|
if(rand.nextDouble() > 0.99)
|
|
{
|
|
Entity zombie = new EntityZombie();
|
|
zombie.pos = new Vec2d(
|
|
RandomHelpers.randrange(rand, (int)Main.player.pos.x - 100, (int)Main.player.pos.x + 100),
|
|
RandomHelpers.randrange(rand, (int)Main.player.pos.y - 100, (int)Main.player.pos.y + 100));
|
|
layer.spawnEntity(zombie);
|
|
}
|
|
}
|
|
}
|