Changed RGB light to a single brightness value to save resources.

This commit is contained in:
josua 2019-09-11 14:14:03 +10:00
parent b15b396935
commit b672a176b8
39 changed files with 283 additions and 183 deletions

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

View File

@ -17,10 +17,12 @@ import shootergame.input.JoystickCallback;
import shootergame.mainloop.MainloopEventHandler; import shootergame.mainloop.MainloopEventHandler;
import shootergame.menu.Menu; import shootergame.menu.Menu;
import shootergame.menu.MenuNone; import shootergame.menu.MenuNone;
import shootergame.time.GameTimer;
import shootergame.world.World; import shootergame.world.World;
import shootergame.world.chunk.ChunkEventHandler; import shootergame.world.chunk.ChunkEventHandler;
import shootergame.world.layer.layergen.LayerGenCaves; import shootergame.world.layer.layergen.LayerGenCaves;
import shootergame.world.layer.layergen.LayerGenEarth; import shootergame.world.layer.layergen.LayerGenEarth;
import shootergame.world.layer.layergen.LayerGenLavaCaves;
public class Main public class Main
{ {
@ -55,6 +57,7 @@ public class Main
mainloop.register(ChunkEventHandler.CHUNK_EVENT_HANDLER); mainloop.register(ChunkEventHandler.CHUNK_EVENT_HANDLER);
mainloop.register(DisplayStatsEventHandler.DISPLAY_STATS_EVENT_HANDLER); mainloop.register(DisplayStatsEventHandler.DISPLAY_STATS_EVENT_HANDLER);
mainloop.register(JoystickCallback.JOYSTICK_CALLBACK); mainloop.register(JoystickCallback.JOYSTICK_CALLBACK);
mainloop.register(new GameTimer());
// Create the display // Create the display
window = new DisplayWindow("ShooterGame"); window = new DisplayWindow("ShooterGame");
@ -67,7 +70,7 @@ public class Main
JoystickCallback.JOYSTICK_CALLBACK.init(); JoystickCallback.JOYSTICK_CALLBACK.init();
// Create the world // Create the world
world = new World(new Random(), new LayerGenEarth(), new LayerGenCaves()); world = new World(new Random(), new LayerGenEarth(), new LayerGenCaves(), new LayerGenLavaCaves());
// Initialise the entities // Initialise the entities
mainloop.register(EntityEventHandler.ENTITY_EVENT_HANDLER); mainloop.register(EntityEventHandler.ENTITY_EVENT_HANDLER);

View File

@ -6,27 +6,17 @@ import shootergame.entity.Entity;
import shootergame.entity.player.EntityPlayer; import shootergame.entity.player.EntityPlayer;
import shootergame.util.math.MathHelpers; import shootergame.util.math.MathHelpers;
import shootergame.util.math.TileState; import shootergame.util.math.TileState;
import shootergame.util.math.map.Map2DElement;
import shootergame.util.math.vec.Vec2i; import shootergame.util.math.vec.Vec2i;
import shootergame.util.math.vec.Vec3d;
import shootergame.world.chunk.Chunk; import shootergame.world.chunk.Chunk;
import shootergame.world.layer.Layer; import shootergame.world.layer.Layer;
public class LightingManager public class LightingManager
{ {
@Deprecated
public static void markDirty() {
}
public static void update() public static void update()
{ {
// Do nothing if nothing has changed
//if(!isDirty) return;
//isDirty = false;
int r = Camera.camera.renderDistance; int r = Camera.camera.renderDistance;
Layer layer = Main.world.getLayer(); Layer layer = Main.world.getLayer();
Vec3d light_clear = layer.layergen.getLightLevel(); double light_clear = layer.layergen.getLightLevel();
EntityPlayer player = Main.player; EntityPlayer player = Main.player;
// Loop over all the loaded blocks and reset the light level // Loop over all the loaded blocks and reset the light level
@ -38,12 +28,12 @@ public class LightingManager
} }
// Loop over every entity to scan for light sources // Loop over every entity to scan for light sources
for(Map2DElement<Chunk> mce : layer.chunks) for(int cx=-r;cx<r;cx++) {
{ for(int cy=-r;cy<r;cy++)
if(mce.pos.squareDistance(new Vec2i((int)(player.pos.x/16), (int)(player.pos.y/16))) < r)
{ {
// Loop over all the entities // Loop over all the entities
Chunk chunk = mce.o; Vec2i cpos = new Vec2i(cx + ((int)player.pos.x / 16), cy + ((int)player.pos.y / 16));
Chunk chunk = layer.getChunk(cpos);
for(Entity e : chunk.entities) for(Entity e : chunk.entities)
{ {
// Does this entity emit light // Does this entity emit light
@ -53,7 +43,7 @@ public class LightingManager
addLightToTiles(layer, new Vec2i( addLightToTiles(layer, new Vec2i(
MathHelpers.floor(e.pos.x), MathHelpers.floor(e.pos.x),
MathHelpers.floor(e.pos.y)), MathHelpers.floor(e.pos.y)),
e.getLightLevel()); e.getLightLevel(), true);
} }
} }
@ -62,7 +52,7 @@ public class LightingManager
for(int y=0;y<16;y++) for(int y=0;y<16;y++)
{ {
// Get the tile position // Get the tile position
Vec2i tpos = new Vec2i(x + mce.pos.x * 16, y + mce.pos.y * 16); Vec2i tpos = new Vec2i(x + cpos.x * 16, y + cpos.y * 16);
int tid = tpos.getId(Chunk.CHUNK_SIZE); int tid = tpos.getId(Chunk.CHUNK_SIZE);
// Get the front and back tiles // Get the front and back tiles
@ -73,20 +63,16 @@ public class LightingManager
if(fts.tile.emitsLight || bts.tile.emitsLight) if(fts.tile.emitsLight || bts.tile.emitsLight)
{ {
// Calculate the light given off by the tile // Calculate the light given off by the tile
Vec3d light_tile = chunk.getLightLevel(tid); double light_tile = chunk.getLightLevel(tid);
Vec3d light_tile2 = light_tile.copy(); double light_tile2 = light_tile;
Vec3d ftsl = fts.tile.getLightLevel(fts); double ftsl = fts.tile.getLightLevel(fts);
Vec3d btsl = fts.tile.getLightLevel(bts); double btsl = fts.tile.getLightLevel(bts);
if(ftsl.x > light_tile.x) light_tile.x = ftsl.x; if(ftsl > light_tile) light_tile = ftsl;
if(ftsl.y > light_tile.y) light_tile.y = ftsl.y; if(btsl > light_tile) light_tile = btsl;
if(ftsl.z > light_tile.z) light_tile.z = ftsl.z;
if(btsl.x > light_tile.x) light_tile.x = btsl.x;
if(btsl.y > light_tile.y) light_tile.y = btsl.y;
if(btsl.z > light_tile.z) light_tile.z = btsl.z;
// Has the light level changed; add light to this tile // Has the light level changed; add light to this tile
if(!light_tile.equal(light_tile2)) { if(light_tile != light_tile2) {
addLightToTiles(layer, tpos, light_tile); addLightToTiles(layer, tpos, light_tile, true);
} }
} }
} }
@ -99,11 +85,11 @@ public class LightingManager
addLightToTiles(layer, new Vec2i( addLightToTiles(layer, new Vec2i(
MathHelpers.floor(player.pos.x), MathHelpers.floor(player.pos.x),
MathHelpers.floor(player.pos.y)), MathHelpers.floor(player.pos.y)),
player.getLightLevel()); player.getLightLevel(), true);
} }
} }
private static void addLightToTiles(Layer layer, Vec2i lpos, Vec3d light) private static void addLightToTiles(Layer layer, Vec2i lpos, double light, boolean ignoreDissipation)
{ {
// Get the light pos id // Get the light pos id
int lid = lpos.getId(Chunk.CHUNK_SIZE); int lid = lpos.getId(Chunk.CHUNK_SIZE);
@ -112,36 +98,25 @@ public class LightingManager
Chunk chunk = layer.getChunk(lpos); Chunk chunk = layer.getChunk(lpos);
TileState bt = chunk.getBackTile(lid); TileState bt = chunk.getBackTile(lid);
TileState ft = chunk.getFrontTile(lid); TileState ft = chunk.getFrontTile(lid);
Vec3d light_dissipation = bt.tile.getLightDissipation(bt); double light_dissipation = 0;
Vec3d light_dissipation2 = ft.tile.getLightDissipation(ft);
if(light_dissipation2.x > light_dissipation.x) light_dissipation.x = light_dissipation2.x;
if(light_dissipation2.y > light_dissipation.y) light_dissipation.y = light_dissipation2.y;
if(light_dissipation2.z > light_dissipation.z) light_dissipation.z = light_dissipation2.z;
// Set the light dissipation if(!ignoreDissipation) {
light = light.subtract(light_dissipation); light_dissipation = MathHelpers.biggest(
if(light.x < 0) light.x = 0; bt.tile.getLightDissipation(bt),
if(light.y < 0) light.y = 0; ft.tile.getLightDissipation(ft));
if(light.z < 0) light.z = 0;
if(light.x == 0 && light.y == 0 && light.z == 0) {
return;
} }
// Calculate the light level // Calculate the light level
Vec3d light_tile = chunk.getLightLevel(lid); double light_tile = chunk.getLightLevel(lid);
if( if(light <= light_tile) {
light.x <= light_tile.x &&
light.y <= light_tile.y &&
light.z <= light_tile.z) {
return; return;
} }
// Merge the light and the light tile values // Merge the light and the light tile values
if(light.x > light_tile.x) light_tile.x = light.x; chunk.setLightLevel(light, lid);
if(light.y > light_tile.y) light_tile.y = light.y;
if(light.z > light_tile.z) light_tile.z = light.z; // Set the light dissipation
chunk.setLightLevel(light_tile, lid); light = light - light_dissipation;
// Get all the adjacent positions of the light tiles to flow onto // Get all the adjacent positions of the light tiles to flow onto
Vec2i positions[] = { Vec2i positions[] = {
@ -153,7 +128,7 @@ public class LightingManager
// Add the light to all the adjacent positions // Add the light to all the adjacent positions
for(Vec2i position : positions) { for(Vec2i position : positions) {
addLightToTiles(layer, position, light); addLightToTiles(layer, position, light, false);
} }
} }
} }

View File

@ -12,7 +12,6 @@ import shootergame.util.math.MathHelpers;
import shootergame.util.math.TileState; import shootergame.util.math.TileState;
import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2d;
import shootergame.util.math.vec.Vec2i; import shootergame.util.math.vec.Vec2i;
import shootergame.util.math.vec.Vec3d;
import shootergame.world.chunk.Chunk; import shootergame.world.chunk.Chunk;
import shootergame.world.layer.Layer; import shootergame.world.layer.Layer;
@ -217,7 +216,7 @@ public class Entity implements ITransparentObject
return new Vec2d(0, 0); return new Vec2d(0, 0);
} }
public Vec3d getLightLevel() { public double getLightLevel() {
return new Vec3d(0, 0, 0); return 0;
} }
} }

