diff --git a/_resources/sound/gun.ogg b/_resources/sound/gun.ogg deleted file mode 100644 index 2e43705..0000000 Binary files a/_resources/sound/gun.ogg and /dev/null differ diff --git a/_resources/texmap.png b/_resources/texmap.png deleted file mode 100644 index fb2115b..0000000 Binary files a/_resources/texmap.png and /dev/null differ diff --git a/_resources/texmap.xcf b/_resources/texmap.xcf deleted file mode 100644 index 14cfff1..0000000 Binary files a/_resources/texmap.xcf and /dev/null differ diff --git a/src/shootergame/Main.java b/src/shootergame/Main.java index 0bde9e9..475fbce 100644 --- a/src/shootergame/Main.java +++ b/src/shootergame/Main.java @@ -17,10 +17,12 @@ import shootergame.input.JoystickCallback; import shootergame.mainloop.MainloopEventHandler; import shootergame.menu.Menu; import shootergame.menu.MenuNone; +import shootergame.time.GameTimer; import shootergame.world.World; import shootergame.world.chunk.ChunkEventHandler; import shootergame.world.layer.layergen.LayerGenCaves; import shootergame.world.layer.layergen.LayerGenEarth; +import shootergame.world.layer.layergen.LayerGenLavaCaves; public class Main { @@ -55,6 +57,7 @@ public class Main mainloop.register(ChunkEventHandler.CHUNK_EVENT_HANDLER); mainloop.register(DisplayStatsEventHandler.DISPLAY_STATS_EVENT_HANDLER); mainloop.register(JoystickCallback.JOYSTICK_CALLBACK); + mainloop.register(new GameTimer()); // Create the display window = new DisplayWindow("ShooterGame"); @@ -67,7 +70,7 @@ public class Main JoystickCallback.JOYSTICK_CALLBACK.init(); // 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 mainloop.register(EntityEventHandler.ENTITY_EVENT_HANDLER); diff --git a/src/shootergame/display/lighting/LightingManager.java b/src/shootergame/display/lighting/LightingManager.java index 84a1ce1..206c485 100644 --- a/src/shootergame/display/lighting/LightingManager.java +++ b/src/shootergame/display/lighting/LightingManager.java @@ -6,27 +6,17 @@ import shootergame.entity.Entity; import shootergame.entity.player.EntityPlayer; import shootergame.util.math.MathHelpers; import shootergame.util.math.TileState; -import shootergame.util.math.map.Map2DElement; import shootergame.util.math.vec.Vec2i; -import shootergame.util.math.vec.Vec3d; import shootergame.world.chunk.Chunk; import shootergame.world.layer.Layer; public class LightingManager { - @Deprecated - public static void markDirty() { - } - public static void update() { - // Do nothing if nothing has changed - //if(!isDirty) return; - //isDirty = false; - int r = Camera.camera.renderDistance; Layer layer = Main.world.getLayer(); - Vec3d light_clear = layer.layergen.getLightLevel(); + double light_clear = layer.layergen.getLightLevel(); EntityPlayer player = Main.player; // 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 - for(Map2DElement mce : layer.chunks) - { - if(mce.pos.squareDistance(new Vec2i((int)(player.pos.x/16), (int)(player.pos.y/16))) < r) + for(int cx=-r;cx light_tile.x) light_tile.x = ftsl.x; - if(ftsl.y > light_tile.y) light_tile.y = ftsl.y; - 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; + double light_tile = chunk.getLightLevel(tid); + double light_tile2 = light_tile; + double ftsl = fts.tile.getLightLevel(fts); + double btsl = fts.tile.getLightLevel(bts); + if(ftsl > light_tile) light_tile = ftsl; + if(btsl > light_tile) light_tile = btsl; // Has the light level changed; add light to this tile - if(!light_tile.equal(light_tile2)) { - addLightToTiles(layer, tpos, light_tile); + if(light_tile != light_tile2) { + addLightToTiles(layer, tpos, light_tile, true); } } } @@ -99,11 +85,11 @@ public class LightingManager addLightToTiles(layer, new Vec2i( MathHelpers.floor(player.pos.x), 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 int lid = lpos.getId(Chunk.CHUNK_SIZE); @@ -112,36 +98,25 @@ public class LightingManager Chunk chunk = layer.getChunk(lpos); TileState bt = chunk.getBackTile(lid); TileState ft = chunk.getFrontTile(lid); - Vec3d light_dissipation = bt.tile.getLightDissipation(bt); - 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; + double light_dissipation = 0; - // Set the light dissipation - light = light.subtract(light_dissipation); - if(light.x < 0) light.x = 0; - if(light.y < 0) light.y = 0; - if(light.z < 0) light.z = 0; - - if(light.x == 0 && light.y == 0 && light.z == 0) { - return; + if(!ignoreDissipation) { + light_dissipation = MathHelpers.biggest( + bt.tile.getLightDissipation(bt), + ft.tile.getLightDissipation(ft)); } // Calculate the light level - Vec3d light_tile = chunk.getLightLevel(lid); - if( - light.x <= light_tile.x && - light.y <= light_tile.y && - light.z <= light_tile.z) { + double light_tile = chunk.getLightLevel(lid); + if(light <= light_tile) { return; } // Merge the light and the light tile values - if(light.x > light_tile.x) light_tile.x = light.x; - if(light.y > light_tile.y) light_tile.y = light.y; - if(light.z > light_tile.z) light_tile.z = light.z; - chunk.setLightLevel(light_tile, lid); + chunk.setLightLevel(light, lid); + + // Set the light dissipation + light = light - light_dissipation; // Get all the adjacent positions of the light tiles to flow onto Vec2i positions[] = { @@ -153,7 +128,7 @@ public class LightingManager // Add the light to all the adjacent positions for(Vec2i position : positions) { - addLightToTiles(layer, position, light); + addLightToTiles(layer, position, light, false); } } } diff --git a/src/shootergame/entity/Entity.java b/src/shootergame/entity/Entity.java index 6a721c8..23f6c62 100644 --- a/src/shootergame/entity/Entity.java +++ b/src/shootergame/entity/Entity.java @@ -12,7 +12,6 @@ import shootergame.util.math.MathHelpers; import shootergame.util.math.TileState; import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2i; -import shootergame.util.math.vec.Vec3d; import shootergame.world.chunk.Chunk; import shootergame.world.layer.Layer; @@ -217,7 +216,7 @@ public class Entity implements ITransparentObject return new Vec2d(0, 0); } - public Vec3d getLightLevel() { - return new Vec3d(0, 0, 0); + public double getLightLevel() { + return 0; } } diff --git a/src/shootergame/entity/EntityBullet.java b/src/shootergame/entity/EntityBullet.java index ec5dabe..071a0e3 100644 --- a/src/shootergame/entity/EntityBullet.java +++ b/src/shootergame/entity/EntityBullet.java @@ -116,9 +116,9 @@ public class EntityBullet extends EntityParticle public void render(Vec2d pos, Camera camera) { // Set the colour - Vec3d light = chunk.getLightLevel(new Vec2i( + double light = chunk.getLightLevel(new Vec2i( 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 super.render(pos, camera); diff --git a/src/shootergame/entity/EntityVertical.java b/src/shootergame/entity/EntityVertical.java index 569610d..3636c2d 100644 --- a/src/shootergame/entity/EntityVertical.java +++ b/src/shootergame/entity/EntityVertical.java @@ -7,7 +7,6 @@ import shootergame.util.gl.texture.TextureReference; import shootergame.util.math.MathHelpers; import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2i; -import shootergame.util.math.vec.Vec3d; public class EntityVertical extends Entity { @@ -26,10 +25,9 @@ public class EntityVertical extends Entity @Override 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))); - GlHelpers.color3(light.x, light.y, light.z); + GlHelpers.color3(light, light, light); this.render(pos, camera, tex, size); - GlHelpers.color3(1, 1, 1); } } diff --git a/src/shootergame/entity/particle/ParticleBlood.java b/src/shootergame/entity/particle/ParticleBlood.java index 7309fc6..c22f57a 100644 --- a/src/shootergame/entity/particle/ParticleBlood.java +++ b/src/shootergame/entity/particle/ParticleBlood.java @@ -9,7 +9,6 @@ import shootergame.util.math.MathHelpers; import shootergame.util.math.random.RandomHelpers; import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2i; -import shootergame.util.math.vec.Vec3d; import shootergame.world.chunk.Chunk; import shootergame.world.layer.Layer; @@ -61,12 +60,12 @@ public class ParticleBlood extends EntityParticle public void render(Vec2d pos, Camera camera) { // Get the light level - Vec3d light = chunk.getLightLevel(new Vec2i( + double light = chunk.getLightLevel(new Vec2i( MathHelpers.floor(pos.x), MathHelpers.floor(pos.y))); // Set some settings GlHelpers.pushMatrix(); - GlHelpers.color3(r_color * light.x, 0, 0); + GlHelpers.color3(r_color * light, 0, 0); GlHelpers.translate(0, 0, height); // Call super diff --git a/src/shootergame/entity/particle/ParticleBreak.java b/src/shootergame/entity/particle/ParticleBreak.java index 1640618..02a02db 100644 --- a/src/shootergame/entity/particle/ParticleBreak.java +++ b/src/shootergame/entity/particle/ParticleBreak.java @@ -11,7 +11,6 @@ import shootergame.util.math.TileState; import shootergame.util.math.random.RandomHelpers; import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2i; -import shootergame.util.math.vec.Vec3d; import shootergame.world.chunk.Chunk; import shootergame.world.layer.Layer; @@ -69,13 +68,12 @@ public class ParticleBreak extends EntityVertical @Override 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))); - GlHelpers.color3(light.x, light.y, light.z); + GlHelpers.color3(light, light, light); GlHelpers.pushMatrix(); GlHelpers.translate(0, 0, height); super.render(pos, camera, tex, size); - GlHelpers.color3(1, 1, 1); GlHelpers.popMatrix(); } } diff --git a/src/shootergame/entity/particle/ParticleSmoke.java b/src/shootergame/entity/particle/ParticleSmoke.java index 7da3bb9..cfbc42b 100644 --- a/src/shootergame/entity/particle/ParticleSmoke.java +++ b/src/shootergame/entity/particle/ParticleSmoke.java @@ -9,7 +9,6 @@ import shootergame.util.math.MathHelpers; import shootergame.util.math.random.RandomHelpers; import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2i; -import shootergame.util.math.vec.Vec3d; import shootergame.world.chunk.Chunk; import shootergame.world.layer.Layer; @@ -36,9 +35,9 @@ public class ParticleSmoke extends EntityVertical if(opacity <= 0) return; GlHelpers.pushMatrix(); 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))); - GlHelpers.color4(light.x, light.y, light.z, opacity); + GlHelpers.color4(light, light, light, opacity); super.render(pos, camera); GlHelpers.color4(1, 1, 1, 1); GlHelpers.popMatrix(); diff --git a/src/shootergame/entity/particle/ParticleWater.java b/src/shootergame/entity/particle/ParticleWater.java index 7790a2f..ed623b0 100644 --- a/src/shootergame/entity/particle/ParticleWater.java +++ b/src/shootergame/entity/particle/ParticleWater.java @@ -49,9 +49,9 @@ public class ParticleWater extends EntityParticle public void render(Vec2d pos, Camera camera) { GlHelpers.pushMatrix(); 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))); - GlHelpers.color4(0, 0, light.z, 0.4); + GlHelpers.color4(0, 0, light, 0.4); super.render(pos, camera); GlHelpers.color4(1, 1, 1, 1); GlHelpers.popMatrix(); diff --git a/src/shootergame/entity/player/EntityPlayer.java b/src/shootergame/entity/player/EntityPlayer.java index d96d14a..2071eb8 100644 --- a/src/shootergame/entity/player/EntityPlayer.java +++ b/src/shootergame/entity/player/EntityPlayer.java @@ -17,7 +17,6 @@ import shootergame.util.math.ItemStack; import shootergame.util.math.MathHelpers; import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2i; -import shootergame.util.math.vec.Vec3d; import shootergame.world.chunk.Chunk; import shootergame.world.layer.Layer; @@ -64,13 +63,15 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI } @Override - public Vec3d getLightLevel() { - return new Vec3d(1, 1, 1); + public double getLightLevel() { + return 1; } @Override public void tick(Chunk chunk, Layer layer) { + Cheats.god_mode = true; + // Handle player deaths if(health <= 0) { @@ -90,9 +91,6 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI // Call super super.tick(chunk, layer); - // Regen some of the players health - //this.addHealth(0.1); - // Rotate left if(MOVE_LEFT) { this.angle -= 1; @@ -157,9 +155,9 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI GlHelpers.translate(0, 0, height); // 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))); - GlHelpers.color3(light.x, light.y, light.z); + GlHelpers.color3(light, light, light); // Moving if(MOVE_BACKWARD || MOVE_FORWARD || moving) diff --git a/src/shootergame/input/KeyCallback.java b/src/shootergame/input/KeyCallback.java index a27152b..da36414 100644 --- a/src/shootergame/input/KeyCallback.java +++ b/src/shootergame/input/KeyCallback.java @@ -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(pressed) { if(!esc_last) { diff --git a/src/shootergame/tiles/LavaLightlevel.java b/src/shootergame/tiles/LavaLightlevel.java new file mode 100644 index 0000000..b74e260 --- /dev/null +++ b/src/shootergame/tiles/LavaLightlevel.java @@ -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); + } +} diff --git a/src/shootergame/tiles/Tile.java b/src/shootergame/tiles/Tile.java index 49e5a24..e7fab88 100644 --- a/src/shootergame/tiles/Tile.java +++ b/src/shootergame/tiles/Tile.java @@ -7,7 +7,6 @@ import shootergame.entity.Entity; import shootergame.util.math.TileState; import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2i; -import shootergame.util.math.vec.Vec3d; import shootergame.world.chunk.Chunk; import shootergame.world.layer.Layer; @@ -20,7 +19,7 @@ public class Tile implements ITransparentObject public double tileHitbox = 0; public double slowness = 0; 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 Tile(String id) { @@ -66,11 +65,11 @@ public class Tile implements ITransparentObject public void onActivated(Layer layer, Vec2i tpos, Entity entity, TileState state) { } - public Vec3d getLightDissipation(TileState state) { + public double getLightDissipation(TileState state) { return light_dissipation; } - public Vec3d getLightLevel(TileState state) { - return new Vec3d(0, 0, 0); + public double getLightLevel(TileState state) { + return 0; } } diff --git a/src/shootergame/tiles/TileFlat.java b/src/shootergame/tiles/TileFlat.java index 39655d5..7875f56 100644 --- a/src/shootergame/tiles/TileFlat.java +++ b/src/shootergame/tiles/TileFlat.java @@ -25,7 +25,7 @@ public class TileFlat extends Tile implements IHasTexture super.render(pos, camera, state); // 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(); 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); diff --git a/src/shootergame/tiles/TileLadder.java b/src/shootergame/tiles/TileLadder.java index a7db05a..58d47f2 100644 --- a/src/shootergame/tiles/TileLadder.java +++ b/src/shootergame/tiles/TileLadder.java @@ -1,6 +1,7 @@ package shootergame.tiles; import shootergame.init.Textures; +import shootergame.util.math.TileState; import shootergame.util.math.vec.Vec2d; public class TileLadder extends TileVertical @@ -13,6 +14,12 @@ public class TileLadder extends TileVertical this.tileSolid = true; this.tileHitbox = 0.3; this.unbreakable = true; + this.emitsLight = true; + } + + @Override + public double getLightLevel(TileState state) { + return 0.5; } } diff --git a/src/shootergame/tiles/TileLadderUp.java b/src/shootergame/tiles/TileLadderUp.java index ced55a9..9052612 100644 --- a/src/shootergame/tiles/TileLadderUp.java +++ b/src/shootergame/tiles/TileLadderUp.java @@ -5,9 +5,11 @@ import shootergame.Main; import shootergame.entity.Entity; import shootergame.entity.player.EntityPlayer; import shootergame.init.Textures; +import shootergame.mainloop.MainloopEventHandler; import shootergame.util.math.TileState; import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2i; +import shootergame.world.chunk.ChunkEventHandler; import shootergame.world.layer.Layer; public class TileLadderUp extends TileVertical @@ -50,7 +52,7 @@ public class TileLadderUp extends TileVertical player.height += 0.04; } - if(movingPlayer == 1) { + else if(movingPlayer == 2) { player.height += 0.02; } @@ -61,9 +63,15 @@ public class TileLadderUp extends TileVertical player.height = -1; } - if(player.height >= 0 && movingPlayer == 1) + else if(movingPlayer == 1 && ChunkEventHandler.loaded) { movingPlayer = 2; + MainloopEventHandler.MAINLOOP_EVENT_HANDLER.mspf = 1000/60; + } + + else if(player.height >= 0 && movingPlayer == 2) + { + movingPlayer = 3; player.height = 0; player.moving = false; player.in_animation = false; @@ -72,7 +80,7 @@ public class TileLadderUp extends TileVertical @Override public boolean MainLoopRepeat() { - return movingPlayer != 2; + return movingPlayer != 3; } @Override diff --git a/src/shootergame/tiles/TileLava.java b/src/shootergame/tiles/TileLava.java index e24166a..04e7b9c 100644 --- a/src/shootergame/tiles/TileLava.java +++ b/src/shootergame/tiles/TileLava.java @@ -13,6 +13,7 @@ public class TileLava extends TileFlat super(id, Textures.TILE_LAVA); this.tileWalkable = false; + this.emitsLight = true; } @Override @@ -22,5 +23,10 @@ public class TileLava extends TileFlat super.render(pos, camera, state); GlHelpers.popMatrix(); } + + @Override + public double getLightLevel(TileState state) { + return LavaLightlevel.getLightLevel(); + } } diff --git a/src/shootergame/tiles/TileLavaFlow.java b/src/shootergame/tiles/TileLavaFlow.java index dc4ece5..cb0a5b2 100644 --- a/src/shootergame/tiles/TileLavaFlow.java +++ b/src/shootergame/tiles/TileLavaFlow.java @@ -11,6 +11,8 @@ public class TileLavaFlow extends TileFlat public TileLavaFlow(String id) { super(id, Textures.TILE_LAVA_FLOW); + + this.emitsLight = true; } @Override @@ -20,5 +22,10 @@ public class TileLavaFlow extends TileFlat super.render(pos, camera, state); GlHelpers.popMatrix(); } + + @Override + public double getLightLevel(TileState state) { + return LavaLightlevel.getLightLevel(); + } } diff --git a/src/shootergame/tiles/TilePortalDown.java b/src/shootergame/tiles/TilePortalDown.java index 3c25dad..70aa07f 100644 --- a/src/shootergame/tiles/TilePortalDown.java +++ b/src/shootergame/tiles/TilePortalDown.java @@ -5,6 +5,7 @@ import shootergame.Main; import shootergame.entity.Entity; import shootergame.entity.player.EntityPlayer; import shootergame.init.Textures; +import shootergame.mainloop.MainloopEventHandler; import shootergame.util.math.TileState; import shootergame.util.math.vec.Vec2i; import shootergame.world.chunk.ChunkEventHandler; @@ -48,13 +49,21 @@ public class TilePortalDown extends TileFlat player.height -= 0.02; } - if(movingPlayer == 2) { + else if(movingPlayer == 2) { 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; + MainloopEventHandler.MAINLOOP_EVENT_HANDLER.mspf = 1000/60; Vec2i check_poses[] = { new Vec2i( 1, 0), @@ -91,14 +100,7 @@ public class TilePortalDown extends TileFlat } } - if(player.height < -1 && movingPlayer == 0) - { - movingPlayer = 1; - Main.world.setLayerID(state.meta); - player.height = 6; - } - - if(player.height < 0 && movingPlayer == 2) + else if(player.height < 0 && movingPlayer == 2) { movingPlayer = 3; player.height = 0; diff --git a/src/shootergame/tiles/TileTree.java b/src/shootergame/tiles/TileTree.java index 666a291..5964fba 100644 --- a/src/shootergame/tiles/TileTree.java +++ b/src/shootergame/tiles/TileTree.java @@ -3,12 +3,9 @@ package shootergame.tiles; import shootergame.init.Textures; import shootergame.util.math.TileState; import shootergame.util.math.vec.Vec2d; -import shootergame.util.math.vec.Vec3d; 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) { super(id, Textures.TILE_TREE, new Vec2d(1, 4)); @@ -19,8 +16,8 @@ public class TileTree extends TileVertical } @Override - public Vec3d getLightDissipation(TileState state) { - return light_dissipation; + public double getLightDissipation(TileState state) { + return 1/2.0; } diff --git a/src/shootergame/tiles/TileVertical.java b/src/shootergame/tiles/TileVertical.java index 8eeb6c6..f035754 100644 --- a/src/shootergame/tiles/TileVertical.java +++ b/src/shootergame/tiles/TileVertical.java @@ -24,7 +24,7 @@ public class TileVertical extends Tile implements IHasTexture @Override public void render(Vec2d pos, Camera camera, TileState 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); } diff --git a/src/shootergame/tiles/TileWall.java b/src/shootergame/tiles/TileWall.java index 6619090..de30c11 100644 --- a/src/shootergame/tiles/TileWall.java +++ b/src/shootergame/tiles/TileWall.java @@ -1,7 +1,6 @@ package shootergame.tiles; import shootergame.init.Textures; -import shootergame.util.math.vec.Vec3d; public class TileWall extends TileFlat { @@ -13,7 +12,7 @@ public class TileWall extends TileFlat this.tileSolid = true; this.tileHitbox = 1; - this.light_dissipation = new Vec3d(1/4.0, 1/4.0, 1/4.0); + this.light_dissipation = 1; } } diff --git a/src/shootergame/time/GameTimer.java b/src/shootergame/time/GameTimer.java new file mode 100644 index 0000000..805ccb5 --- /dev/null +++ b/src/shootergame/time/GameTimer.java @@ -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; + } +} diff --git a/src/shootergame/util/math/MathHelpers.java b/src/shootergame/util/math/MathHelpers.java index 0a7d41f..ec757de 100644 --- a/src/shootergame/util/math/MathHelpers.java +++ b/src/shootergame/util/math/MathHelpers.java @@ -95,4 +95,16 @@ public class MathHelpers p_distance * Math.sin(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; + } } diff --git a/src/shootergame/util/math/TileState.java b/src/shootergame/util/math/TileState.java index 89aba3c..5fb0010 100644 --- a/src/shootergame/util/math/TileState.java +++ b/src/shootergame/util/math/TileState.java @@ -2,7 +2,6 @@ package shootergame.util.math; import shootergame.init.Tiles; import shootergame.tiles.Tile; -import shootergame.util.math.vec.Vec3d; public class TileState { @@ -10,7 +9,7 @@ public class TileState public Tile tile; public byte meta; - public Vec3d light = new Vec3d(0, 0, 0); + public double light = 0; public TileState(Tile tile, byte meta) { this.tile = tile; @@ -21,15 +20,9 @@ public class TileState this(tile, (byte)meta); } - public TileState withLightLevel(Vec3d light) { + public TileState withLightLevel(double level) { TileState ts = new TileState(tile, meta); - ts.light = light; - return ts; - } - - public TileState withLightLevel(int r, int g, int b) { - TileState ts = new TileState(tile, meta); - ts.light = new Vec3d(r, g, b); + ts.light = level; return ts; } diff --git a/src/shootergame/util/math/vec/Vec2d.java b/src/shootergame/util/math/vec/Vec2d.java index 482cf96..e4995bd 100644 --- a/src/shootergame/util/math/vec/Vec2d.java +++ b/src/shootergame/util/math/vec/Vec2d.java @@ -49,8 +49,6 @@ public class Vec2d { double dx = MathHelpers.positive(other.x - x); double dy = MathHelpers.positive(other.y - y); - - if(dx > dy) return dx; - else return dy; + return MathHelpers.biggest(dx, dy); } } diff --git a/src/shootergame/util/math/vec/Vec2i.java b/src/shootergame/util/math/vec/Vec2i.java index 1b0ed61..1d55d8b 100644 --- a/src/shootergame/util/math/vec/Vec2i.java +++ b/src/shootergame/util/math/vec/Vec2i.java @@ -71,12 +71,10 @@ public class Vec2i return new Vec2i(x, y); } - public int squareDistance(Vec2i other) + public double squareDistance(Vec2i other) { int dx = MathHelpers.positive(other.x - x); int dy = MathHelpers.positive(other.y - y); - - if(dx > dy) return dx; - else return dy; + return MathHelpers.biggest(dx, dy); } } diff --git a/src/shootergame/world/World.java b/src/shootergame/world/World.java index eb85235..9a5fc77 100644 --- a/src/shootergame/world/World.java +++ b/src/shootergame/world/World.java @@ -19,10 +19,12 @@ public class World long seed = rand.nextLong(); // Loop over the layer generators + int id = 0; for(LayerGen lg : layergen) { // 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 diff --git a/src/shootergame/world/chunk/Chunk.java b/src/shootergame/world/chunk/Chunk.java index 62a15b1..bac39df 100644 --- a/src/shootergame/world/chunk/Chunk.java +++ b/src/shootergame/world/chunk/Chunk.java @@ -14,7 +14,6 @@ import shootergame.util.math.TileState; import shootergame.util.math.range.Range2i; import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2i; -import shootergame.util.math.vec.Vec3d; import shootergame.world.layer.Layer; public class Chunk @@ -28,9 +27,7 @@ public class Chunk private Tile tiles_front[] = new Tile[CHUNK_INDEX]; private byte tiles_front_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_g[] = new byte[CHUNK_INDEX]; - private byte tiles_lighting_b[] = new byte[CHUNK_INDEX]; + private byte tiles_lighting[] = new byte[CHUNK_INDEX]; public ArrayList entities = new ArrayList(); private Layer layer; private Vec2i c_pos; @@ -51,10 +48,8 @@ public class Chunk tiles_front_meta[i] = 0; // Set the light level - Vec3d light_level = layer.layergen.getLightLevel(); - tiles_lighting_r[i] = (byte)(light_level.x*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); + double light_level = layer.layergen.getLightLevel(); + tiles_lighting[i] = (byte)(light_level*Byte.MAX_VALUE); } } @@ -183,9 +178,7 @@ public class Chunk { // Send back the back tile 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.y = this.tiles_lighting_g[id] / (double) Byte.MAX_VALUE; - ts.light.z = this.tiles_lighting_b[id] / (double) Byte.MAX_VALUE; + ts.light = this.tiles_lighting[id] / (double) Byte.MAX_VALUE; return ts; } @@ -204,9 +197,7 @@ public class Chunk { // Send back the front tile 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.y = this.tiles_lighting_g[id] / (double) Byte.MAX_VALUE; - ts.light.z = this.tiles_lighting_b[id] / (double) Byte.MAX_VALUE; + ts.light = this.tiles_lighting[id] / (double) Byte.MAX_VALUE; return ts; } @@ -222,14 +213,11 @@ public class Chunk } } - public Vec3d getLightLevel(int id) { - return new Vec3d( - 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 double getLightLevel(int id) { + return tiles_lighting[id] / (double)Byte.MAX_VALUE; } - public Vec3d getLightLevel(Vec2i pos) + public double getLightLevel(Vec2i pos) { // Get the id Vec2i cpos = new Vec2i(0, 0); @@ -240,13 +228,11 @@ public class Chunk return getLightLevel(id); } - public void setLightLevel(Vec3d light, int id) { - this.tiles_lighting_r[id] = (byte)(light.x * 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(double light, int id) { + this.tiles_lighting[id] = (byte)(light * Byte.MAX_VALUE); } - public void setLightLevel(Vec3d light, Vec2i pos) + public void setLightLevel(double light, Vec2i pos) { // Get the id Vec2i cpos = new Vec2i(0, 0); diff --git a/src/shootergame/world/chunk/ChunkEmpty.java b/src/shootergame/world/chunk/ChunkEmpty.java index 340ebfe..85703d1 100644 --- a/src/shootergame/world/chunk/ChunkEmpty.java +++ b/src/shootergame/world/chunk/ChunkEmpty.java @@ -7,7 +7,6 @@ import shootergame.entity.Entity; import shootergame.util.math.TileState; import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2i; -import shootergame.util.math.vec.Vec3d; public class ChunkEmpty extends Chunk { @@ -73,21 +72,21 @@ public class ChunkEmpty extends Chunk } @Override - public Vec3d getLightLevel(int id) { - return new Vec3d(0, 0, 0); + public double getLightLevel(int id) { + return 0; } @Override - public Vec3d getLightLevel(Vec2i pos) { - return new Vec3d(0, 0, 0); + public double getLightLevel(Vec2i pos) { + return 0; } @Override - public void setLightLevel(Vec3d light, int id) { + public void setLightLevel(double light, int id) { } @Override - public void setLightLevel(Vec3d light, Vec2i pos) { + public void setLightLevel(double light, Vec2i pos) { } @Override diff --git a/src/shootergame/world/layer/Layer.java b/src/shootergame/world/layer/Layer.java index f3df5ae..40f4abe 100644 --- a/src/shootergame/world/layer/Layer.java +++ b/src/shootergame/world/layer/Layer.java @@ -12,7 +12,6 @@ import shootergame.util.math.map.Map2D; import shootergame.util.math.map.Map2DElement; import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2i; -import shootergame.util.math.vec.Vec3d; import shootergame.world.chunk.Chunk; import shootergame.world.layer.layergen.LayerGen; @@ -22,14 +21,16 @@ public class Layer public LayerGen layergen; private Random rand; 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 this.layergen = layergen; this.seed = rand.nextLong(); this.rand = new Random(); this.chunks = new Map2D(layergen); + this.id = id; } public void render(Camera camera) @@ -118,7 +119,7 @@ public class Layer MathHelpers.floor(pos.y / (double)Chunk.CHUNK_SIZE.my)); } - public Vec3d getLightLevel(Vec2i pos) + public double getLightLevel(Vec2i pos) { // Get the chunk pos Vec2i c_pos = getChunkPosFromPos(pos); @@ -127,7 +128,7 @@ public class Layer 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 Vec2i c_pos = getChunkPosFromPos(pos); diff --git a/src/shootergame/world/layer/layergen/LayerGen.java b/src/shootergame/world/layer/layergen/LayerGen.java index 93e2464..5c1092a 100644 --- a/src/shootergame/world/layer/layergen/LayerGen.java +++ b/src/shootergame/world/layer/layergen/LayerGen.java @@ -5,7 +5,6 @@ import java.util.Random; import shootergame.util.math.TileState; import shootergame.util.math.map.IMap2D; import shootergame.util.math.vec.Vec2i; -import shootergame.util.math.vec.Vec3d; import shootergame.world.chunk.Chunk; import shootergame.world.layer.Layer; @@ -14,7 +13,7 @@ public abstract class LayerGen implements IMap2D public abstract void generateChunk(Chunk chunk, Layer layer, long seed, Random rand, Vec2i pos); public abstract void spawnEntities(Layer layer, Random rand); public abstract TileState getTileDestroyed(); - public abstract Vec3d getLightLevel(); + public abstract double getLightLevel(); @Override public Chunk getEmpty(Vec2i pos) { diff --git a/src/shootergame/world/layer/layergen/LayerGenCaves.java b/src/shootergame/world/layer/layergen/LayerGenCaves.java index 64e2299..f0d5510 100644 --- a/src/shootergame/world/layer/layergen/LayerGenCaves.java +++ b/src/shootergame/world/layer/layergen/LayerGenCaves.java @@ -12,7 +12,6 @@ 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.util.math.vec.Vec3d; import shootergame.world.chunk.Chunk; 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) { // 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; if(portal) portal_pos = new Vec2i( RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.mx), RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.my)); // 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; if(portal_down) portal_down_pos = new Vec2i( RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.mx), RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.my)); // 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 for(int x=0;x 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 @@ -26,12 +75,12 @@ public class LayerGenLavaCaves extends LayerGen @Override public TileState getTileDestroyed() { - return Tiles.LAVA.getDefaultState(); + return Tiles.STONE.getDefaultState(); } @Override - public Vec3d getLightLevel() { - return new Vec3d(0.1, 0.1, 0.1); + public double getLightLevel() { + return 0.1; } } diff --git a/src/shootergame/world/layer/layergen/PortalSpawnrates.java b/src/shootergame/world/layer/layergen/PortalSpawnrates.java new file mode 100644 index 0000000..3e6b3cc --- /dev/null +++ b/src/shootergame/world/layer/layergen/PortalSpawnrates.java @@ -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; + } +}