View File

@ -116,9 +116,9 @@ public class EntityBullet extends EntityParticle
public void render(Vec2d pos, Camera camera) public void render(Vec2d pos, Camera camera)
{ {
// Set the colour // Set the colour
Vec3d light = chunk.getLightLevel(new Vec2i( double light = chunk.getLightLevel(new Vec2i(
MathHelpers.floor(pos.x), MathHelpers.floor(pos.y))); MathHelpers.floor(pos.x), MathHelpers.floor(pos.y)));
GlHelpers.color3(1 * light.x, 0.8 * light.y, 0.3 * light.z); GlHelpers.color3(1 * light, 0.8 * light, 0.3 * light);
// Call super // Call super
super.render(pos, camera); super.render(pos, camera);

View File

@ -7,7 +7,6 @@ import shootergame.util.gl.texture.TextureReference;
import shootergame.util.math.MathHelpers; import shootergame.util.math.MathHelpers;
import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2d;
import shootergame.util.math.vec.Vec2i; import shootergame.util.math.vec.Vec2i;
import shootergame.util.math.vec.Vec3d;
public class EntityVertical extends Entity public class EntityVertical extends Entity
{ {
@ -26,10 +25,9 @@ public class EntityVertical extends Entity
@Override @Override
public void render(Vec2d pos, Camera camera) { public void render(Vec2d pos, Camera camera) {
Vec3d light = chunk.getLightLevel(new Vec2i( double light = chunk.getLightLevel(new Vec2i(
MathHelpers.floor(pos.x), MathHelpers.floor(pos.y))); MathHelpers.floor(pos.x), MathHelpers.floor(pos.y)));
GlHelpers.color3(light.x, light.y, light.z); GlHelpers.color3(light, light, light);
this.render(pos, camera, tex, size); this.render(pos, camera, tex, size);
GlHelpers.color3(1, 1, 1);
} }
} }

View File

@ -9,7 +9,6 @@ import shootergame.util.math.MathHelpers;
import shootergame.util.math.random.RandomHelpers; import shootergame.util.math.random.RandomHelpers;
import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2d;
import shootergame.util.math.vec.Vec2i; import shootergame.util.math.vec.Vec2i;
import shootergame.util.math.vec.Vec3d;
import shootergame.world.chunk.Chunk; import shootergame.world.chunk.Chunk;
import shootergame.world.layer.Layer; import shootergame.world.layer.Layer;
@ -61,12 +60,12 @@ public class ParticleBlood extends EntityParticle
public void render(Vec2d pos, Camera camera) public void render(Vec2d pos, Camera camera)
{ {
// Get the light level // Get the light level
Vec3d light = chunk.getLightLevel(new Vec2i( double light = chunk.getLightLevel(new Vec2i(
MathHelpers.floor(pos.x), MathHelpers.floor(pos.y))); MathHelpers.floor(pos.x), MathHelpers.floor(pos.y)));
// Set some settings // Set some settings
GlHelpers.pushMatrix(); GlHelpers.pushMatrix();
GlHelpers.color3(r_color * light.x, 0, 0); GlHelpers.color3(r_color * light, 0, 0);
GlHelpers.translate(0, 0, height); GlHelpers.translate(0, 0, height);
// Call super // Call super

View File

@ -11,7 +11,6 @@ import shootergame.util.math.TileState;
import shootergame.util.math.random.RandomHelpers; import shootergame.util.math.random.RandomHelpers;
import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2d;
import shootergame.util.math.vec.Vec2i; import shootergame.util.math.vec.Vec2i;
import shootergame.util.math.vec.Vec3d;
import shootergame.world.chunk.Chunk; import shootergame.world.chunk.Chunk;
import shootergame.world.layer.Layer; import shootergame.world.layer.Layer;
@ -69,13 +68,12 @@ public class ParticleBreak extends EntityVertical
@Override @Override
public void render(Vec2d pos, Camera camera, TextureReference tex, Vec2d size) { public void render(Vec2d pos, Camera camera, TextureReference tex, Vec2d size) {
Vec3d light = chunk.getLightLevel(new Vec2i( double light = chunk.getLightLevel(new Vec2i(
MathHelpers.floor(pos.x), MathHelpers.floor(pos.y))); MathHelpers.floor(pos.x), MathHelpers.floor(pos.y)));
GlHelpers.color3(light.x, light.y, light.z); GlHelpers.color3(light, light, light);
GlHelpers.pushMatrix(); GlHelpers.pushMatrix();
GlHelpers.translate(0, 0, height); GlHelpers.translate(0, 0, height);
super.render(pos, camera, tex, size); super.render(pos, camera, tex, size);
GlHelpers.color3(1, 1, 1);
GlHelpers.popMatrix(); GlHelpers.popMatrix();
} }
} }

View File

@ -9,7 +9,6 @@ import shootergame.util.math.MathHelpers;
import shootergame.util.math.random.RandomHelpers; import shootergame.util.math.random.RandomHelpers;
import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2d;
import shootergame.util.math.vec.Vec2i; import shootergame.util.math.vec.Vec2i;
import shootergame.util.math.vec.Vec3d;
import shootergame.world.chunk.Chunk; import shootergame.world.chunk.Chunk;
import shootergame.world.layer.Layer; import shootergame.world.layer.Layer;
@ -36,9 +35,9 @@ public class ParticleSmoke extends EntityVertical
if(opacity <= 0) return; if(opacity <= 0) return;
GlHelpers.pushMatrix(); GlHelpers.pushMatrix();
GlHelpers.translate(0, 0, height); GlHelpers.translate(0, 0, height);
Vec3d light = chunk.getLightLevel(new Vec2i( double light = chunk.getLightLevel(new Vec2i(
MathHelpers.floor(pos.x), MathHelpers.floor(pos.y))); MathHelpers.floor(pos.x), MathHelpers.floor(pos.y)));
GlHelpers.color4(light.x, light.y, light.z, opacity); GlHelpers.color4(light, light, light, opacity);
super.render(pos, camera); super.render(pos, camera);
GlHelpers.color4(1, 1, 1, 1); GlHelpers.color4(1, 1, 1, 1);
GlHelpers.popMatrix(); GlHelpers.popMatrix();

View File

@ -49,9 +49,9 @@ public class ParticleWater extends EntityParticle
public void render(Vec2d pos, Camera camera) { public void render(Vec2d pos, Camera camera) {
GlHelpers.pushMatrix(); GlHelpers.pushMatrix();
GlHelpers.translate(0, 0, height); GlHelpers.translate(0, 0, height);
Vec3d light = chunk.getLightLevel(new Vec2i( double light = chunk.getLightLevel(new Vec2i(
MathHelpers.floor(pos.x), MathHelpers.floor(pos.y))); MathHelpers.floor(pos.x), MathHelpers.floor(pos.y)));
GlHelpers.color4(0, 0, light.z, 0.4); GlHelpers.color4(0, 0, light, 0.4);
super.render(pos, camera); super.render(pos, camera);
GlHelpers.color4(1, 1, 1, 1); GlHelpers.color4(1, 1, 1, 1);
GlHelpers.popMatrix(); GlHelpers.popMatrix();

View File

@ -17,7 +17,6 @@ import shootergame.util.math.ItemStack;
import shootergame.util.math.MathHelpers; import shootergame.util.math.MathHelpers;
import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2d;
import shootergame.util.math.vec.Vec2i; import shootergame.util.math.vec.Vec2i;
import shootergame.util.math.vec.Vec3d;
import shootergame.world.chunk.Chunk; import shootergame.world.chunk.Chunk;
import shootergame.world.layer.Layer; import shootergame.world.layer.Layer;
@ -64,13 +63,15 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI
} }
@Override @Override
public Vec3d getLightLevel() { public double getLightLevel() {
return new Vec3d(1, 1, 1); return 1;
} }
@Override @Override
public void tick(Chunk chunk, Layer layer) public void tick(Chunk chunk, Layer layer)
{ {
Cheats.god_mode = true;
// Handle player deaths // Handle player deaths
if(health <= 0) if(health <= 0)
{ {
@ -90,9 +91,6 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI
// Call super // Call super
super.tick(chunk, layer); super.tick(chunk, layer);
// Regen some of the players health
//this.addHealth(0.1);
// Rotate left // Rotate left
if(MOVE_LEFT) { if(MOVE_LEFT) {
this.angle -= 1; this.angle -= 1;
@ -157,9 +155,9 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI
GlHelpers.translate(0, 0, height); GlHelpers.translate(0, 0, height);
// Set the colour due to the lighting // Set the colour due to the lighting
Vec3d light = chunk.getLightLevel(new Vec2i( double light = chunk.getLightLevel(new Vec2i(
MathHelpers.floor(pos.x), MathHelpers.floor(pos.y))); MathHelpers.floor(pos.x), MathHelpers.floor(pos.y)));
GlHelpers.color3(light.x, light.y, light.z); GlHelpers.color3(light, light, light);
// Moving // Moving
if(MOVE_BACKWARD || MOVE_FORWARD || moving) if(MOVE_BACKWARD || MOVE_FORWARD || moving)

View File

@ -114,6 +114,17 @@ public class KeyCallback implements GLFWKeyCallbackI
} }
} }
else {
itemUse_last = false;
esc_last = false;
action_last = false;
itemDrop_last = false;
Main.player.MOVE_BACKWARD = false;
Main.player.MOVE_FORWARD = false;
Main.player.MOVE_LEFT = false;
Main.player.MOVE_RIGHT = false;
}
if(key == GLFW_KEY_ESCAPE) { if(key == GLFW_KEY_ESCAPE) {
if(pressed) { if(pressed) {
if(!esc_last) { if(!esc_last) {

View File

@ -0,0 +1,16 @@
package shootergame.tiles;
import java.util.Random;
import shootergame.time.GameTimer;
import shootergame.util.math.MathHelpers;
import shootergame.util.math.random.OpenSimplexNoise;
public class LavaLightlevel
{
static OpenSimplexNoise noise = new OpenSimplexNoise(new Random().nextLong());
static double getLightLevel() {
return MathHelpers.map(noise.eval(GameTimer.getTime() / 1000.0, 0), -1, 1, 0.4, 0.6);
}
}

View File

@ -7,7 +7,6 @@ import shootergame.entity.Entity;
import shootergame.util.math.TileState; import shootergame.util.math.TileState;
import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2d;
import shootergame.util.math.vec.Vec2i; import shootergame.util.math.vec.Vec2i;
import shootergame.util.math.vec.Vec3d;
import shootergame.world.chunk.Chunk; import shootergame.world.chunk.Chunk;
import shootergame.world.layer.Layer; import shootergame.world.layer.Layer;
@ -20,7 +19,7 @@ public class Tile implements ITransparentObject
public double tileHitbox = 0; public double tileHitbox = 0;
public double slowness = 0; public double slowness = 0;
public boolean unbreakable = false; public boolean unbreakable = false;
protected Vec3d light_dissipation = new Vec3d(1/12.0, 1/12.0, 1/12.0); protected double light_dissipation = 1/8.0;
public boolean emitsLight = true; public boolean emitsLight = true;
public Tile(String id) { public Tile(String id) {
@ -66,11 +65,11 @@ public class Tile implements ITransparentObject
public void onActivated(Layer layer, Vec2i tpos, Entity entity, TileState state) { public void onActivated(Layer layer, Vec2i tpos, Entity entity, TileState state) {
} }
public Vec3d getLightDissipation(TileState state) { public double getLightDissipation(TileState state) {
return light_dissipation; return light_dissipation;
} }
public Vec3d getLightLevel(TileState state) { public double getLightLevel(TileState state) {
return new Vec3d(0, 0, 0); return 0;
} }
} }

View File

@ -25,7 +25,7 @@ public class TileFlat extends Tile implements IHasTexture
super.render(pos, camera, state); super.render(pos, camera, state);
// Render the tile // Render the tile
GlHelpers.color3(state.light.x*color.x, state.light.y*color.y, state.light.z*color.z); GlHelpers.color3(state.light * color.x, state.light * color.y, state.light * color.z);
GlHelpers.begin(); GlHelpers.begin();
tex.texCoord(1, 1); GlHelpers.vertex3(pos.x+0, pos.y+0, 0); tex.texCoord(1, 1); GlHelpers.vertex3(pos.x+0, pos.y+0, 0);
tex.texCoord(0, 1); GlHelpers.vertex3(pos.x+1, pos.y+0, 0); tex.texCoord(0, 1); GlHelpers.vertex3(pos.x+1, pos.y+0, 0);

View File

@ -1,6 +1,7 @@
package shootergame.tiles; package shootergame.tiles;
import shootergame.init.Textures; import shootergame.init.Textures;
import shootergame.util.math.TileState;
import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2d;
public class TileLadder extends TileVertical public class TileLadder extends TileVertical
@ -13,6 +14,12 @@ public class TileLadder extends TileVertical
this.tileSolid = true; this.tileSolid = true;
this.tileHitbox = 0.3; this.tileHitbox = 0.3;
this.unbreakable = true; this.unbreakable = true;
this.emitsLight = true;
}
@Override
public double getLightLevel(TileState state) {
return 0.5;
} }
} }

View File

@ -5,9 +5,11 @@ import shootergame.Main;
import shootergame.entity.Entity; import shootergame.entity.Entity;
import shootergame.entity.player.EntityPlayer; import shootergame.entity.player.EntityPlayer;
import shootergame.init.Textures; import shootergame.init.Textures;
import shootergame.mainloop.MainloopEventHandler;
import shootergame.util.math.TileState; import shootergame.util.math.TileState;
import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2d;
import shootergame.util.math.vec.Vec2i; import shootergame.util.math.vec.Vec2i;
import shootergame.world.chunk.ChunkEventHandler;
import shootergame.world.layer.Layer; import shootergame.world.layer.Layer;
public class TileLadderUp extends TileVertical public class TileLadderUp extends TileVertical
@ -50,7 +52,7 @@ public class TileLadderUp extends TileVertical
player.height += 0.04; player.height += 0.04;
} }
if(movingPlayer == 1) { else if(movingPlayer == 2) {
player.height += 0.02; player.height += 0.02;
} }
@ -61,9 +63,15 @@ public class TileLadderUp extends TileVertical
player.height = -1; player.height = -1;
} }
if(player.height >= 0 && movingPlayer == 1) else if(movingPlayer == 1 && ChunkEventHandler.loaded)
{ {
movingPlayer = 2; movingPlayer = 2;
MainloopEventHandler.MAINLOOP_EVENT_HANDLER.mspf = 1000/60;
}
else if(player.height >= 0 && movingPlayer == 2)
{
movingPlayer = 3;
player.height = 0; player.height = 0;
player.moving = false; player.moving = false;
player.in_animation = false; player.in_animation = false;
@ -72,7 +80,7 @@ public class TileLadderUp extends TileVertical
@Override @Override
public boolean MainLoopRepeat() { public boolean MainLoopRepeat() {
return movingPlayer != 2; return movingPlayer != 3;
} }
@Override @Override

View File

@ -13,6 +13,7 @@ public class TileLava extends TileFlat
super(id, Textures.TILE_LAVA); super(id, Textures.TILE_LAVA);
this.tileWalkable = false; this.tileWalkable = false;
this.emitsLight = true;
} }
@Override @Override
@ -23,4 +24,9 @@ public class TileLava extends TileFlat
GlHelpers.popMatrix(); GlHelpers.popMatrix();
} }
@Override
public double getLightLevel(TileState state) {
return LavaLightlevel.getLightLevel();
}
} }

View File

@ -11,6 +11,8 @@ public class TileLavaFlow extends TileFlat
public TileLavaFlow(String id) { public TileLavaFlow(String id) {
super(id, Textures.TILE_LAVA_FLOW); super(id, Textures.TILE_LAVA_FLOW);
this.emitsLight = true;
} }
@Override @Override
@ -21,4 +23,9 @@ public class TileLavaFlow extends TileFlat
GlHelpers.popMatrix(); GlHelpers.popMatrix();
} }
@Override
public double getLightLevel(TileState state) {
return LavaLightlevel.getLightLevel();
}
} }

View File

@ -5,6 +5,7 @@ import shootergame.Main;
import shootergame.entity.Entity; import shootergame.entity.Entity;
import shootergame.entity.player.EntityPlayer; import shootergame.entity.player.EntityPlayer;
import shootergame.init.Textures; import shootergame.init.Textures;
import shootergame.mainloop.MainloopEventHandler;
import shootergame.util.math.TileState; import shootergame.util.math.TileState;
import shootergame.util.math.vec.Vec2i; import shootergame.util.math.vec.Vec2i;
import shootergame.world.chunk.ChunkEventHandler; import shootergame.world.chunk.ChunkEventHandler;
@ -48,13 +49,21 @@ public class TilePortalDown extends TileFlat
player.height -= 0.02; player.height -= 0.02;
} }
if(movingPlayer == 2) { else if(movingPlayer == 2) {
player.height -= 0.04; player.height -= 0.04;
} }
if(ChunkEventHandler.loaded && movingPlayer == 1) if(player.height < -1 && movingPlayer == 0)
{
movingPlayer = 1;
Main.world.setLayerID(state.meta);
player.height = 6;
}
else if(ChunkEventHandler.loaded && movingPlayer == 1)
{ {
movingPlayer = 2; movingPlayer = 2;
MainloopEventHandler.MAINLOOP_EVENT_HANDLER.mspf = 1000/60;
Vec2i check_poses[] = { Vec2i check_poses[] = {
new Vec2i( 1, 0), new Vec2i( 1, 0),
@ -91,14 +100,7 @@ public class TilePortalDown extends TileFlat
} }
} }
if(player.height < -1 && movingPlayer == 0) else if(player.height < 0 && movingPlayer == 2)
{
movingPlayer = 1;
Main.world.setLayerID(state.meta);
player.height = 6;
}
if(player.height < 0 && movingPlayer == 2)
{ {
movingPlayer = 3; movingPlayer = 3;
player.height = 0; player.height = 0;

View File

@ -3,12 +3,9 @@ package shootergame.tiles;
import shootergame.init.Textures; import shootergame.init.Textures;
import shootergame.util.math.TileState; import shootergame.util.math.TileState;
import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2d;
import shootergame.util.math.vec.Vec3d;
public class TileTree extends TileVertical public class TileTree extends TileVertical
{ {
private static final Vec3d light_dissipation = new Vec3d(1/4.0, 1/4.0, 1/4.0);
public TileTree(String id) { public TileTree(String id) {
super(id, Textures.TILE_TREE, new Vec2d(1, 4)); super(id, Textures.TILE_TREE, new Vec2d(1, 4));
@ -19,8 +16,8 @@ public class TileTree extends TileVertical
} }
@Override @Override
public Vec3d getLightDissipation(TileState state) { public double getLightDissipation(TileState state) {
return light_dissipation; return 1/2.0;
} }

View File

@ -24,7 +24,7 @@ public class TileVertical extends Tile implements IHasTexture
@Override @Override
public void render(Vec2d pos, Camera camera, TileState state) { public void render(Vec2d pos, Camera camera, TileState state) {
super.render(pos, camera, state); super.render(pos, camera, state);
GlHelpers.color3(state.light.x, state.light.y, state.light.z); GlHelpers.color3(state.light, state.light, state.light);
VerticalRender.render(pos, camera, tex, size); VerticalRender.render(pos, camera, tex, size);
} }

View File

@ -1,7 +1,6 @@
package shootergame.tiles; package shootergame.tiles;
import shootergame.init.Textures; import shootergame.init.Textures;
import shootergame.util.math.vec.Vec3d;
public class TileWall extends TileFlat public class TileWall extends TileFlat
{ {
@ -13,7 +12,7 @@ public class TileWall extends TileFlat
this.tileSolid = true; this.tileSolid = true;
this.tileHitbox = 1; this.tileHitbox = 1;
this.light_dissipation = new Vec3d(1/4.0, 1/4.0, 1/4.0); this.light_dissipation = 1;
} }
} }

View File

@ -0,0 +1,28 @@
package shootergame.time;
import mainloop.task.IMainloopTask;
public class GameTimer implements IMainloopTask
{
private static long time;
public static long getTime() {
return time;
}
@Override
public boolean MainLoopDelay(long millis) {
return millis > 1;
}
@Override
public boolean MainLoopRepeat() {
return true;
}
@Override
public void MainLoopUpdate() {
time += 1;
}
}

View File

@ -95,4 +95,16 @@ public class MathHelpers
p_distance * Math.sin(angle + p_angle), p_distance * Math.sin(angle + p_angle),
p_distance * Math.cos(angle + p_angle)); p_distance * Math.cos(angle + p_angle));
} }
public static double biggest(double a, double b)
{
if(a > b) return a;
else return b;
}
public static double smallest(double a, double b)
{
if(a < b) return a;
else return b;
}
} }

View File

@ -2,7 +2,6 @@ package shootergame.util.math;
import shootergame.init.Tiles; import shootergame.init.Tiles;
import shootergame.tiles.Tile; import shootergame.tiles.Tile;
import shootergame.util.math.vec.Vec3d;
public class TileState public class TileState
{ {
@ -10,7 +9,7 @@ public class TileState
public Tile tile; public Tile tile;
public byte meta; public byte meta;
public Vec3d light = new Vec3d(0, 0, 0); public double light = 0;
public TileState(Tile tile, byte meta) { public TileState(Tile tile, byte meta) {
this.tile = tile; this.tile = tile;
@ -21,15 +20,9 @@ public class TileState
this(tile, (byte)meta); this(tile, (byte)meta);
} }
public TileState withLightLevel(Vec3d light) { public TileState withLightLevel(double level) {
TileState ts = new TileState(tile, meta); TileState ts = new TileState(tile, meta);
ts.light = light; ts.light = level;
return ts;
}
public TileState withLightLevel(int r, int g, int b) {
TileState ts = new TileState(tile, meta);
ts.light = new Vec3d(r, g, b);
return ts; return ts;
} }

View File

@ -49,8 +49,6 @@ public class Vec2d
{ {
double dx = MathHelpers.positive(other.x - x); double dx = MathHelpers.positive(other.x - x);
double dy = MathHelpers.positive(other.y - y); double dy = MathHelpers.positive(other.y - y);
return MathHelpers.biggest(dx, dy);
if(dx > dy) return dx;
else return dy;
} }
} }

View File

@ -71,12 +71,10 @@ public class Vec2i
return new Vec2i(x, y); return new Vec2i(x, y);
} }
public int squareDistance(Vec2i other) public double squareDistance(Vec2i other)
{ {
int dx = MathHelpers.positive(other.x - x); int dx = MathHelpers.positive(other.x - x);
int dy = MathHelpers.positive(other.y - y); int dy = MathHelpers.positive(other.y - y);
return MathHelpers.biggest(dx, dy);
if(dx > dy) return dx;
else return dy;
} }
} }

View File

@ -19,10 +19,12 @@ public class World
long seed = rand.nextLong(); long seed = rand.nextLong();
// Loop over the layer generators // Loop over the layer generators
int id = 0;
for(LayerGen lg : layergen) for(LayerGen lg : layergen)
{ {
// Create new layers // Create new layers
layers.add(new Layer(new Random(seed), lg)); layers.add(new Layer(new Random(seed), lg, id));
id += 1;
} }
// Set the current layer // Set the current layer

View File

@ -14,7 +14,6 @@ import shootergame.util.math.TileState;
import shootergame.util.math.range.Range2i; import shootergame.util.math.range.Range2i;
import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2d;
import shootergame.util.math.vec.Vec2i; import shootergame.util.math.vec.Vec2i;
import shootergame.util.math.vec.Vec3d;
import shootergame.world.layer.Layer; import shootergame.world.layer.Layer;
public class Chunk public class Chunk
@ -28,9 +27,7 @@ public class Chunk
private Tile tiles_front[] = new Tile[CHUNK_INDEX]; private Tile tiles_front[] = new Tile[CHUNK_INDEX];
private byte tiles_front_meta[] = new byte[CHUNK_INDEX]; private byte tiles_front_meta[] = new byte[CHUNK_INDEX];
private byte tiles_back_meta[] = new byte[CHUNK_INDEX]; private byte tiles_back_meta[] = new byte[CHUNK_INDEX];
private byte tiles_lighting_r[] = new byte[CHUNK_INDEX]; private byte tiles_lighting[] = new byte[CHUNK_INDEX];
private byte tiles_lighting_g[] = new byte[CHUNK_INDEX];
private byte tiles_lighting_b[] = new byte[CHUNK_INDEX];
public ArrayList<Entity> entities = new ArrayList<Entity>(); public ArrayList<Entity> entities = new ArrayList<Entity>();
private Layer layer; private Layer layer;
private Vec2i c_pos; private Vec2i c_pos;
@ -51,10 +48,8 @@ public class Chunk
tiles_front_meta[i] = 0; tiles_front_meta[i] = 0;
// Set the light level // Set the light level
Vec3d light_level = layer.layergen.getLightLevel(); double light_level = layer.layergen.getLightLevel();
tiles_lighting_r[i] = (byte)(light_level.x*Byte.MAX_VALUE); tiles_lighting[i] = (byte)(light_level*Byte.MAX_VALUE);
tiles_lighting_g[i] = (byte)(light_level.y*Byte.MAX_VALUE);
tiles_lighting_b[i] = (byte)(light_level.z*Byte.MAX_VALUE);
} }
} }
@ -183,9 +178,7 @@ public class Chunk
{ {
// Send back the back tile // Send back the back tile
TileState ts = new TileState(this.tiles_back[id], this.tiles_back_meta[id]); TileState ts = new TileState(this.tiles_back[id], this.tiles_back_meta[id]);
ts.light.x = this.tiles_lighting_r[id] / (double) Byte.MAX_VALUE; ts.light = this.tiles_lighting[id] / (double) Byte.MAX_VALUE;
ts.light.y = this.tiles_lighting_g[id] / (double) Byte.MAX_VALUE;
ts.light.z = this.tiles_lighting_b[id] / (double) Byte.MAX_VALUE;
return ts; return ts;
} }
@ -204,9 +197,7 @@ public class Chunk
{ {
// Send back the front tile // Send back the front tile
TileState ts = new TileState(this.tiles_front[id], this.tiles_front_meta[id]); TileState ts = new TileState(this.tiles_front[id], this.tiles_front_meta[id]);
ts.light.x = this.tiles_lighting_r[id] / (double) Byte.MAX_VALUE; ts.light = this.tiles_lighting[id] / (double) Byte.MAX_VALUE;
ts.light.y = this.tiles_lighting_g[id] / (double) Byte.MAX_VALUE;
ts.light.z = this.tiles_lighting_b[id] / (double) Byte.MAX_VALUE;
return ts; return ts;
} }
@ -222,14 +213,11 @@ public class Chunk
} }
} }
public Vec3d getLightLevel(int id) { public double getLightLevel(int id) {
return new Vec3d( return tiles_lighting[id] / (double)Byte.MAX_VALUE;
this.tiles_lighting_r[id] / (double)Byte.MAX_VALUE,
this.tiles_lighting_g[id] / (double)Byte.MAX_VALUE,
this.tiles_lighting_b[id] / (double)Byte.MAX_VALUE);
} }
public Vec3d getLightLevel(Vec2i pos) public double getLightLevel(Vec2i pos)
{ {
// Get the id // Get the id
Vec2i cpos = new Vec2i(0, 0); Vec2i cpos = new Vec2i(0, 0);
@ -240,13 +228,11 @@ public class Chunk
return getLightLevel(id); return getLightLevel(id);
} }
public void setLightLevel(Vec3d light, int id) { public void setLightLevel(double light, int id) {
this.tiles_lighting_r[id] = (byte)(light.x * Byte.MAX_VALUE); this.tiles_lighting[id] = (byte)(light * Byte.MAX_VALUE);
this.tiles_lighting_g[id] = (byte)(light.y * Byte.MAX_VALUE);
this.tiles_lighting_b[id] = (byte)(light.z * Byte.MAX_VALUE);
} }
public void setLightLevel(Vec3d light, Vec2i pos) public void setLightLevel(double light, Vec2i pos)
{ {
// Get the id // Get the id
Vec2i cpos = new Vec2i(0, 0); Vec2i cpos = new Vec2i(0, 0);

View File

@ -7,7 +7,6 @@ import shootergame.entity.Entity;
import shootergame.util.math.TileState; import shootergame.util.math.TileState;
import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2d;
import shootergame.util.math.vec.Vec2i; import shootergame.util.math.vec.Vec2i;
import shootergame.util.math.vec.Vec3d;
public class ChunkEmpty extends Chunk public class ChunkEmpty extends Chunk
{ {
@ -73,21 +72,21 @@ public class ChunkEmpty extends Chunk
} }
@Override @Override
public Vec3d getLightLevel(int id) { public double getLightLevel(int id) {
return new Vec3d(0, 0, 0); return 0;
} }
@Override @Override
public Vec3d getLightLevel(Vec2i pos) { public double getLightLevel(Vec2i pos) {
return new Vec3d(0, 0, 0); return 0;
} }
@Override @Override
public void setLightLevel(Vec3d light, int id) { public void setLightLevel(double light, int id) {
} }
@Override @Override
public void setLightLevel(Vec3d light, Vec2i pos) { public void setLightLevel(double light, Vec2i pos) {
} }
@Override @Override

View File

@ -12,7 +12,6 @@ import shootergame.util.math.map.Map2D;
import shootergame.util.math.map.Map2DElement; import shootergame.util.math.map.Map2DElement;
import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2d;
import shootergame.util.math.vec.Vec2i; import shootergame.util.math.vec.Vec2i;
import shootergame.util.math.vec.Vec3d;
import shootergame.world.chunk.Chunk; import shootergame.world.chunk.Chunk;
import shootergame.world.layer.layergen.LayerGen; import shootergame.world.layer.layergen.LayerGen;
@ -22,14 +21,16 @@ public class Layer
public LayerGen layergen; public LayerGen layergen;
private Random rand; private Random rand;
private long seed; private long seed;
public int id;
public Layer(Random rand, LayerGen layergen) public Layer(Random rand, LayerGen layergen, int id)
{ {
// Create the array of tiles // Create the array of tiles
this.layergen = layergen; this.layergen = layergen;
this.seed = rand.nextLong(); this.seed = rand.nextLong();
this.rand = new Random(); this.rand = new Random();
this.chunks = new Map2D<Chunk>(layergen); this.chunks = new Map2D<Chunk>(layergen);
this.id = id;
} }
public void render(Camera camera) public void render(Camera camera)
@ -118,7 +119,7 @@ public class Layer
MathHelpers.floor(pos.y / (double)Chunk.CHUNK_SIZE.my)); MathHelpers.floor(pos.y / (double)Chunk.CHUNK_SIZE.my));
} }
public Vec3d getLightLevel(Vec2i pos) public double getLightLevel(Vec2i pos)
{ {
// Get the chunk pos // Get the chunk pos
Vec2i c_pos = getChunkPosFromPos(pos); Vec2i c_pos = getChunkPosFromPos(pos);
@ -127,7 +128,7 @@ public class Layer
return chunks.get(c_pos).getLightLevel(pos); return chunks.get(c_pos).getLightLevel(pos);
} }
public void setLightLevel(Vec3d light, Vec2i pos) public void setLightLevel(double light, Vec2i pos)
{ {
// Get the chunk pos // Get the chunk pos
Vec2i c_pos = getChunkPosFromPos(pos); Vec2i c_pos = getChunkPosFromPos(pos);

View File

@ -5,7 +5,6 @@ import java.util.Random;
import shootergame.util.math.TileState; import shootergame.util.math.TileState;
import shootergame.util.math.map.IMap2D; import shootergame.util.math.map.IMap2D;
import shootergame.util.math.vec.Vec2i; import shootergame.util.math.vec.Vec2i;
import shootergame.util.math.vec.Vec3d;
import shootergame.world.chunk.Chunk; import shootergame.world.chunk.Chunk;
import shootergame.world.layer.Layer; import shootergame.world.layer.Layer;
@ -14,7 +13,7 @@ public abstract class LayerGen implements IMap2D<Chunk>
public abstract void generateChunk(Chunk chunk, Layer layer, long seed, Random rand, Vec2i pos); public abstract void generateChunk(Chunk chunk, Layer layer, long seed, Random rand, Vec2i pos);
public abstract void spawnEntities(Layer layer, Random rand); public abstract void spawnEntities(Layer layer, Random rand);
public abstract TileState getTileDestroyed(); public abstract TileState getTileDestroyed();
public abstract Vec3d getLightLevel(); public abstract double getLightLevel();
@Override @Override
public Chunk getEmpty(Vec2i pos) { public Chunk getEmpty(Vec2i pos) {

View File

@ -12,7 +12,6 @@ import shootergame.util.math.random.OpenSimplexNoise;
import shootergame.util.math.random.RandomHelpers; import shootergame.util.math.random.RandomHelpers;
import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2d;
import shootergame.util.math.vec.Vec2i; import shootergame.util.math.vec.Vec2i;
import shootergame.util.math.vec.Vec3d;
import shootergame.world.chunk.Chunk; import shootergame.world.chunk.Chunk;
import shootergame.world.layer.Layer; import shootergame.world.layer.Layer;
@ -23,21 +22,21 @@ public class LayerGenCaves extends LayerGen
public void generateChunk(Chunk chunk, Layer layer, long seed, Random rand, Vec2i c_pos) public void generateChunk(Chunk chunk, Layer layer, long seed, Random rand, Vec2i c_pos)
{ {
// Is there going to be a portal up in this chunk // Is there going to be a portal up in this chunk
boolean portal = RandomHelpers.randrange(rand, 10) == 0; boolean portal = PortalSpawnrates.WorldCavePortal(rand);
Vec2i portal_pos = null; Vec2i portal_pos = null;
if(portal) portal_pos = new Vec2i( if(portal) portal_pos = new Vec2i(
RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.mx), RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.mx),
RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.my)); RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.my));
// Is there going to be a portal down in this chunk // Is there going to be a portal down in this chunk
boolean portal_down = RandomHelpers.randrange(rand, 10) == 0; boolean portal_down = PortalSpawnrates.CaveLavaCavePortal(rand);
Vec2i portal_down_pos = null; Vec2i portal_down_pos = null;
if(portal_down) portal_down_pos = new Vec2i( if(portal_down) portal_down_pos = new Vec2i(
RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.mx), RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.mx),
RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.my)); RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.my));
// Get some noise generators // Get some noise generators
OpenSimplexNoise noisegen_n = new OpenSimplexNoise(seed); OpenSimplexNoise noisegen_n = new OpenSimplexNoise(new Random(seed + layer.id).nextLong());
// Loop over the chunk // Loop over the chunk
for(int x=0;x<Chunk.CHUNK_SIZE.mx;x++) { for(int x=0;x<Chunk.CHUNK_SIZE.mx;x++) {
@ -115,8 +114,8 @@ public class LayerGenCaves extends LayerGen
} }
@Override @Override
public Vec3d getLightLevel() { public double getLightLevel() {
return new Vec3d(0, 0, 0); return 0;
} }
} }

View File

@ -11,7 +11,6 @@ import shootergame.util.math.random.OpenSimplexNoise;
import shootergame.util.math.random.RandomHelpers; import shootergame.util.math.random.RandomHelpers;
import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2d;
import shootergame.util.math.vec.Vec2i; import shootergame.util.math.vec.Vec2i;
import shootergame.util.math.vec.Vec3d;
import shootergame.world.chunk.Chunk; import shootergame.world.chunk.Chunk;
import shootergame.world.layer.Layer; import shootergame.world.layer.Layer;
@ -22,14 +21,14 @@ public class LayerGenEarth extends LayerGen
public void generateChunk(Chunk chunk, Layer layer, long seed, Random rand, Vec2i c_pos) public void generateChunk(Chunk chunk, Layer layer, long seed, Random rand, Vec2i c_pos)
{ {
// Is there going to be a portal in this chunk // Is there going to be a portal in this chunk
boolean portal = RandomHelpers.randrange(rand, 10) == 0; boolean portal = PortalSpawnrates.WorldCavePortal(rand);
Vec2i portal_pos = null; Vec2i portal_pos = null;
if(portal) portal_pos = new Vec2i( if(portal) portal_pos = new Vec2i(
RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.mx), RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.mx),
RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.my)); RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.my));
// Get the noise generator // Get the noise generator
OpenSimplexNoise noisegen_n = new OpenSimplexNoise(seed); OpenSimplexNoise noisegen_n = new OpenSimplexNoise(new Random(seed + layer.id).nextLong());
// Loop over the layer dimensions and create land // Loop over the layer dimensions and create land
for(int x=0;x<Chunk.CHUNK_SIZE.mx;x++) { for(int x=0;x<Chunk.CHUNK_SIZE.mx;x++) {
@ -88,7 +87,7 @@ public class LayerGenEarth extends LayerGen
} }
@Override @Override
public Vec3d getLightLevel() { public double getLightLevel() {
return new Vec3d(0.3, 0.3, 0.3); return 0.3;
} }
} }

View File

@ -4,8 +4,9 @@ import java.util.Random;
import shootergame.init.Tiles; import shootergame.init.Tiles;
import shootergame.util.math.TileState; import shootergame.util.math.TileState;
import shootergame.util.math.random.OpenSimplexNoise;
import shootergame.util.math.random.RandomHelpers;
import shootergame.util.math.vec.Vec2i; import shootergame.util.math.vec.Vec2i;
import shootergame.util.math.vec.Vec3d;
import shootergame.world.chunk.Chunk; import shootergame.world.chunk.Chunk;
import shootergame.world.layer.Layer; import shootergame.world.layer.Layer;
@ -15,8 +16,56 @@ public class LayerGenLavaCaves extends LayerGen
@Override @Override
public void generateChunk(Chunk chunk, Layer layer, long seed, Random rand, Vec2i pos) public void generateChunk(Chunk chunk, Layer layer, long seed, Random rand, Vec2i pos)
{ {
// TODO Auto-generated method stub // Make sure the random generated is the same
if(PortalSpawnrates.WorldCavePortal(rand)) {
rand.nextDouble();
rand.nextDouble();
}
boolean hasLadder = PortalSpawnrates.CaveLavaCavePortal(rand);
Vec2i ladder_pos = null;
if(hasLadder) {
ladder_pos = new Vec2i(
RandomHelpers.randrange(rand, 16),
RandomHelpers.randrange(rand, 16));
}
// Get some noise generators
OpenSimplexNoise noisegen_n = new OpenSimplexNoise(new Random(seed + layer.id).nextLong());
// Loop over the chunk
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 + pos.x * Chunk.CHUNK_SIZE.mx;
int cy = y + 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 tpos = new Vec2i(x, y);
if(noise_n > 40) {
chunk.setBackTile(Tiles.STONE.getDefaultState(), tpos);
}
else {
chunk.setBackTile(Tiles.WALL.getDefaultState(), tpos);
}
if(noise_n > 55 && noise_n < 60) {
chunk.setFrontTile(Tiles.LAVA_FLOW.getDefaultState(), tpos);
}
else if(noise_n > 60) {
chunk.setFrontTile(Tiles.LAVA.getDefaultState(), tpos);
}
}
}
if(hasLadder) {
chunk.setFrontTile(new TileState(Tiles.LADDER_UP, (short)1), ladder_pos);
}
} }
@Override @Override
@ -26,12 +75,12 @@ public class LayerGenLavaCaves extends LayerGen
@Override @Override
public TileState getTileDestroyed() { public TileState getTileDestroyed() {
return Tiles.LAVA.getDefaultState(); return Tiles.STONE.getDefaultState();
} }
@Override @Override
public Vec3d getLightLevel() { public double getLightLevel() {
return new Vec3d(0.1, 0.1, 0.1); return 0.1;
} }
} }

View File

@ -0,0 +1,16 @@
package shootergame.world.layer.layergen;
import java.util.Random;
import shootergame.util.math.random.RandomHelpers;
class PortalSpawnrates
{
static boolean WorldCavePortal(Random rand) {
return RandomHelpers.randrange(rand, 2) == 0;
}
static boolean CaveLavaCavePortal(Random rand) {
return RandomHelpers.randrange(rand, 2) == 0;
}
}