diff --git a/.classpath b/.classpath old mode 100644 new mode 100755 index 324a40d..a78e5fc --- a/.classpath +++ b/.classpath @@ -2,11 +2,11 @@ - + diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/.project b/.project old mode 100644 new mode 100755 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs old mode 100644 new mode 100755 diff --git a/layer.bdf b/layer.bdf new file mode 100644 index 0000000..1ccd406 Binary files /dev/null and b/layer.bdf differ diff --git a/resources/sound/explosion.ogg b/resources/sound/explosion.ogg old mode 100644 new mode 100755 diff --git a/resources/sound/gun0.ogg b/resources/sound/gun0.ogg old mode 100644 new mode 100755 diff --git a/resources/sound/gun1.ogg b/resources/sound/gun1.ogg old mode 100644 new mode 100755 diff --git a/resources/sound/gun2.ogg b/resources/sound/gun2.ogg old mode 100644 new mode 100755 diff --git a/resources/sound/gun3.ogg b/resources/sound/gun3.ogg old mode 100644 new mode 100755 diff --git a/resources/sound/gun4.ogg b/resources/sound/gun4.ogg old mode 100644 new mode 100755 diff --git a/resources/sound/gun5.ogg b/resources/sound/gun5.ogg old mode 100644 new mode 100755 diff --git a/resources/sound/gun6.ogg b/resources/sound/gun6.ogg old mode 100644 new mode 100755 diff --git a/resources/sound/gun7.ogg b/resources/sound/gun7.ogg old mode 100644 new mode 100755 diff --git a/resources/sound/gun8.ogg b/resources/sound/gun8.ogg old mode 100644 new mode 100755 diff --git a/resources/sound/gun9.ogg b/resources/sound/gun9.ogg old mode 100644 new mode 100755 diff --git a/resources/sound/hit0.ogg b/resources/sound/hit0.ogg old mode 100644 new mode 100755 diff --git a/resources/sound/hit1.ogg b/resources/sound/hit1.ogg old mode 100644 new mode 100755 diff --git a/resources/sound/hit2.ogg b/resources/sound/hit2.ogg old mode 100644 new mode 100755 diff --git a/resources/texmap.old.png b/resources/texmap.old.png old mode 100644 new mode 100755 diff --git a/resources/texmap.png b/resources/texmap.png old mode 100644 new mode 100755 index 8e10a00..e59b0bf Binary files a/resources/texmap.png and b/resources/texmap.png differ diff --git a/resources/texmap.xcf b/resources/texmap.xcf old mode 100644 new mode 100755 index ff78e06..855faec Binary files a/resources/texmap.xcf and b/resources/texmap.xcf differ diff --git a/settings.bdf b/settings.bdf old mode 100644 new mode 100755 index fdaed9e..1c4441a Binary files a/settings.bdf and b/settings.bdf differ diff --git a/src/projectzombie/Main.java b/src/projectzombie/Main.java old mode 100644 new mode 100755 index 10b61eb..b58aa8e --- a/src/projectzombie/Main.java +++ b/src/projectzombie/Main.java @@ -2,18 +2,24 @@ package projectzombie; import java.util.Random; +import bdf.file.BdfCompressedFileManager; import mainloop.manager.MainloopManager; import projectzombie.audio.AudioEngine; import projectzombie.audio.AudioSources; +import projectzombie.display.Camera; import projectzombie.display.DisplayStatsEventHandler; import projectzombie.display.DisplayWindow; import projectzombie.display.bossbar.BossBars; import projectzombie.entity.EntityEventHandler; import projectzombie.entity.player.EntityPlayer; +import projectzombie.init.Entities; +import projectzombie.init.Items; +import projectzombie.init.LayerGenerators; import projectzombie.init.Layers; import projectzombie.init.Resources; import projectzombie.init.Sounds; import projectzombie.init.Textures; +import projectzombie.init.Tiles; import projectzombie.input.JoystickCallback; import projectzombie.input.KeyCallback; import projectzombie.mainloop.MainloopEventHandler; @@ -46,6 +52,11 @@ public class Main Layers.init(rand.nextLong()); player = new EntityPlayer(); GameTimer.resetTime(); + + /*BdfCompressedFileManager bdf = new BdfCompressedFileManager("./layer.bdf"); + Main.world = new World(); + Main.world.BdfClassLoad(bdf);*/ + BossBars.clear(); } @@ -56,6 +67,11 @@ public class Main Cheats.init(args); Settings.init(); + Items.init(); + Entities.init(); + Tiles.init(); + LayerGenerators.init(); + // Load the resources Resources.loadResources(); diff --git a/src/projectzombie/audio/AudioEngine.java b/src/projectzombie/audio/AudioEngine.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/audio/AudioObject.java b/src/projectzombie/audio/AudioObject.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/audio/AudioRandom.java b/src/projectzombie/audio/AudioRandom.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/audio/AudioSources.java b/src/projectzombie/audio/AudioSources.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/display/Camera.java b/src/projectzombie/display/Camera.java old mode 100644 new mode 100755 index c5ee36a..bfdde10 --- a/src/projectzombie/display/Camera.java +++ b/src/projectzombie/display/Camera.java @@ -10,6 +10,7 @@ public class Camera public Vec2d angle; public int renderDistance; public double cameraDistance; + public double distanceFromPlayer; public static Camera camera; @@ -20,5 +21,7 @@ public class Camera cameraDistance, new Vec2d(Math.toRadians(angle.x), Math.toRadians(-angle.y)))); this.cameraDistance = cameraDistance; this.renderDistance = renderDistance; + + this.distanceFromPlayer = 10; } } diff --git a/src/projectzombie/display/DisplayRender.java b/src/projectzombie/display/DisplayRender.java old mode 100644 new mode 100755 index 117118a..921b3fd --- a/src/projectzombie/display/DisplayRender.java +++ b/src/projectzombie/display/DisplayRender.java @@ -24,6 +24,7 @@ import projectzombie.util.gl.GlHelpers; import projectzombie.util.math.vec.Vec2d; import projectzombie.util.math.vec.Vec3d; import projectzombie.world.chunk.Chunk; +import projectzombie.world.chunk.ChunkEventHandler; public class DisplayRender { @@ -59,6 +60,7 @@ public class DisplayRender // Push the matrix GlHelpers.pushMatrix(); + if(ChunkEventHandler.loaded) { // Set matrix mode glMatrixMode(GL_MODELVIEW); @@ -104,9 +106,9 @@ public class DisplayRender // Render the sorted transparent objects TransparentObjects.render(camera); - - GlHelpers.popMatrix(); } + + GlHelpers.popMatrix(); } // Render the user interface diff --git a/src/projectzombie/display/DisplayRenderUI.java b/src/projectzombie/display/DisplayRenderUI.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/display/DisplayStatsEventHandler.java b/src/projectzombie/display/DisplayStatsEventHandler.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/display/DisplayWindow.java b/src/projectzombie/display/DisplayWindow.java old mode 100644 new mode 100755 index 852f591..1a54b16 --- a/src/projectzombie/display/DisplayWindow.java +++ b/src/projectzombie/display/DisplayWindow.java @@ -1,5 +1,9 @@ package projectzombie.display; +import static org.lwjgl.glfw.GLFW.GLFW_DOUBLEBUFFER; +import static org.lwjgl.glfw.GLFW.GLFW_FALSE; +import static org.lwjgl.glfw.GLFW.glfwWindowHint; + import java.nio.IntBuffer; import org.lwjgl.BufferUtils; @@ -64,7 +68,9 @@ public class DisplayWindow implements IMainloopTask this.height = h.get()*4; // Set the window hint - GLFW.glfwWindowHint(GLFW.GLFW_VISIBLE, GLFW.GLFW_FALSE); + GLFW.glfwWindowHint(GLFW.GLFW_SAMPLES, 0); + GLFW.glfwWindowHint(GLFW.GLFW_SCALE_TO_MONITOR, 1); + GLFW.glfwWindowHint(GLFW.GLFW_VISIBLE, 0); GLFW.glfwWindowHint(GLFW.GLFW_VERSION_MAJOR, 3); GLFW.glfwWindowHint(GLFW.GLFW_VERSION_MINOR, 3); diff --git a/src/projectzombie/display/bossbar/BossBars.java b/src/projectzombie/display/bossbar/BossBars.java old mode 100644 new mode 100755 index 38b78d5..6045df3 --- a/src/projectzombie/display/bossbar/BossBars.java +++ b/src/projectzombie/display/bossbar/BossBars.java @@ -24,6 +24,8 @@ public class BossBars TextureReference health_bg = Textures.UI_HEALTH_BG; ArrayList toRemove = new ArrayList(); + double s = GlHelpers.getScale() / 10.0; + // Render the boss bars int i = 0; for(IBossBar bossbar : bossbars) @@ -32,15 +34,15 @@ public class BossBars double a = 1 - (bossbar.getHealth() / max_health); GlHelpers.begin(); - health_bg.texCoord(0, 1); GlHelpers.vertex2(-4, 8.5 - i); - health_bg.texCoord(0, 0); GlHelpers.vertex2(-4, 9.0 - i); - health_bg.texCoord(1, 0); GlHelpers.vertex2(4, 9.0 - i); - health_bg.texCoord(1, 1); GlHelpers.vertex2(4, 8.5 - i); + health_bg.texCoord(0, 1); GlHelpers.vertex2(-4*s, 8.5*s - i); + health_bg.texCoord(0, 0); GlHelpers.vertex2(-4*s, 9.0*s - i); + health_bg.texCoord(1, 0); GlHelpers.vertex2(4*s, 9.0*s - i); + health_bg.texCoord(1, 1); GlHelpers.vertex2(4*s, 8.5*s - i); - health_fg.texCoord(0, 1); GlHelpers.vertex2(-4, 8.5 - i); - health_fg.texCoord(0, 0); GlHelpers.vertex2(-4, 9.0 - i); - health_fg.texCoord(1-a, 0); GlHelpers.vertex2(4-a*8, 9.0 - i); - health_fg.texCoord(1-a, 1); GlHelpers.vertex2(4-a*8, 8.5 - i); + health_fg.texCoord(0, 1); GlHelpers.vertex2(-4*s, 8.5*s - i); + health_fg.texCoord(0, 0); GlHelpers.vertex2(-4*s, 9.0*s - i); + health_fg.texCoord(1-a, 0); GlHelpers.vertex2(4*s-a*8*s, 9.0*s - i); + health_fg.texCoord(1-a, 1); GlHelpers.vertex2(4*s-a*8*s, 8.5*s - i); GlHelpers.end(); i += 1; diff --git a/src/projectzombie/display/bossbar/IBossBar.java b/src/projectzombie/display/bossbar/IBossBar.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/display/lighting/ChunkLightingCollection.java b/src/projectzombie/display/lighting/ChunkLightingCollection.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/display/lighting/ChunkLightingTemp.java b/src/projectzombie/display/lighting/ChunkLightingTemp.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/display/lighting/DynamicLighting.java b/src/projectzombie/display/lighting/DynamicLighting.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/display/lighting/TileLighting.java b/src/projectzombie/display/lighting/TileLighting.java old mode 100644 new mode 100755 index 81d9f38..63e2645 --- a/src/projectzombie/display/lighting/TileLighting.java +++ b/src/projectzombie/display/lighting/TileLighting.java @@ -20,6 +20,7 @@ public class TileLighting implements IMainloopTask public static void update() { + if(Camera.camera == null) return; if(!ChunkEventHandler.loaded) return; Layer layer = Main.world.getLayer(); EntityPlayer player = Main.player; @@ -55,6 +56,11 @@ public class TileLighting implements IMainloopTask MainloopHelpers.loopAsync(0, range.maxValue(), (it) -> { + + if(!ChunkEventHandler.loaded) { + return; + } + Vec4i upto = Vec4i.fromId(range, it); Vec2i cpos = new Vec2i( @@ -140,12 +146,20 @@ public class TileLighting implements IMainloopTask // Set the light level if(daylightMode) { - if(tile_f.tile.passNaturalLight && tile_b.tile.passNaturalLight && it == 1) { + if(tile_f.tile.passNaturalLight && tile_b.tile.passNaturalLight && it != 0) { return; } if(light <= chunk_t.getDaylightLevel(lid)) return; chunk_t.setDaylightLevel(light, lid); } else { + if((tile_f.tile.emitsLight || tile_b.tile.emitsLight) && it == 1) { + double light_external = MathHelpers.biggest( + tile_f.tile.getLightLevel(tile_f, lpos), + tile_b.tile.getLightLevel(tile_b, lpos)); + if(light_external >= light) { + return; + }; + } if(light <= chunk_t.getLightLevel(lid)) return; chunk_t.setLightLevel(light, lid); } @@ -163,30 +177,6 @@ public class TileLighting implements IMainloopTask new Vec2i(lpos.x, lpos.y-1) }; - int samechunk = 0; - - for(Vec2i position : positions) { - Vec2i new_cpos = Layer.getChunkPosFromPos(position); - if(new_cpos.equal(chunk.c_pos)) { - samechunk += 1; - } - } - - if(samechunk == 4) { - double neighbour_light = 0; - for(Vec2i position : positions) { - TileState tf = chunk.getFrontTile(position); - TileState tb = chunk.getBackTile(position); - neighbour_light = MathHelpers.smallest(MathHelpers.biggest( - tb.tile.getLightLevel(tb, position), - tf.tile.getLightLevel(tf, position)), - neighbour_light); - } - if(neighbour_light > light) { - return; - } - } - // Add the light to all the adjacent positions for(Vec2i position : positions) { addLightToTiles(chunks, layer, position, it + 1, light - dissipation, daylightMode); diff --git a/src/projectzombie/display/transparent/ITransparentObject.java b/src/projectzombie/display/transparent/ITransparentObject.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/display/transparent/TransparentObject.java b/src/projectzombie/display/transparent/TransparentObject.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/display/transparent/TransparentObjects.java b/src/projectzombie/display/transparent/TransparentObjects.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/entity/Entity.java b/src/projectzombie/entity/Entity.java old mode 100644 new mode 100755 index e843997..997e8b9 --- a/src/projectzombie/entity/Entity.java +++ b/src/projectzombie/entity/Entity.java @@ -1,7 +1,13 @@ package projectzombie.entity; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import java.util.Random; +import bdf.classes.IBdfClassManager; +import bdf.types.BdfArray; +import bdf.types.BdfNamedList; +import bdf.types.BdfObject; import mainloop.task.IMainloopTask; import projectzombie.Main; import projectzombie.display.Camera; @@ -14,17 +20,16 @@ import projectzombie.util.math.TileState; import projectzombie.util.math.vec.Vec2d; import projectzombie.util.math.vec.Vec2i; import projectzombie.world.chunk.Chunk; +import projectzombie.world.chunk.ChunkEventHandler; import projectzombie.world.layer.Layer; -public class Entity implements ITransparentObject +public class Entity implements ITransparentObject, IBdfClassManager { public Vec2d pos; - public double angle = 0; public boolean opaqueTile = true; public double hitbox = 1; public boolean isSolid = false; public Chunk chunk; - private double speed = 1; private TileState tile_front; private TileState tile_back; public boolean crossUnWalkable = true; @@ -34,18 +39,123 @@ public class Entity implements ITransparentObject public int stepOnTileCooldown = 0; + protected double getTilesLightDissipation() { + if(chunk == null) return 0; + TileState tsf = chunk.getFrontTile(pos.toInt()); + TileState tsb = chunk.getBackTile(pos.toInt()); + return MathHelpers.biggest( + tsf.tile.getLightDissipation(tsf), + tsb.tile.getLightDissipation(tsb)); + } + + protected double getLightWithHeight(double light) { + double height = 1; + if(this instanceof EntityHeight) { + height *= ((EntityHeight)this).getHeight(); + } + return light - (this.getTilesLightDissipation() * Math.abs(height)); + } + + public int getID() { + for(int i=0;i ec = Entities.entities.get(i); + if(ec == this.getClass()) { + return i; + } + } + return -1; + } + + public static Entity loadEntity(BdfObject bdf) + { + try + { + // Load the entity id + BdfNamedList nl = bdf.getNamedList(); + int id = nl.get("id").getInteger(); + + // Send back null if the id is out of range + if(id < 0 || id >= Entities.entities.size()) { + System.out.println("Warning: Invalid ID detected: " + id); + return null; + } + + // Get the class and the constructor + Class ecl = Entities.entities.get(id); + Constructor econ = ecl.getConstructor(BdfObject.class); + + // Send back the new entity + return econ.newInstance(bdf); + } + + catch( + NoSuchMethodException | + SecurityException | + InstantiationException | + IllegalAccessException | + IllegalArgumentException | + InvocationTargetException e) + { + e.printStackTrace(); + + // Send null if there was an issue + return null; + } + } + public Entity(Vec2d pos) { - // Add this entity to the list of entities - Entities.entities.add(this); - // Store the specified values this.pos = pos; } + public Entity(BdfObject bdf) { + this.BdfClassLoad(bdf); + } + + @Override + public void BdfClassLoad(BdfObject bdf) { + BdfNamedList nl = bdf.getNamedList(); + BdfArray e = nl.get("e").getArray(); + pos = new Vec2d(e.get(0)); + opaqueTile = e.get(1).getBoolean(); + hitbox = e.get(2).getDouble(); + isSolid = e.get(3).getBoolean(); + crossUnWalkable = e.get(4).getBoolean(); + goThroughSolid = e.get(5).getBoolean(); + emitsLight = e.get(6).getBoolean(); + stepOnTileCooldown = e.get(7).getInteger(); + } + + @Override + public void BdfClassSave(BdfObject bdf) + { + // Get the ID and return if its invalid (entity can't be saved) + int id = getID(); + if(id == -1) return; + + BdfNamedList nl = bdf.getNamedList(); + nl.set("id", BdfObject.withInteger(getID())); + + BdfObject pos_bdf = new BdfObject(); + pos.BdfClassSave(pos_bdf); + + BdfArray e = new BdfArray(); + nl.set("e", BdfObject.withArray(e)); + + e.add(pos_bdf); + e.add(BdfObject.withBoolean(opaqueTile)); + e.add(BdfObject.withDouble(hitbox)); + e.add(BdfObject.withBoolean(isSolid)); + e.add(BdfObject.withBoolean(crossUnWalkable)); + e.add(BdfObject.withBoolean(goThroughSolid)); + e.add(BdfObject.withBoolean(emitsLight)); + e.add(BdfObject.withInteger(stepOnTileCooldown)); + } + public void tick(Chunk chunk, Layer layer) { - speed = 1; - angle = MathHelpers.mod(angle, 360); + //speed = 1; + //angle = MathHelpers.mod(angle, 360); Vec2i tpos = new Vec2i(MathHelpers.floor(pos.x)+0, MathHelpers.floor(pos.y)+0); if(chunk == null) chunk = layer.getChunk(pos); this.chunk = chunk; @@ -56,15 +166,23 @@ public class Entity implements ITransparentObject stepOnTileCooldown -= 1; } - if(this.isSolid) - { - this.addSlowness(tile_back.tile.slowness); - this.addSlowness(tile_front.tile.slowness); - } + moveAwayFromSolidEntities(layer); } - public void addSlowness(double amount) { - speed *= (1 - amount); + protected void moveAwayFromSolidEntities(Layer layer) + { + if(!goThroughSolid) + { + for(Entity e : layer.getNearbyEntities(pos, hitbox)) + { + if(e.isSolid && e != this) { + double angle = Math.toDegrees(Math.atan2( + pos.y - e.pos.y, + pos.x - e.pos.x)); + moveTowards(angle + 180, 0.1); + } + } + } } public void render(Vec2d pos, Camera camera) { @@ -91,19 +209,17 @@ public class Entity implements ITransparentObject return this.opaqueTile; } - public void moveForward(double speed) { - this.moveTowards(0, speed); - } - - public void moveBackward(double speed) { - this.moveTowards(0, -speed); - } - public void moveTowards(double angle, double speed) { + if(chunk == null) { + chunk = Main.world.getLayer().getChunk(pos); + } + // Calculate the new position - speed *= this.speed; - Vec2d pos = this.pos.add(MathHelpers.moveTowards2(speed, Math.toRadians(this.angle + angle))); + speed *= 1 - MathHelpers.biggest( + chunk.getFrontTile(pos.toInt()).tile.slowness, + chunk.getBackTile(pos.toInt()).tile.slowness); + Vec2d pos = this.pos.add(MathHelpers.moveTowards2(speed, Math.toRadians(angle))); // Check if the new position is legal if(this.moveIsLegal(new Vec2d(this.pos.x, pos.y))) this.pos.y = pos.y; @@ -113,16 +229,20 @@ public class Entity implements ITransparentObject if(this.isSolid) activateSteppedOnTile(); } - public void moveForward() { - this.moveForward(0.1); - } - - public void moveBackward() { - this.moveBackward(0.1); - } - - public void moveTowards(double angle) { - moveTowards(angle, 0.1); + public void moveInVector(Vec2d vec, double speed) + { + // Calculate the new position + speed *= 1 - MathHelpers.biggest( + chunk.getFrontTile(pos.toInt()).tile.slowness, + chunk.getBackTile(pos.toInt()).tile.slowness); + Vec2d pos = vec.multiply(speed).add(this.pos); + + // Check if the new position is legal + if(this.moveIsLegal(new Vec2d(this.pos.x, pos.y))) this.pos.y = pos.y; + if(this.moveIsLegal(new Vec2d(pos.x, this.pos.y))) this.pos.x = pos.x; + + // Activate stepped on tiles if the entity is "solid" + if(this.isSolid) activateSteppedOnTile(); } public void kill() { @@ -168,7 +288,6 @@ public class Entity implements ITransparentObject // Is this entity solid if(!goThroughSolid || !crossUnWalkable) { - // Check the tile the player is standing on Vec2i tpos = new Vec2i(MathHelpers.floor(pos.x)+0, MathHelpers.floor(pos.y)+0); @@ -236,8 +355,12 @@ public class Entity implements ITransparentObject @Override public void MainLoopUpdate() { + if(!ChunkEventHandler.loaded) + return; + if(chunk == null) + chunk = Main.world.getLayer().getChunk(pos); if(Main.menu.doGameloop) { - moveTowards(Math.toRadians(angle) + 180, a[0]/100.0); + moveTowards(angle, a[0]/100.0); a[0] -= a[0] / 100.0; } } diff --git a/src/projectzombie/entity/EntityAlive.java b/src/projectzombie/entity/EntityAlive.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/entity/EntityBoss.java b/src/projectzombie/entity/EntityBoss.java old mode 100644 new mode 100755 index a6eedb6..0957449 --- a/src/projectzombie/entity/EntityBoss.java +++ b/src/projectzombie/entity/EntityBoss.java @@ -1,5 +1,9 @@ package projectzombie.entity; +import java.util.Random; + +import bdf.types.BdfNamedList; +import bdf.types.BdfObject; import projectzombie.Main; import projectzombie.display.Camera; import projectzombie.display.bossbar.BossBars; @@ -19,7 +23,7 @@ import projectzombie.util.math.vec.Vec3d; import projectzombie.world.chunk.Chunk; import projectzombie.world.layer.Layer; -public class EntityBoss extends EntityVertical implements IBossBar +public class EntityBoss extends EntityVertical implements IBossBar, EntityKillWithParticles { private boolean moving = false; private boolean firing = false; @@ -27,10 +31,55 @@ public class EntityBoss extends EntityVertical implements IBossBar private double health = max_health; private int bullet_frequency = 0; private int spawn_frequency = 0; + private double time = 0; private OpenSimplexNoise noise_gun; private OpenSimplexNoise noise_walk; private OpenSimplexNoise noise_spawn; + protected OpenSimplexNoise noise_target_x; + protected OpenSimplexNoise noise_target_y; + + private long seed; + + public EntityBoss(BdfObject bdf) { + super(bdf, TextureReference.EMPTY, new Vec2d(4, 4)); + } + + @Override + public void BdfClassLoad(BdfObject bdf) { + super.BdfClassLoad(bdf); + + BdfNamedList nl = bdf.getNamedList(); + health = nl.get("health").getDouble(); + bullet_frequency = nl.get("bullet_freq").getInteger(); + spawn_frequency = nl.get("spawn_frq").getInteger(); + + this.isSolid = true; + this.goThroughSolid = false; + this.crossUnWalkable = false; + this.hitbox = 2; + + long seed = nl.get("seed").getLong(); + Random rand = new Random(seed); + this.noise_gun = new OpenSimplexNoise(rand.nextLong()); + this.noise_walk = new OpenSimplexNoise(rand.nextLong()); + this.noise_spawn = new OpenSimplexNoise(rand.nextLong()); + this.noise_target_x = new OpenSimplexNoise(rand.nextLong()); + this.noise_target_y = new OpenSimplexNoise(rand.nextLong()); + + BossBars.register(this); + } + + @Override + public void BdfClassSave(BdfObject bdf) { + super.BdfClassSave(bdf); + + BdfNamedList nl = bdf.getNamedList(); + nl.set("health", BdfObject.withDouble(health)); + nl.set("bullet_freq", BdfObject.withInteger(bullet_frequency)); + nl.set("spawn_freq", BdfObject.withInteger(spawn_frequency)); + nl.set("seed", BdfObject.withLong(seed)); + } public EntityBoss(Vec2d pos) { super(pos, TextureReference.EMPTY, new Vec2d(4, 4)); @@ -38,11 +87,15 @@ public class EntityBoss extends EntityVertical implements IBossBar this.isSolid = true; this.goThroughSolid = false; this.crossUnWalkable = false; - this.hitbox = 1; + this.hitbox = 2; + long seed = rand.nextLong(); + Random rand = new Random(seed); this.noise_gun = new OpenSimplexNoise(rand.nextLong()); this.noise_walk = new OpenSimplexNoise(rand.nextLong()); this.noise_spawn = new OpenSimplexNoise(rand.nextLong()); + this.noise_target_x = new OpenSimplexNoise(rand.nextLong()); + this.noise_target_y = new OpenSimplexNoise(rand.nextLong()); BossBars.register(this); } @@ -51,8 +104,12 @@ public class EntityBoss extends EntityVertical implements IBossBar public void tick(Chunk chunk, Layer layer) { super.tick(chunk, layer); - double angle = Math.atan2(pos.x - Main.player.pos.x, pos.y - Main.player.pos.y); - this.angle = Math.toDegrees(angle) + 180; + double angle = Math.atan2( + pos.x - Main.player.pos.x + noise_target_x.eval( + time*2, Main.player.pos.x/25, Main.player.pos.y/25)*10, + pos.y - Main.player.pos.y + noise_target_y.eval( + time*2, Main.player.pos.y/25, Main.player.pos.y/25)*10); + angle = Math.toDegrees(angle) + 180; if(this.noise_spawn.eval(GameTimer.getTime() / 500.0, 0) > 0.2) { if(spawn_frequency == 0) { @@ -77,7 +134,7 @@ public class EntityBoss extends EntityVertical implements IBossBar if(bullet_frequency == 0) { - Vec2d gun_offset = MathHelpers.moveTowards2(1, Math.toRadians(90 + this.angle)); + Vec2d gun_offset = MathHelpers.moveTowards2(1, Math.toRadians(90)); Vec3d pos1 = new Vec3d(pos.x + gun_offset.x, pos.y + gun_offset.y, 1); double distance_1 = pos1.distance(new Vec3d(pos.x, pos.y, pos1.z)); @@ -90,9 +147,9 @@ public class EntityBoss extends EntityVertical implements IBossBar double angle2_0 = Math.toDegrees(Math.atan2(pos2.x - Main.player.pos.x, pos2.y - Main.player.pos.y)) + 180; double angle2_1 = Math.toDegrees(Math.atan2(distance_2, pos2.z - 1)) - 90; - layer.spawnEntity(new EntityBullet(pos.add(gun_offset), this, angle1_0, 20, 5, 1000 + layer.spawnEntity(new EntityBullet(pos.add(gun_offset), this, angle1_0, 20, 1000 ).withHeight(angle1_1, pos1.z)); - layer.spawnEntity(new EntityBullet(pos.subtract(gun_offset), this, angle2_0, 20, 5, 1000 + layer.spawnEntity(new EntityBullet(pos.subtract(gun_offset), this, angle2_0, 20, 1000 ).withHeight(angle2_1, pos2.z)); bullet_frequency = 10; } @@ -109,13 +166,16 @@ public class EntityBoss extends EntityVertical implements IBossBar } if(this.noise_walk.eval(GameTimer.getTime() / 500.0, 0) > -0.4) { - this.moveForward(); + this.moveTowards(angle); this.moving = true; } else { this.moving = false; } + + // Increase time + time += 0.001; } @Override @@ -186,21 +246,10 @@ public class EntityBoss extends EntityVertical implements IBossBar return health >= 0; } - @Override public void moveTowards(double angle) { this.moveTowards(angle, 0.02); } - @Override - public void moveBackward() { - this.moveBackward(0.02); - } - - @Override - public void moveForward() { - this.moveForward(0.02); - } - @Override public void onDeath(Layer layer) { IBossBar.super.onDeath(layer); @@ -229,4 +278,8 @@ public class EntityBoss extends EntityVertical implements IBossBar @Override public void push(double amount, double angle) { } + + @Override + protected void moveAwayFromSolidEntities(Layer layer) { + } } diff --git a/src/projectzombie/entity/EntityBullet.java b/src/projectzombie/entity/EntityBullet.java old mode 100644 new mode 100755 index d526a84..afdf87b --- a/src/projectzombie/entity/EntityBullet.java +++ b/src/projectzombie/entity/EntityBullet.java @@ -1,9 +1,13 @@ package projectzombie.entity; +import bdf.types.BdfNamedList; +import bdf.types.BdfObject; import projectzombie.display.Camera; import projectzombie.entity.particle.ParticleBlood; import projectzombie.init.Sounds; +import projectzombie.settings.SettingQuality; import projectzombie.tiles.Tile; +import projectzombie.tiles.TileBulletBreakable; import projectzombie.util.gl.GlHelpers; import projectzombie.util.math.MathHelpers; import projectzombie.util.math.random.RandomHelpers; @@ -19,20 +23,49 @@ public class EntityBullet extends EntityParticle private Entity parent; private double damage; - private int breakchance; private double height = 0.2; private double height_angle = 0; + private double angle = 0; private Vec3d velocity; - public EntityBullet(Vec2d pos, Entity parent, double angle, double damage, int breakchance, int despawn_time) { - super(pos, 0.2, 0.4); + public EntityBullet(BdfObject bdf) { + super(bdf); + } + + @Override + public void BdfClassLoad(BdfObject bdf) { + super.BdfClassLoad(bdf); + + BdfNamedList nl = bdf.getNamedList(); + time = nl.get("time").getInteger(); + damage = nl.get("damage").getDouble(); + height = nl.get("height").getDouble(); + height_angle = nl.get("angle_h").getDouble(); + angle = nl.get("angle").getDouble(); + velocity = new Vec3d(nl.get("velocity")); + } + + @Override + public void BdfClassSave(BdfObject bdf) { + super.BdfClassSave(bdf); + + BdfNamedList nl = bdf.getNamedList(); + nl.set("time", BdfObject.withInteger(time)); + nl.set("damage", BdfObject.withDouble(damage)); + nl.set("height", BdfObject.withDouble(height)); + nl.set("angle_h", BdfObject.withDouble(height_angle)); + nl.set("angle", BdfObject.withDouble(angle)); + velocity.BdfClassSave(nl.get("velocity")); + } + + public EntityBullet(Vec2d pos, Entity parent, double angle, double damage, int despawn_time) { + super(pos, 0.2, despawn_time); // Store some specified values this.angle = angle; this.parent = parent; this.damage = damage; - this.breakchance = breakchance; this.time = despawn_time; // Calculate the velocity vector @@ -86,7 +119,8 @@ public class EntityBullet extends EntityParticle if(pos.squareDistance(new Vec2d(tpos.x + 0.5, tpos.y + 0.5)) < tile_f.tileHitbox) { // Break the block - if(RandomHelpers.randrange(rand, breakchance) == 0) { + if(tile_f instanceof TileBulletBreakable && RandomHelpers.randrange(rand, + ((TileBulletBreakable)tile_f).getBulletBreakChance()) == 0) { chunk.breakFrontTile(tpos); } @@ -97,7 +131,8 @@ public class EntityBullet extends EntityParticle if(pos.squareDistance(new Vec2d(tpos.x + 0.5, tpos.y + 0.5)) < tile_b.tileHitbox) { // Break the block - if(RandomHelpers.randrange(rand, breakchance) == 0) { + if(tile_f instanceof TileBulletBreakable && RandomHelpers.randrange(rand, + ((TileBulletBreakable)tile_f).getBulletBreakChance()) == 0) { chunk.breakBackTile(tpos); } @@ -120,8 +155,10 @@ public class EntityBullet extends EntityParticle e.push(1, angle); // Spawn some blood particles - for(int i=0;i= 8) { ea.setHeight(0); - Main.world.setLayer(Layers.getLayer(layerId)); + Main.world.setLayer(layerId); + + if(layer.layergen.destroyOnLeave) { + Main.world.removeLayer(layerId); + } if(entity instanceof EntityPlayer) { diff --git a/src/projectzombie/entity/EntityHeight.java b/src/projectzombie/entity/EntityHeight.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/entity/EntityInventory.java b/src/projectzombie/entity/EntityInventory.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/entity/EntityItem.java b/src/projectzombie/entity/EntityItem.java old mode 100644 new mode 100755 index 0b9c089..69c4b09 --- a/src/projectzombie/entity/EntityItem.java +++ b/src/projectzombie/entity/EntityItem.java @@ -1,6 +1,9 @@ package projectzombie.entity; +import bdf.types.BdfNamedList; +import bdf.types.BdfObject; import projectzombie.display.Camera; +import projectzombie.init.Textures; import projectzombie.util.gl.GlHelpers; import projectzombie.util.gl.texture.TextureReference; import projectzombie.util.math.ItemStack; @@ -14,21 +17,65 @@ public class EntityItem extends EntityVertical private ItemStack stack; private double height = 0; private double height_speed; - private int pickup_time = 100; + private int pickup_time = 200; + private long age = 0; + + public double angle; + + public EntityItem(BdfObject bdf) { + super(bdf, TextureReference.EMPTY, new Vec2d(0.5, 0.5)); + } + + @Override + public void BdfClassLoad(BdfObject bdf) { + super.BdfClassLoad(bdf); + + BdfNamedList nl = bdf.getNamedList(); + stack = new ItemStack(nl.get("stack")); + height = nl.get("height").getDouble(); + height_speed = nl.get("speed_h").getDouble(); + pickup_time = nl.get("pickup").getInteger(); + age = nl.get("age").getLong(); + angle = nl.get("angle").getDouble(); + + tex = stack.item.texture; + } + + @Override + public void BdfClassSave(BdfObject bdf) { + super.BdfClassSave(bdf); + + BdfNamedList nl = bdf.getNamedList(); + stack.BdfClassSave(nl.get("stack")); + nl.set("height", BdfObject.withDouble(height)); + nl.set("speed_h", BdfObject.withDouble(height_speed)); + nl.set("pickup", BdfObject.withInteger(pickup_time)); + nl.set("age", BdfObject.withLong(age)); + nl.set("angle", BdfObject.withDouble(angle)); + } public EntityItem(Vec2d pos, ItemStack stack) { super(pos, stack.item.texture, new Vec2d(0.5, 0.5)); + this.emitsLight = true; this.opaqueTile = true; this.stack = stack; this.angle = RandomHelpers.randrange(rand, 360); height_speed = RandomHelpers.randrange(rand, 10000) / 200000.0; } + @Override + public double getLightLevel() { + if(this.stack.isEmpty()) return 0; + return getLightWithHeight(this.stack.item.getLightLevel()); + } + @Override public void tick(Chunk chunk, Layer layer) { super.tick(chunk, layer); + age += 1; + height += height_speed; height_speed -= 0.001; @@ -42,7 +89,30 @@ public class EntityItem extends EntityVertical } else { - moveForward(0.01); + moveTowards(angle, 0.01); + } + + // Merge nearby stacks + for(Entity e : layer.getNearbyEntities(pos, 1)) + { + if(e instanceof EntityItem && e != this) { + EntityItem ei = (EntityItem) e; + + if( + ei.stack.meta == this.stack.meta && + ei.stack.item == this.stack.item && + ei.age > this.age + ) { + this.pickup_time = 200; + this.stack.count += ei.stack.count; + this.pos = new Vec2d( + ei.pos.x / 2 + this.pos.x / 2, + ei.pos.y / 2 + this.pos.y / 2); + this.height = ei.height / 2 + this.height / 2; + this.height_speed = ei.height_speed / 2 + this.height_speed / 2; + ei.kill(); + } + } } if(pickup_time == 0) @@ -68,7 +138,7 @@ public class EntityItem extends EntityVertical public void render(Vec2d pos, Camera camera, TextureReference tex, Vec2d size) { GlHelpers.pushMatrix(); GlHelpers.translate3(0, 0, height); - super.render(pos, camera, tex, size); + super.render(pos, camera, stack.item.texture, size); GlHelpers.popMatrix(); } } diff --git a/src/projectzombie/entity/EntityKillWithParticles.java b/src/projectzombie/entity/EntityKillWithParticles.java new file mode 100755 index 0000000..4913b19 --- /dev/null +++ b/src/projectzombie/entity/EntityKillWithParticles.java @@ -0,0 +1,6 @@ +package projectzombie.entity; + +public interface EntityKillWithParticles +{ + public void killWithParticles(); +} diff --git a/src/projectzombie/entity/EntityParticle.java b/src/projectzombie/entity/EntityParticle.java old mode 100644 new mode 100755 index 0ccfc12..054e7bb --- a/src/projectzombie/entity/EntityParticle.java +++ b/src/projectzombie/entity/EntityParticle.java @@ -1,7 +1,9 @@ package projectzombie.entity; +import bdf.types.BdfObject; import projectzombie.Main; import projectzombie.display.Camera; +import projectzombie.settings.SettingQuality; import projectzombie.util.gl.GlHelpers; import projectzombie.util.math.vec.Vec2d; import projectzombie.world.chunk.Chunk; @@ -9,9 +11,15 @@ import projectzombie.world.layer.Layer; public class EntityParticle extends Entity { + public static SettingQuality MODE = SettingQuality.FANCY; + private double height; private double size; + public EntityParticle(BdfObject bdf) { + super(bdf); + } + public EntityParticle(Vec2d pos, double size, double height) { super(pos); @@ -34,7 +42,7 @@ public class EntityParticle extends Entity super.tick(chunk, layer); // Kill the particle if the player can't see it to reduce lag - if(Main.player.pos.squareDistance(pos) > 32) this.kill(); + if(Main.player.pos.squareDistance(pos) > Camera.camera.renderDistance * 16) this.kill(); } @Override diff --git a/src/projectzombie/entity/EntityTnt.java b/src/projectzombie/entity/EntityTnt.java old mode 100644 new mode 100755 index 94fac57..3b31eb5 --- a/src/projectzombie/entity/EntityTnt.java +++ b/src/projectzombie/entity/EntityTnt.java @@ -1,5 +1,7 @@ package projectzombie.entity; +import bdf.types.BdfNamedList; +import bdf.types.BdfObject; import projectzombie.display.Camera; import projectzombie.entity.particle.ParticleSpark; import projectzombie.init.Textures; @@ -18,6 +20,38 @@ public class EntityTnt extends EntityVertical private int explode_radius; private double explode_damage; + public EntityTnt(BdfObject bdf) { + super(bdf, Textures.ENTITY_TNT, new Vec2d(0.5, 0.5)); + } + + @Override + public void BdfClassLoad(BdfObject bdf) { + super.BdfClassLoad(bdf); + + BdfNamedList nl = bdf.getNamedList(); + height = nl.get("height").getDouble(); + velocity = new Vec3d(nl.get("velocity")); + + BdfNamedList explode = nl.get("explosion").getNamedList(); + explode_time = explode.get("time").getInteger(); + explode_radius = explode.get("radius").getInteger(); + explode_damage = explode.get("damage").getDouble(); + } + + @Override + public void BdfClassSave(BdfObject bdf) { + super.BdfClassSave(bdf); + + BdfNamedList nl = bdf.getNamedList(); + nl.set("height", BdfObject.withDouble(height)); + velocity.BdfClassSave(nl.get("velocity")); + + BdfNamedList explode = nl.get("explosion").getNamedList(); + explode.set("time", BdfObject.withInteger(explode_time)); + explode.set("radius", BdfObject.withInteger(explode_radius)); + explode.set("damage", BdfObject.withDouble(explode_damage)); + } + public EntityTnt(Vec2d pos, double angle, int explode_radius, double explode_damage) { super(pos, Textures.ENTITY_TNT, new Vec2d(0.5, 0.5)); @@ -93,7 +127,11 @@ public class EntityTnt extends EntityVertical @Override public double getLightLevel() { - return (1 - (this.height * (1/12.0))) * rand.nextDouble(); + return getLightWithHeight(1 - (this.height * (1/12.0))) * ( rand.nextDouble() / 10.0 + 0.9 ); + } + + @Override + protected void moveAwayFromSolidEntities(Layer layer) { } } diff --git a/src/projectzombie/entity/EntityVertical.java b/src/projectzombie/entity/EntityVertical.java old mode 100644 new mode 100755 index b818e30..0f9a806 --- a/src/projectzombie/entity/EntityVertical.java +++ b/src/projectzombie/entity/EntityVertical.java @@ -1,18 +1,27 @@ package projectzombie.entity; +import bdf.types.BdfObject; import projectzombie.display.Camera; +import projectzombie.entity.particle.ParticleBreak; import projectzombie.util.gl.GlHelpers; import projectzombie.util.gl.VerticalRender; +import projectzombie.util.gl.texture.IHasTexture; import projectzombie.util.gl.texture.TextureReference; import projectzombie.util.math.MathHelpers; import projectzombie.util.math.vec.Vec2d; import projectzombie.util.math.vec.Vec2i; import projectzombie.util.math.vec.Vec3d; -public class EntityVertical extends Entity +public class EntityVertical extends Entity implements IHasTexture { - private TextureReference tex; - private Vec2d size; + public TextureReference tex; + public Vec2d size; + + public EntityVertical(BdfObject bdf, TextureReference tex, Vec2d size) { + super(bdf); + this.size = size; + this.tex = tex; + } public EntityVertical(Vec2d pos, TextureReference tex, Vec2d size) { super(pos); @@ -37,4 +46,13 @@ public class EntityVertical extends Entity this.render(pos, camera, tex, size); GlHelpers.color4(1, 1, 1, 1); } + + @Override + public TextureReference getTexture() { + return tex; + } + + public void killWithParticles() { + ParticleBreak.spawnParticles(chunk, pos, this); + } } diff --git a/src/projectzombie/entity/EntityZombie.java b/src/projectzombie/entity/EntityZombie.java old mode 100644 new mode 100755 index 26e3844..ccd929f --- a/src/projectzombie/entity/EntityZombie.java +++ b/src/projectzombie/entity/EntityZombie.java @@ -1,27 +1,94 @@ package projectzombie.entity; +import java.util.Random; + +import bdf.types.BdfNamedList; +import bdf.types.BdfObject; import projectzombie.Main; import projectzombie.init.Textures; +import projectzombie.util.gl.texture.TextureReference; +import projectzombie.util.math.astar.AStar; +import projectzombie.util.math.astar.AStarSearcher; import projectzombie.util.math.random.OpenSimplexNoise; import projectzombie.util.math.vec.Vec2d; +import projectzombie.util.math.vec.Vec2i; import projectzombie.world.chunk.Chunk; import projectzombie.world.layer.Layer; -public class EntityZombie extends EntityVertical implements EntityAlive +public class EntityZombie extends EntityVertical implements EntityAlive, EntityKillWithParticles { protected OpenSimplexNoise noise_movement; protected OpenSimplexNoise noise_gun_fire; protected OpenSimplexNoise noise_gun_angle; protected OpenSimplexNoise noise_target_x; protected OpenSimplexNoise noise_target_y; + + protected long seed; + protected double time; protected double health_max = 100; protected double health = health_max; protected int gun_interval = 0; protected int gun_level = 0; + + private Vec2i walk_direction; + private int walk_scan_cooldown = 0; + private boolean can_see_player = false; + private int walking_for = 0; + private static final Vec2d size = new Vec2d(1, 1); + + public EntityZombie(BdfObject bdf) { + super(bdf, Textures.ENTITY_ZOMBIE_F, size); + + // Set some settings + hitbox = 0.5; + isSolid = true; + goThroughSolid = false; + crossUnWalkable = false; + } + + @Override + public void BdfClassLoad(BdfObject bdf) { + super.BdfClassLoad(bdf); + + BdfNamedList nl = bdf.getNamedList(); + health_max = nl.get("max_health").getDouble(); + health = nl.get("health").getDouble(); + gun_interval = nl.get("gun_interval").getInteger(); + gun_level = nl.get("gun_level").getInteger(); + seed = nl.get("seed").getLong(); + + + Random rand = new Random(seed); + + noise_movement = new OpenSimplexNoise(rand.nextLong()); + noise_gun_fire = new OpenSimplexNoise(rand.nextLong()); + noise_gun_angle = new OpenSimplexNoise(rand.nextLong()); + noise_target_x = new OpenSimplexNoise(rand.nextLong()); + noise_target_y = new OpenSimplexNoise(rand.nextLong()); + } + + @Override + public void BdfClassSave(BdfObject bdf) { + super.BdfClassSave(bdf); + + BdfNamedList nl = bdf.getNamedList(); + nl.set("max_health", BdfObject.withDouble(health_max)); + nl.set("health", BdfObject.withDouble(health)); + nl.set("gun_interval", BdfObject.withInteger(gun_interval)); + nl.set("gun_level", BdfObject.withInteger(gun_level)); + nl.set("seed", BdfObject.withLong(seed)); + + + } + public EntityZombie(Vec2d pos) { - super(pos, Textures.ENTITY_ZOMBIE, new Vec2d(1, 1)); + super(pos, Textures.ENTITY_ZOMBIE_F, size); + + seed = rand.nextLong(); + Random rand = new Random(seed); + noise_movement = new OpenSimplexNoise(rand.nextLong()); noise_gun_fire = new OpenSimplexNoise(rand.nextLong()); noise_gun_angle = new OpenSimplexNoise(rand.nextLong()); @@ -40,21 +107,48 @@ public class EntityZombie extends EntityVertical implements EntityAlive public void tick(Chunk chunk, Layer layer) { super.tick(chunk, layer); - // Get the player targeted area - Vec2d target = new Vec2d( - Main.player.pos.x + noise_target_x.eval(time*5, Main.player.pos.x/10, Main.player.pos.y/10)*10, - Main.player.pos.y + noise_target_y.eval(time*5, Main.player.pos.x/10, Main.player.pos.y/10)*10); + //System.out.println(walk_direction != null ? (walk_direction.x + ", " + walk_direction.y + ": " + pos.toInt().x + ", " + pos.toInt().y) : "null"); - // Get the angle between the player and the zombie - double angle_walk = Math.atan2(pos.x - target.x, pos.y - target.y); - double angle_fire = Math.atan2(pos.x - Main.player.pos.x, pos.y - Main.player.pos.y); + if(walk_direction == null) { + walk_scan_cooldown -= 1; + } - // Move forward towards the player - this.angle = Math.toDegrees(angle_walk) + 180; - this.moveForward(); - - if(noise_gun_fire.eval(time, 0) > 0 && !Main.player.dead && !Main.player.in_animation) + if( + (walk_direction != null && pos.toInt().equal(walk_direction) && + pos.squareDistance(Main.player.pos) > 2) || + walk_scan_cooldown < 1 || walking_for > 200) { + AStar astar = new AStar(pos.toInt(), 16, new AStarSearcher(layer, crossUnWalkable)); + Vec2i path[] = astar.getPath(Main.player.pos.toInt()); + + walk_scan_cooldown = 100; + walking_for = 0; + + if(path != null && path.length > 1) { + walk_direction = path[1]; + } else { + walk_direction = Main.player.pos.toInt(); + } + + can_see_player = (path != null); + } + + // Walk towards the player + if(walk_direction != null) + { + double angle = Math.toDegrees(Math.atan2( + walk_direction.x - (this.pos.x - 0.5) + noise_target_x.eval(time, pos.x/10, pos.y/10), + walk_direction.y - (this.pos.y - 0.5) + noise_target_y.eval(time, pos.x/10, pos.y/10))); + this.moveTowards(angle); + + walking_for += 1; + } + + if(can_see_player && noise_gun_fire.eval(time, 0) > 0 && !Main.player.dead && !Main.player.in_animation) + { + // Get the angle between the player and the zombie + double angle_fire = Math.atan2(pos.x - Main.player.pos.x, pos.y - Main.player.pos.y); + gun_interval += 1; gun_interval %= 10; @@ -66,8 +160,7 @@ public class EntityZombie extends EntityVertical implements EntityAlive // Fire the gun int d = (int)(1 + gun_level / 5.0); - int b = (int)(1 - gun_level / 5.0); - layer.spawnEntity(new EntityBullet(pos.copy(), this, angle_gun, 20*d*d, 5*b*b, 60)); + layer.spawnEntity(new EntityBullet(pos.copy(), this, angle_gun, 20*d*d, 60)); } } @@ -76,13 +169,16 @@ public class EntityZombie extends EntityVertical implements EntityAlive } @Override - public void moveForward() { - this.moveForward(0.06); + public TextureReference getTexture() { + return Textures.ENTITY_ZOMBIE_F; } - @Override - public void moveBackward() { - super.moveBackward(0.06); + public void moveInVector(Vec2d vec) { + super.moveInVector(vec, 0.06); + } + + public void moveTowards(double angle) { + super.moveTowards(angle, 0.06); } @Override diff --git a/src/projectzombie/entity/EntityZombieArmored.java b/src/projectzombie/entity/EntityZombieArmored.java old mode 100644 new mode 100755 index 66b4923..e339e93 --- a/src/projectzombie/entity/EntityZombieArmored.java +++ b/src/projectzombie/entity/EntityZombieArmored.java @@ -1,5 +1,6 @@ package projectzombie.entity; +import bdf.types.BdfObject; import projectzombie.display.Camera; import projectzombie.init.Textures; import projectzombie.util.gl.texture.TextureReference; @@ -7,7 +8,9 @@ import projectzombie.util.math.vec.Vec2d; public class EntityZombieArmored extends EntityZombie { - + public EntityZombieArmored(BdfObject bdf) { + super(bdf); + } public EntityZombieArmored(Vec2d pos) { super(pos); @@ -20,7 +23,7 @@ public class EntityZombieArmored extends EntityZombie @Override public void render(Vec2d pos, Camera camera, TextureReference tex, Vec2d size) { - super.render(pos, camera, Textures.ENTITY_ZOMBIE_ARMORED, new Vec2d(1, 1)); + super.render(pos, camera, Textures.ENTITY_ZOMBIE_F_ARMORED, size); } @Override diff --git a/src/projectzombie/entity/particle/ParticleBlood.java b/src/projectzombie/entity/particle/ParticleBlood.java old mode 100644 new mode 100755 index 0ff3edb..2100890 --- a/src/projectzombie/entity/particle/ParticleBlood.java +++ b/src/projectzombie/entity/particle/ParticleBlood.java @@ -4,6 +4,7 @@ import java.util.Random; import projectzombie.display.Camera; import projectzombie.entity.EntityParticle; +import projectzombie.settings.SettingQuality; import projectzombie.util.gl.GlHelpers; import projectzombie.util.math.MathHelpers; import projectzombie.util.math.random.RandomHelpers; @@ -19,17 +20,18 @@ public class ParticleBlood extends EntityParticle private double time = 1000; private double height = 0; private Vec3d velocity; - private double angle_height; public ParticleBlood(Random rand, Vec2d pos, double angle) { super(pos, rand.nextDouble() / 5, 0); - this.angle = angle + RandomHelpers.randrange(rand, -100, 100); - this.angle_height = RandomHelpers.randrange(rand, 9000, 18000) / 100; + angle += RandomHelpers.randrange(rand, -100, 100); + double angle_height = RandomHelpers.randrange(rand, 9000, 18000) / 100; this.height = rand.nextDouble(); r_color = RandomHelpers.randrange(rand, 200, 800) / 1000.0; velocity = MathHelpers.moveTowards3(0.1, - new Vec2d(Math.toRadians(this.angle), Math.toRadians(angle_height))); + new Vec2d(Math.toRadians(angle), Math.toRadians(angle_height))); + + time = RandomHelpers.randrange(rand, 800, 1200); } @Override @@ -55,6 +57,10 @@ public class ParticleBlood extends EntityParticle // Should this particle too old; destroy it if(time < 0) chunk.killEntity(this); + + if(MODE == SettingQuality.OFF) { + kill(); + } } @Override diff --git a/src/projectzombie/entity/particle/ParticleBreak.java b/src/projectzombie/entity/particle/ParticleBreak.java old mode 100644 new mode 100755 index 840c755..c9762e7 --- a/src/projectzombie/entity/particle/ParticleBreak.java +++ b/src/projectzombie/entity/particle/ParticleBreak.java @@ -2,8 +2,13 @@ package projectzombie.entity.particle; import projectzombie.Main; import projectzombie.display.Camera; +import projectzombie.entity.Entity; +import projectzombie.entity.EntityParticle; import projectzombie.entity.EntityVertical; +import projectzombie.settings.SettingQuality; +import projectzombie.tiles.TileVertical; import projectzombie.util.gl.GlHelpers; +import projectzombie.util.gl.texture.AnimationReference; import projectzombie.util.gl.texture.IHasTexture; import projectzombie.util.gl.texture.TextureReference; import projectzombie.util.math.MathHelpers; @@ -19,13 +24,73 @@ public class ParticleBreak extends EntityVertical { private double height = 0; private Vec3d velocity; - private int time = 1000; + private int time = 0; + private boolean landed = false; + + public static void spawnParticles(Chunk chunk, Vec2d pos, Entity e) + { + if(EntityParticle.MODE == SettingQuality.OFF) { + return; + } + + int height = 1; + + if(e instanceof EntityVertical) { + height = MathHelpers.floor(((EntityVertical)e).size.y); + } + + for(int i=0;i<50 * height;i++) { + chunk.spawnEntity(new ParticleBreak(pos.copy(), e)); + } + } + + public static void spawnParticles(Chunk chunk, Vec2d pos, TileState s) + { + if(EntityParticle.MODE == SettingQuality.OFF) { + return; + } + + int height = 1; + + if(s.tile instanceof TileVertical) { + height = MathHelpers.floor(((TileVertical)s.tile).size.y); + } + + for(int i=0;i<50 * height;i++) { + chunk.spawnEntity(new ParticleBreak(pos.copy(), s)); + } + } private static TextureReference getTexture(TileState ts) { if(ts.tile instanceof IHasTexture) { TextureReference tex = ((IHasTexture)ts.tile).getTexture(); + + if(tex instanceof AnimationReference) { + tex = ((AnimationReference)tex).c; + } + + int px = RandomHelpers.randrange(rand, tex.start_x, tex.end_x - 2); + int py = RandomHelpers.randrange(rand, tex.start_y, tex.end_y - 2); + return tex.getTextureReference(px, px + 2, py, py + 2); + } + + else { + return TextureReference.EMPTY; + } + } + + private static TextureReference getTexture(Entity entity) + { + if(entity instanceof IHasTexture) + { + TextureReference tex = ((IHasTexture)entity).getTexture(); + + if(tex instanceof AnimationReference) { + tex = ((AnimationReference)tex).c; + } + int px = RandomHelpers.randrange(rand, tex.start_x, tex.end_x - 2); int py = RandomHelpers.randrange(rand, tex.start_y, tex.end_y - 2); return tex.getTextureReference(px, px + 2, py, py + 2); @@ -37,14 +102,51 @@ public class ParticleBreak extends EntityVertical } public ParticleBreak(Vec2d pos, TileState ts) { - super(pos, getTexture(ts), new Vec2d(1/4.0, 1/4.0)); - this.opaqueTile = ts.tile.opaqueTile; - this.angle = RandomHelpers.randrange(rand, 360); + super(pos, getTexture(ts), new Vec2d(1/8.0, 1/8.0)); + double angle = RandomHelpers.randrange(rand, 360); + + if(EntityParticle.MODE == SettingQuality.FANCY) { + this.opaqueTile = ts.tile.opaqueTile; + } else { + this.opaqueTile = false; + } + + if(ts.tile instanceof TileVertical) { + TileVertical ts_v = (TileVertical) ts.tile; + + height = RandomHelpers.randrange(rand, 0, MathHelpers.floor(ts_v.size.y)); + } Vec2d side_v = MathHelpers.moveTowards2(0.01, Math.toRadians(angle)); velocity = new Vec3d( side_v.x, side_v.y, RandomHelpers.randrange(rand, 10000) / 200000.0); + + time = RandomHelpers.randrange(rand, 800, 1200); + } + + public ParticleBreak(Vec2d pos, Entity entity) { + super(pos, getTexture(entity), new Vec2d(1/8.0, 1/8.0)); + double angle = RandomHelpers.randrange(rand, 360); + + if(EntityParticle.MODE == SettingQuality.FANCY) { + this.opaqueTile = entity.opaqueTile; + } else { + this.opaqueTile = false; + } + + if(entity instanceof EntityVertical) { + EntityVertical entity_v = (EntityVertical) entity; + + height = RandomHelpers.randrange(rand, 0, MathHelpers.floor(entity_v.size.y)); + } + + Vec2d side_v = MathHelpers.moveTowards2(0.01, Math.toRadians(angle)); + velocity = new Vec3d( + side_v.x, side_v.y, + RandomHelpers.randrange(rand, 10000) / 200000.0); + + time = RandomHelpers.randrange(rand, 500, 1500); } @Override @@ -58,10 +160,18 @@ public class ParticleBreak extends EntityVertical time -= 1; - height += velocity.z; - velocity.z -= MathHelpers.FallSpeed; + if(!landed) { + height += velocity.z; + velocity.z -= MathHelpers.FallSpeed; + } - if(height < -1) { + if(height < 0) { + height = 0; + velocity = velocity.multiply(0); + landed = true; + } + + if(time < 0) { kill(); } @@ -69,6 +179,10 @@ public class ParticleBreak extends EntityVertical pos.x += velocity.x; pos.y += velocity.y; } + + if(EntityParticle.MODE == SettingQuality.OFF) { + kill(); + } } @Override diff --git a/src/projectzombie/entity/particle/ParticleLava.java b/src/projectzombie/entity/particle/ParticleLava.java old mode 100644 new mode 100755 index 9c5159f..7ee2126 --- a/src/projectzombie/entity/particle/ParticleLava.java +++ b/src/projectzombie/entity/particle/ParticleLava.java @@ -4,6 +4,7 @@ import java.util.Random; import projectzombie.display.Camera; import projectzombie.entity.EntityParticle; +import projectzombie.settings.SettingQuality; import projectzombie.util.gl.GlHelpers; import projectzombie.util.math.MathHelpers; import projectzombie.util.math.random.RandomHelpers; @@ -40,6 +41,10 @@ public class ParticleLava extends EntityParticle if(height < -1) { kill(); } + + if(MODE == SettingQuality.OFF) { + kill(); + } } @Override diff --git a/src/projectzombie/entity/particle/ParticleSmoke.java b/src/projectzombie/entity/particle/ParticleSmoke.java old mode 100644 new mode 100755 index c830bf7..1faa4da --- a/src/projectzombie/entity/particle/ParticleSmoke.java +++ b/src/projectzombie/entity/particle/ParticleSmoke.java @@ -2,8 +2,10 @@ package projectzombie.entity.particle; import projectzombie.Main; import projectzombie.display.Camera; +import projectzombie.entity.EntityParticle; import projectzombie.entity.EntityVertical; import projectzombie.init.Textures; +import projectzombie.settings.SettingQuality; import projectzombie.util.gl.GlHelpers; import projectzombie.util.math.random.RandomHelpers; import projectzombie.util.math.vec.Vec2d; @@ -48,6 +50,10 @@ public class ParticleSmoke extends EntityVertical height += height_speed; opacity -= disappear_speed; + + if(EntityParticle.MODE == SettingQuality.OFF) { + kill(); + } } } diff --git a/src/projectzombie/entity/particle/ParticleSpark.java b/src/projectzombie/entity/particle/ParticleSpark.java old mode 100644 new mode 100755 index 08e0ea3..993d541 --- a/src/projectzombie/entity/particle/ParticleSpark.java +++ b/src/projectzombie/entity/particle/ParticleSpark.java @@ -2,6 +2,7 @@ package projectzombie.entity.particle; import projectzombie.display.Camera; import projectzombie.entity.EntityParticle; +import projectzombie.settings.SettingQuality; import projectzombie.util.gl.GlHelpers; import projectzombie.util.math.vec.Vec2d; import projectzombie.world.chunk.Chunk; @@ -30,6 +31,10 @@ public class ParticleSpark extends EntityParticle // Destroy this particle kill(); } + + if(MODE == SettingQuality.OFF) { + kill(); + } } @Override diff --git a/src/projectzombie/entity/particle/ParticleWater.java b/src/projectzombie/entity/particle/ParticleWater.java old mode 100644 new mode 100755 index cf119c6..04054a8 --- a/src/projectzombie/entity/particle/ParticleWater.java +++ b/src/projectzombie/entity/particle/ParticleWater.java @@ -2,6 +2,7 @@ package projectzombie.entity.particle; import projectzombie.display.Camera; import projectzombie.entity.EntityParticle; +import projectzombie.settings.SettingQuality; import projectzombie.util.gl.GlHelpers; import projectzombie.util.math.MathHelpers; import projectzombie.util.math.random.RandomHelpers; @@ -20,7 +21,7 @@ public class ParticleWater extends EntityParticle super(pos, rand.nextDouble()/5, 0); // Set the velocity - velocity = MathHelpers.moveTowards3(0.1, new Vec2d(Math.toRadians( + velocity = MathHelpers.moveTowards3(0.05, new Vec2d(Math.toRadians( RandomHelpers.randrange(rand, 360)), Math.toRadians(RandomHelpers.randrange(rand, 0, 45)))); } @@ -38,6 +39,10 @@ public class ParticleWater extends EntityParticle if(height < 0) { kill(); } + + if(MODE == SettingQuality.OFF) { + kill(); + } } @Override @@ -46,9 +51,9 @@ public class ParticleWater extends EntityParticle GlHelpers.translate3(0, 0, height); Vec3d light = chunk.getRGBLightLevel(new Vec2i( MathHelpers.floor(pos.x), MathHelpers.floor(pos.y))); - GlHelpers.color4(0, 0, light.z, 0.4); + GlHelpers.color3(light.x * 0.2, light.y * 0.2, light.z * 0.6); super.render(pos, camera); - GlHelpers.color4(1, 1, 1, 1); + GlHelpers.color3(1, 1, 1); GlHelpers.popMatrix(); } diff --git a/src/projectzombie/entity/player/EntityPlayer.java b/src/projectzombie/entity/player/EntityPlayer.java old mode 100644 new mode 100755 index 62b9585..bb8e417 --- a/src/projectzombie/entity/player/EntityPlayer.java +++ b/src/projectzombie/entity/player/EntityPlayer.java @@ -1,15 +1,22 @@ package projectzombie.entity.player; +import java.io.FileOutputStream; +import java.util.zip.DeflaterOutputStream; + +import bdf.types.BdfIndent; +import bdf.types.BdfNamedList; +import bdf.types.BdfObject; import mainloop.task.IMainloopTask; import projectzombie.Main; import projectzombie.display.Camera; -import projectzombie.entity.Entity; import projectzombie.entity.EntityAlive; import projectzombie.entity.EntityBullet; import projectzombie.entity.EntityHeight; import projectzombie.entity.EntityInventory; import projectzombie.entity.EntityItem; import projectzombie.entity.EntityVertical; +import projectzombie.entity.particle.ParticleBreak; +import projectzombie.init.Items; import projectzombie.init.Textures; import projectzombie.inventory.Inventory; import projectzombie.menu.MenuDeath; @@ -20,7 +27,10 @@ import projectzombie.util.math.ItemStack; import projectzombie.util.math.MathHelpers; import projectzombie.util.math.vec.Vec2d; import projectzombie.util.math.vec.Vec2i; +import projectzombie.util.math.vec.Vec3d; +import projectzombie.world.World; import projectzombie.world.chunk.Chunk; +import projectzombie.world.chunk.ChunkEventHandler; import projectzombie.world.layer.Layer; public class EntityPlayer extends EntityVertical implements EntityAlive, EntityInventory, EntityHeight @@ -32,6 +42,9 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI public boolean GUN = false; public boolean moving = false; + public TextureReference PLAYER_MOVING = Textures.ENTITY_PLAYER_B_W_MOVING; + public TextureReference PLAYER_STILL = Textures.ENTITY_PLAYER_B_W_STILL; + public double height = 0; private int bullet_frequency = 0; @@ -48,8 +61,45 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI public int defence_level = 0; public int gun_level = 0; + public double angle; + public double speed; + private static final Vec2d size = new Vec2d(1, 1); + public EntityPlayer(BdfObject bdf) { + super(bdf, TextureReference.EMPTY, size); + } + + @Override + public void BdfClassLoad(BdfObject bdf) { + super.BdfClassLoad(bdf); + BdfNamedList nl = bdf.getNamedList(); + height = nl.get("height").getDouble(); + bullet_frequency = nl.get("bullet_frequency").getInteger(); + health = nl.get("health").getDouble(); + dead = nl.get("dead").getBoolean(); + inventory = new Inventory(nl.get("inventory")); + ammo = nl.get("ammo").getInteger(); + defence_level = nl.get("defence_level").getInteger(); + gun_level = nl.get("gun_level").getInteger(); + angle = nl.get("angle").getDouble(); + } + + @Override + public void BdfClassSave(BdfObject bdf) { + super.BdfClassSave(bdf); + BdfNamedList nl = bdf.getNamedList(); + nl.set("height", BdfObject.withDouble(height)); + nl.set("bullet_frequency", BdfObject.withInteger(bullet_frequency)); + nl.set("health", BdfObject.withDouble(health)); + nl.set("dead", BdfObject.withBoolean(dead)); + inventory.BdfClassSave(nl.get("inventory")); + nl.set("ammo", BdfObject.withInteger(ammo)); + nl.set("defence_level", BdfObject.withInteger(defence_level)); + nl.set("gun_level", BdfObject.withInteger(gun_level)); + nl.set("angle", BdfObject.withDouble(angle)); + } + public EntityPlayer() { super(new Vec2d(0, 0), TextureReference.EMPTY, size); @@ -61,24 +111,48 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI goThroughSolid = false; crossUnWalkable = false; emitsLight = true; + speed = 0.1; // Create the inventory inventory = new Inventory(6); + + inventory.setItem(new ItemStack(Items.LANTERN, 99, (byte)0), 2); + inventory.setItem(new ItemStack(Items.SPAWN_ZOMBIE, 99, (byte)0), 3); } @Override - public double getLightLevel() { - return 1; + public double getLightLevel() + { + if(Main.menu.playerEmitsLight) { + return getLightWithHeight(1); + } + + ItemStack item = inventory.getItem(inventory_hand); + + if(!item.isEmpty()) { + return getLightWithHeight(item.item.getLightLevel()); + } + + return 0; + } + + @Override + public TextureReference getTexture() { + return PLAYER_STILL; } @Override public void tick(Chunk chunk, Layer layer) { + chunk = layer.getChunk(pos); + if(dead) return; // Handle player deaths if(health <= 0) { + ParticleBreak.spawnParticles(chunk, pos, this); + if(Cheats.god_mode) { this.resetHealth(); } @@ -105,6 +179,8 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI } }); } + + return; } // Is the player dead or in an animation @@ -116,23 +192,23 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI // Rotate left if(MOVE_LEFT) { this.angle -= 1; - this.angle = MathHelpers.mod(this.angle, 360); } // Rotate right if(MOVE_RIGHT) { this.angle += 1; - this.angle = MathHelpers.mod(this.angle, 360); } + this.angle = MathHelpers.mod(this.angle, 360); + // Move forward if(MOVE_FORWARD) { - this.moveForward(); + this.moveTowards(this.angle); } // Move backward if(MOVE_BACKWARD) { - this.moveBackward(); + this.moveTowards(this.angle + 180); } // Use the gun @@ -145,9 +221,13 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI public void kill() { // Is god mode inactive; kill the player - if(!Cheats.god_mode) { - dead = true; + if(Cheats.god_mode) { + return; } + + ParticleBreak.spawnParticles(chunk, pos, this); + + dead = true; } @Override @@ -156,14 +236,8 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI super.moveTowards(angle, speed); } - @Override - public void moveForward() { - this.moveForward(0.08); - } - - @Override - public void moveBackward(double speed) { - super.moveBackward(0.08); + public void moveTowards(double angle) { + this.moveTowards(angle, 0.08); } @Override @@ -172,21 +246,26 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI // Don't render if the player is dead if(dead) return; + // Don't render if the chunk isnt loaded + if(!ChunkEventHandler.loaded) { + return; + } + // Translation GlHelpers.pushMatrix(); GlHelpers.translate3(0, 0, height); // Set the colour due to the lighting - double light = chunk.getDynamicLightLevel(new Vec2i( + Vec3d light = chunk.getRGBLightLevel(new Vec2i( MathHelpers.floor(pos.x), MathHelpers.floor(pos.y))); - GlHelpers.color3(light, light, light); + GlHelpers.color3(light.x, light.y, light.z); // Moving if(MOVE_BACKWARD || MOVE_FORWARD || moving) - super.render(pos, camera, Textures.ENTITY_PLAYER_MOVING, size); + super.render(pos, camera, PLAYER_MOVING, size); // Standing still - else super.render(pos, camera, Textures.ENTITY_PLAYER_STILL, size); + else super.render(pos, camera, PLAYER_STILL, size); // Pop the matrix GlHelpers.popMatrix(); @@ -207,9 +286,8 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI // Summon bullets at this angle relative to the player int d = (int)(1 + gun_level / 4.0); - int b = (int)(1 + gun_level / 4.0); Main.world.getLayer().spawnEntity(new EntityBullet(pos.copy(), this, angle + this.angle, - 20*d*d, 5/b, 60).withHeight(0, height)); + 20*d*d, 60).withHeight(0, height)); } } @@ -219,7 +297,7 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI ItemStack is = inventory.getItem(inventory_hand); if(!is.isEmpty()) { - is.item.onAction(is, Main.world.getLayer(), chunk, this); + is.item.onPlayerAction(is, Main.world.getLayer(), chunk, this); } } @@ -271,7 +349,7 @@ public class EntityPlayer extends EntityVertical implements EntityAlive, EntityI if(!i.isEmpty()) { - Entity e = new EntityItem(pos.copy(), new ItemStack(i.item, 1, i.meta)); + EntityItem e = new EntityItem(pos.copy(), new ItemStack(i.item, 1, i.meta)); e.angle = angle; Main.world.getLayer().spawnEntity(e); i.count -= 1; diff --git a/src/projectzombie/init/Entities.java b/src/projectzombie/init/Entities.java old mode 100644 new mode 100755 index 3d1ef97..d5b9223 --- a/src/projectzombie/init/Entities.java +++ b/src/projectzombie/init/Entities.java @@ -2,9 +2,48 @@ package projectzombie.init; import java.util.ArrayList; +import bdf.types.BdfObject; import projectzombie.entity.Entity; +import projectzombie.entity.EntityBoss; +import projectzombie.entity.EntityBullet; +import projectzombie.entity.EntityDummy; +import projectzombie.entity.EntityExplosion; +import projectzombie.entity.EntityFlare; +import projectzombie.entity.EntityGrapplingHook; +import projectzombie.entity.EntityItem; +import projectzombie.entity.EntityTnt; +import projectzombie.entity.EntityZombie; +import projectzombie.entity.EntityZombieArmored; +import projectzombie.entity.player.EntityPlayer; public class Entities { - public static final ArrayList entities = new ArrayList(); + public static final ArrayList> entities = new ArrayList<>(); + + private static void register(Class e) + { + try { + e.getConstructor(BdfObject.class); + } catch (NoSuchMethodException | SecurityException err) { + err.printStackTrace(); + System.exit(1); + } + + entities.add(e); + } + + public static void init() + { + register(EntityZombie.class); + register(EntityZombieArmored.class); + register(EntityTnt.class); + register(EntityItem.class); + register(EntityGrapplingHook.class); + register(EntityFlare.class); + register(EntityExplosion.class); + register(EntityDummy.class); + register(EntityBullet.class); + register(EntityBoss.class); + register(EntityPlayer.class); + } } diff --git a/src/projectzombie/init/Items.java b/src/projectzombie/init/Items.java old mode 100644 new mode 100755 index 6c6e324..51b7570 --- a/src/projectzombie/init/Items.java +++ b/src/projectzombie/init/Items.java @@ -1,5 +1,7 @@ package projectzombie.init; +import java.util.ArrayList; + import projectzombie.items.Item; import projectzombie.items.ItemAmmo; import projectzombie.items.ItemDefenceUpgrade; @@ -9,17 +11,49 @@ import projectzombie.items.ItemGrapplingHook; import projectzombie.items.ItemGunUpgrade; import projectzombie.items.ItemHealthPotion; import projectzombie.items.ItemLantern; +import projectzombie.items.ItemRock; import projectzombie.items.ItemTnt; +import projectzombie.items.spawner.ItemSpawnZombie; public class Items { - public static final Item AMMO = new ItemAmmo("ammo"); - public static final Item DEFENCE_UPGRADE = new ItemDefenceUpgrade("defence_upgrade"); - public static final Item GUN_UPGRADE = new ItemGunUpgrade("gun_upgrade"); - public static final Item HEALTH_POTION = new ItemHealthPotion("health_potion"); - public static final Item EMPTY = new ItemEmpty("empty"); - public static final Item TNT = new ItemTnt("tnt"); - public static final Item LANTERN = new ItemLantern("lantern"); - public static final Item FLARE = new ItemFlare("flare"); - public static final Item GRAPPLING_HOOK = new ItemGrapplingHook("grappling_hook"); + public static ArrayList items = new ArrayList(); + + private static void register(Item item) { + item.id = items.size(); + items.add(item); + } + + public static void init() + { + register(EMPTY); + + register(AMMO); + register(DEFENCE_UPGRADE); + register(GUN_UPGRADE); + register(HEALTH_POTION); + register(TNT); + register(LANTERN); + register(FLARE); + register(GRAPPLING_HOOK); + + register(SPAWN_ZOMBIE); + register(ROCK); + + register(AMMO); + } + + public static final Item AMMO = new ItemAmmo(); + public static final Item DEFENCE_UPGRADE = new ItemDefenceUpgrade(); + public static final Item GUN_UPGRADE = new ItemGunUpgrade(); + public static final Item HEALTH_POTION = new ItemHealthPotion(); + public static final Item EMPTY = new ItemEmpty(); + public static final Item TNT = new ItemTnt(); + public static final Item LANTERN = new ItemLantern(); + public static final Item FLARE = new ItemFlare(); + public static final Item GRAPPLING_HOOK = new ItemGrapplingHook(); + + public static final Item SPAWN_ZOMBIE = new ItemSpawnZombie(); + + public static final Item ROCK = new ItemRock(); } diff --git a/src/projectzombie/init/LayerGenerators.java b/src/projectzombie/init/LayerGenerators.java new file mode 100755 index 0000000..7c74c50 --- /dev/null +++ b/src/projectzombie/init/LayerGenerators.java @@ -0,0 +1,46 @@ +package projectzombie.init; + +import java.util.ArrayList; + +import projectzombie.world.layer.layergen.LayerGen; +import projectzombie.world.layer.layergen.LayerGenBossArena; +import projectzombie.world.layer.layergen.LayerGenCaves; +import projectzombie.world.layer.layergen.LayerGenEarth; +import projectzombie.world.layer.layergen.LayerGenLavaCaves; + +public class LayerGenerators +{ + private static final ArrayList lgens = new ArrayList(); + + private static void register(LayerGen lg) { + lg.id = lgens.size(); + lgens.add(lg); + } + + public static void init() + { + register(EARTH); + register(CAVES); + register(LAVA_CAVES); + register(BOSS_ARENA); + } + + public static LayerGen loadFromID(int id) { + return lgens.get(id); + } + + public static int getLGID(LayerGen lg) { + for(int i=0;i id_layers = new ArrayList(); - public static void init(long seed) { // Create all the layers - EARTH = new Layer(new Random(seed), new LayerGenEarth(), 0); - CAVES = new Layer(new Random(seed), new LayerGenCaves(), 1); - LAVA_CAVES = new Layer(new Random(seed), new LayerGenLavaCaves(), 2); - - // Setup all the id-able layers - id_layers = new ArrayList(); - id_layers.add(EARTH); - id_layers.add(CAVES); - id_layers.add(LAVA_CAVES); + EARTH = new Layer(new Random(seed), LayerGenerators.EARTH); + CAVES = new Layer(new Random(seed), LayerGenerators.CAVES); + 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(); - Main.world.setLayer(EARTH); - } - - public static Layer getLayer(int id) { - return id_layers.get(id); + Main.world.addLayer(EARTH); + Main.world.addLayer(CAVES); + Main.world.addLayer(LAVA_CAVES); + Main.world.setLayer(0); } public static Layer EARTH; diff --git a/src/projectzombie/init/Resources.java b/src/projectzombie/init/Resources.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/init/Sounds.java b/src/projectzombie/init/Sounds.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/init/Textures.java b/src/projectzombie/init/Textures.java old mode 100644 new mode 100755 index 2c406d4..c167a39 --- a/src/projectzombie/init/Textures.java +++ b/src/projectzombie/init/Textures.java @@ -97,37 +97,70 @@ public class Textures public static final TextureReference ITEM_GUN_UPGRADE = texmap.getTextureReference(0, 1, 4, 5); public static final TextureReference ITEM_DEFENCE_UPGRADE = texmap.getTextureReference(1, 2, 4, 5); - // Fire - public static final TextureReference TILE_FIRE_0 = texmap.getTextureReference(0, 1, 1, 2); - public static final TextureReference TILE_FIRE_1 = texmap.getTextureReference(1, 2, 1, 2); - public static final TextureReference TILE_FIRE_2 = texmap.getTextureReference(2, 3, 1, 2); - public static final TextureReference TILE_FIRE_3 = texmap.getTextureReference(3, 4, 1, 2); - public static final TextureReference TILE_FIRE = new AnimationReference( - 8, TILE_FIRE_0, TILE_FIRE_1, TILE_FIRE_2, TILE_FIRE_3); + public static final TextureReference ITEM_ROCK = texmap.getTextureReference(0, 1, 3, 4); - // Player - public static final TextureReference ENTITY_PLAYER_STILL = texmap.getTextureReference(0, 1, 2, 3); - public static final TextureReference ENTITY_PLAYER_MOVING = new AnimationReference(10, - texmap.getTextureReference(0, 1, 2, 3), - texmap.getTextureReference(1, 2, 2, 3), - texmap.getTextureReference(2, 3, 2, 3), - texmap.getTextureReference(3, 4, 2, 3) + // Player Back White Varient + public static final TextureReference ENTITY_PLAYER_B_W_STILL = texmap.getTextureReference(28, 29, 0, 1); + public static final TextureReference ENTITY_PLAYER_B_W_MOVING = new AnimationReference(10, + texmap.getTextureReference(28, 29, 0, 1), + texmap.getTextureReference(29, 30, 0, 1), + texmap.getTextureReference(30, 31, 0, 1), + texmap.getTextureReference(31, 32, 0, 1) + ); + + // Player Front White Varient + public static final TextureReference ENTITY_PLAYER_F_W_STILL = texmap.getTextureReference(28, 29, 1, 2); + public static final TextureReference ENTITY_PLAYER_F_W_MOVING = new AnimationReference(10, + texmap.getTextureReference(28, 29, 1, 2), + texmap.getTextureReference(29, 30, 1, 2), + texmap.getTextureReference(30, 31, 1, 2), + texmap.getTextureReference(31, 32, 1, 2) + ); + + // Player Back Black Varient + public static final TextureReference ENTITY_PLAYER_B_B_STILL = texmap.getTextureReference(28, 29, 2, 3); + public static final TextureReference ENTITY_PLAYER_B_B_MOVING = new AnimationReference(10, + texmap.getTextureReference(28, 29, 2, 3), + texmap.getTextureReference(29, 30, 2, 3), + texmap.getTextureReference(30, 31, 2, 3), + texmap.getTextureReference(31, 32, 2, 3) + ); + + // Player Front Black Varient + public static final TextureReference ENTITY_PLAYER_F_B_STILL = texmap.getTextureReference(28, 29, 3, 4); + public static final TextureReference ENTITY_PLAYER_F_B_MOVING = new AnimationReference(10, + texmap.getTextureReference(28, 29, 3, 4), + texmap.getTextureReference(29, 30, 3, 4), + texmap.getTextureReference(30, 31, 3, 4), + texmap.getTextureReference(31, 32, 3, 4) ); // Zombie - public static final TextureReference ENTITY_ZOMBIE = new AnimationReference(10, - texmap.getTextureReference(0, 1, 3, 4), - texmap.getTextureReference(1, 2, 3, 4), - texmap.getTextureReference(2, 3, 3, 4), - texmap.getTextureReference(3, 4, 3, 4) + public static final TextureReference ENTITY_ZOMBIE_B = new AnimationReference(10, + texmap.getTextureReference(28, 29, 4, 5), + texmap.getTextureReference(29, 30, 4, 5), + texmap.getTextureReference(30, 31, 4, 5), + texmap.getTextureReference(31, 32, 4, 5) + ); + public static final TextureReference ENTITY_ZOMBIE_F = new AnimationReference(10, + texmap.getTextureReference(28, 29, 5, 6), + texmap.getTextureReference(29, 30, 5, 6), + texmap.getTextureReference(30, 31, 5, 6), + texmap.getTextureReference(31, 32, 5, 6) ); // Zombie Bomber - public static final TextureReference ENTITY_ZOMBIE_ARMORED = new AnimationReference(10, - texmap.getTextureReference(2, 3, 15, 16), - texmap.getTextureReference(3, 4, 15, 16), - texmap.getTextureReference(4, 5, 15, 16), - texmap.getTextureReference(5, 6, 15, 16) + public static final TextureReference ENTITY_ZOMBIE_B_ARMORED = new AnimationReference(10, + texmap.getTextureReference(28, 29, 6, 7), + texmap.getTextureReference(29, 30, 6, 7), + texmap.getTextureReference(30, 31, 6, 7), + texmap.getTextureReference(31, 32, 6, 7) + ); + public static final TextureReference ENTITY_ZOMBIE_F_ARMORED = new AnimationReference(10, + texmap.getTextureReference(28, 29, 7, 8), + texmap.getTextureReference(29, 30, 7, 8), + texmap.getTextureReference(30, 31, 7, 8), + texmap.getTextureReference(31, 32, 7, 8) ); // Water diff --git a/src/projectzombie/init/Tiles.java b/src/projectzombie/init/Tiles.java old mode 100644 new mode 100755 index 408a640..39a76a8 --- a/src/projectzombie/init/Tiles.java +++ b/src/projectzombie/init/Tiles.java @@ -1,10 +1,11 @@ package projectzombie.init; +import java.util.ArrayList; + import projectzombie.tiles.Tile; import projectzombie.tiles.TileBossPortal; import projectzombie.tiles.TileChest; import projectzombie.tiles.TileDirt; -import projectzombie.tiles.TileFire; import projectzombie.tiles.TileGrass; import projectzombie.tiles.TileLadder; import projectzombie.tiles.TileLadderUp; @@ -24,24 +25,59 @@ import projectzombie.tiles.TileWaterFlow; public class Tiles { - public static final Tile GRASS = new TileGrass("grass"); - public static final Tile FIRE = new TileFire("fire"); - public static final Tile SAND = new TileSand("sand"); - public static final Tile STONE = new TileStone("stone"); - public static final Tile DIRT = new TileDirt("dirt"); - public static final Tile TREE = new TileTree("tree"); - public static final Tile VOID = new TileVoid("void"); - public static final Tile ROCK = new TileRock("rock"); - public static final Tile LAVA = new TileLava("lava"); - public static final Tile WATER = new TileWater("water"); - public static final Tile LAVA_FLOW = new TileLavaFlow("lava_flow"); - public static final Tile WATER_FLOW = new TileWaterFlow("water_flow"); - public static final Tile LADDER = new TileLadder("ladder"); - public static final Tile PORTAL_DOWN = new TilePortalDown("portal_down"); - public static final Tile WALL = new TileWall("wall"); - public static final Tile LADDER_UP = new TileLadderUp("ladder_up"); - public static final Tile CHEST = new TileChest("chest"); - public static final Tile LANTERN = new TileLantern("lantern"); - public static final Tile WALL_UNBREAKABLE = new TileWallUnbreakable("wall_unbreakable"); - public static final Tile BOSS_PORTAL = new TileBossPortal("boss_portal"); + public static ArrayList tiles = new ArrayList(); + + private static void register(Tile tile) + { + int id = tiles.size(); + + if(id > Short.MAX_VALUE) { + throw new RuntimeException("Too many tiles registered. Maximum tiles: " + Short.MAX_VALUE); + } + + tile.id = (short)id; + tiles.add(tile); + } + + public static void init() { + register(VOID); + register(GRASS); + register(SAND); + register(STONE); + register(DIRT); + register(TREE); + register(ROCK); + register(LAVA); + register(WATER); + register(LAVA_FLOW); + register(WATER_FLOW); + register(LADDER); + register(PORTAL_DOWN); + register(WALL); + register(LADDER_UP); + register(CHEST); + register(LANTERN); + register(WALL_UNBREAKABLE); + register(BOSS_PORTAL); + } + + public static final Tile GRASS = new TileGrass(); + public static final Tile SAND = new TileSand(); + public static final Tile STONE = new TileStone(); + public static final Tile DIRT = new TileDirt(); + public static final Tile TREE = new TileTree(); + public static final Tile VOID = new TileVoid(); + public static final Tile ROCK = new TileRock(); + public static final Tile LAVA = new TileLava(); + public static final Tile WATER = new TileWater(); + public static final Tile LAVA_FLOW = new TileLavaFlow(); + public static final Tile WATER_FLOW = new TileWaterFlow(); + public static final Tile LADDER = new TileLadder(); + public static final Tile PORTAL_DOWN = new TilePortalDown(); + public static final Tile WALL = new TileWall(); + public static final Tile LADDER_UP = new TileLadderUp(); + public static final Tile CHEST = new TileChest(); + public static final Tile LANTERN = new TileLantern(); + public static final Tile WALL_UNBREAKABLE = new TileWallUnbreakable(); + public static final Tile BOSS_PORTAL = new TileBossPortal(); } diff --git a/src/projectzombie/input/CursorEnterCallback.java b/src/projectzombie/input/CursorEnterCallback.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/input/CursorPosCallback.java b/src/projectzombie/input/CursorPosCallback.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/input/GameInput.java b/src/projectzombie/input/GameInput.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/input/InputMode.java b/src/projectzombie/input/InputMode.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/input/JoystickCallback.java b/src/projectzombie/input/JoystickCallback.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/input/KeyCallback.java b/src/projectzombie/input/KeyCallback.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/input/KeyCharCallback.java b/src/projectzombie/input/KeyCharCallback.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/input/MouseButtonCallback.java b/src/projectzombie/input/MouseButtonCallback.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/input/ScrollWheelCallback.java b/src/projectzombie/input/ScrollWheelCallback.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/input/types/Input.java b/src/projectzombie/input/types/Input.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/input/types/InputGUI.java b/src/projectzombie/input/types/InputGUI.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/input/types/InputGame.java b/src/projectzombie/input/types/InputGame.java old mode 100644 new mode 100755 index 3a7ac5a..074d58b --- a/src/projectzombie/input/types/InputGame.java +++ b/src/projectzombie/input/types/InputGame.java @@ -4,6 +4,7 @@ import projectzombie.Main; import projectzombie.menu.MenuGamePause; import projectzombie.util.math.MathHelpers; import projectzombie.util.math.vec.Vec2d; +import projectzombie.world.chunk.ChunkEventHandler; public class InputGame implements Input { @@ -14,7 +15,9 @@ public class InputGame implements Input if(state) { // Move the player in the left sticks angle - Main.player.moveTowards(angle); + if(ChunkEventHandler.loaded) { + Main.player.moveTowards(angle + Main.player.angle); + } // Set the players moving to true Main.player.moving = true; diff --git a/src/projectzombie/inventory/IInventory.java b/src/projectzombie/inventory/IInventory.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/inventory/Inventory.java b/src/projectzombie/inventory/Inventory.java old mode 100644 new mode 100755 index 6f53f8d..a06a9e3 --- a/src/projectzombie/inventory/Inventory.java +++ b/src/projectzombie/inventory/Inventory.java @@ -1,8 +1,12 @@ package projectzombie.inventory; +import bdf.classes.IBdfClassManager; +import bdf.types.BdfArray; +import bdf.types.BdfNamedList; +import bdf.types.BdfObject; import projectzombie.util.math.ItemStack; -public class Inventory implements IInventory +public class Inventory implements IInventory, IBdfClassManager { protected ItemStack[] items; @@ -43,5 +47,37 @@ public class Inventory implements IInventory items[slot] = ItemStack.EMPTY; return stack; } + + @Override + public void BdfClassLoad(BdfObject bdf) + { + BdfNamedList nl = bdf.getNamedList(); + items = new ItemStack[nl.get("size").getInteger()]; + + BdfArray array = nl.get("items").getArray(); + + for(int i=0;i start + 8) { + if(System.currentTimeMillis() > start + 5) { tasks.remove(0); } } diff --git a/src/projectzombie/mainloop/MainloopIterator.java b/src/projectzombie/mainloop/MainloopIterator.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/menu/Menu.java b/src/projectzombie/menu/Menu.java old mode 100644 new mode 100755 index a3913f6..5f3742e --- a/src/projectzombie/menu/Menu.java +++ b/src/projectzombie/menu/Menu.java @@ -8,6 +8,7 @@ public abstract class Menu public boolean doGameRender; public boolean keepMouse = true; public boolean showIngameGUI = true; + public boolean playerEmitsLight = false; public Input input; public abstract void render(); diff --git a/src/projectzombie/menu/MenuDeath.java b/src/projectzombie/menu/MenuDeath.java old mode 100644 new mode 100755 index bf7bb2e..fbe6dbb --- a/src/projectzombie/menu/MenuDeath.java +++ b/src/projectzombie/menu/MenuDeath.java @@ -1,8 +1,10 @@ package projectzombie.menu; +import projectzombie.Main; import projectzombie.input.types.InputGUI; import projectzombie.menu.gui.ButtonGroup; import projectzombie.menu.gui.GUI; +import projectzombie.menu.gui.components.ButtonBasic; import projectzombie.menu.gui.components.ButtonGroupPause; import projectzombie.menu.gui.components.LabelPause; import projectzombie.menu.gui.components.OverlayBackground; @@ -20,9 +22,14 @@ public class MenuDeath extends Menu this.input = new InputGUI(this.gui); gui.add(new OverlayBackground()); - gui.add(new LabelPause("You Died!")); + gui.add(new LabelPause("You were slain")); ButtonGroup group = new ButtonGroupPause(); + + group.add(new ButtonBasic("Quit", button -> { + Main.menu = new MenuMain(); + })); + gui.setSelected(group.get(0)); gui.add(group); } diff --git a/src/projectzombie/menu/MenuGame.java b/src/projectzombie/menu/MenuGame.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/menu/MenuGamePause.java b/src/projectzombie/menu/MenuGamePause.java old mode 100644 new mode 100755 index 8e30e44..44453c0 --- a/src/projectzombie/menu/MenuGamePause.java +++ b/src/projectzombie/menu/MenuGamePause.java @@ -1,9 +1,16 @@ package projectzombie.menu; +import java.io.FileOutputStream; +import java.util.zip.DeflaterOutputStream; + +import bdf.types.BdfIndent; +import bdf.types.BdfObject; import projectzombie.Main; import projectzombie.input.types.InputGUI; +import projectzombie.menu.gui.Button; import projectzombie.menu.gui.ButtonGroup; import projectzombie.menu.gui.GUI; +import projectzombie.menu.gui.components.ButtonBasic; import projectzombie.menu.gui.components.ButtonGroupPause; import projectzombie.menu.gui.components.GUIBackToMenu; import projectzombie.menu.gui.components.LabelPause; @@ -25,6 +32,11 @@ public class MenuGamePause extends Menu gui.add(new LabelPause("Game Paused")); ButtonGroup group = new ButtonGroupPause(); + + group.add(new ButtonBasic("Save And Exit", button -> { + saveAndQuit(); + })); + gui.setSelected(group.get(0)); gui.add(group); } @@ -33,4 +45,51 @@ public class MenuGamePause extends Menu public void render() { gui.render(); } + + public void saveAndQuit() + { + long now, cur = 0; + + BdfObject bdf = new BdfObject(); + + now = System.currentTimeMillis(); + Main.world.BdfClassSave(bdf); + cur = System.currentTimeMillis(); + System.out.println("Time for BdfClassSave: " + (cur - now)); + now = cur; + + System.out.println("Size on file: " + bdf.serialize().length()); + //System.out.println(bdf.serializeHumanReadable()); + + try { + + /* + + FileOutputStream os = new FileOutputStream("./layer.hbdf"); + os.write(bdf.serializeHumanReadable(new BdfIndent("\t", "\n")).getBytes()); + os.close(); + + cur = System.currentTimeMillis(); + System.out.println("Time for HBDF: " + (cur - now)); + now = cur; + + */ + + FileOutputStream os2 = new FileOutputStream("./layer.bdf"); + DeflaterOutputStream dos = new DeflaterOutputStream(os2); + dos.write(bdf.serialize().getBytes()); + dos.close(); + os2.close(); + + cur = System.currentTimeMillis(); + System.out.println("Time for BDF: " + (cur - now)); + now = cur; + } + + catch(Exception e) { + e.printStackTrace(); + } + + Main.menu = new MenuMain(); + } } diff --git a/src/projectzombie/menu/MenuMain.java b/src/projectzombie/menu/MenuMain.java old mode 100644 new mode 100755 index 048a305..cf48022 --- a/src/projectzombie/menu/MenuMain.java +++ b/src/projectzombie/menu/MenuMain.java @@ -16,6 +16,7 @@ public class MenuMain extends Menu this.doGameRender = true; this.keepMouse = false; this.showIngameGUI = false; + this.playerEmitsLight = true; this.gui = new GUI(); this.input = new InputGUI(gui); diff --git a/src/projectzombie/menu/MenuSettings.java b/src/projectzombie/menu/MenuSettings.java old mode 100644 new mode 100755 index 9558222..baef517 --- a/src/projectzombie/menu/MenuSettings.java +++ b/src/projectzombie/menu/MenuSettings.java @@ -2,6 +2,7 @@ package projectzombie.menu; import projectzombie.Main; import projectzombie.display.DisplayRenderUI; +import projectzombie.entity.EntityParticle; import projectzombie.input.types.InputGUI; import projectzombie.menu.gui.Button; import projectzombie.menu.gui.ButtonGroup; @@ -12,6 +13,7 @@ import projectzombie.menu.gui.components.ButtonBasic; import projectzombie.menu.gui.components.ButtonSetting; import projectzombie.menu.gui.components.GUIBackToMenu; import projectzombie.menu.gui.components.OverlayBackground; +import projectzombie.settings.SettingQuality; import projectzombie.util.math.vec.Vec2d; import projectzombie.world.chunk.Chunk; @@ -20,6 +22,12 @@ public class MenuSettings extends Menu private GUI gui; private Menu menuOld; + private String qualitySettingToString(SettingQuality sq) { + return sq == SettingQuality.OFF ? "Off" : + sq == SettingQuality.FAST ? "Fast" : + sq == SettingQuality.FANCY ? "Fancy" : null; + } + public MenuSettings(Menu menuOld) { this.menuOld = menuOld; @@ -27,6 +35,7 @@ public class MenuSettings extends Menu doGameloop = false; doGameRender = menuOld.doGameRender; showIngameGUI = menuOld.showIngameGUI; + playerEmitsLight = menuOld.playerEmitsLight; keepMouse = false; ButtonGroup group = new ButtonGroup(); @@ -60,6 +69,34 @@ public class MenuSettings extends Menu button.setText("GUI Scale: " + DisplayRenderUI.guiScale); })); + group.add(new ButtonSetting("Particles: " + qualitySettingToString(EntityParticle.MODE), button -> { + + switch(EntityParticle.MODE) { + + case OFF: { + EntityParticle.MODE = SettingQuality.FAST; + break; + } + + case FAST: { + EntityParticle.MODE = SettingQuality.FANCY; + break; + } + + case FANCY: { + EntityParticle.MODE = SettingQuality.OFF; + break; + } + + default: { + break; + } + + } + + button.setText("Particles: " + qualitySettingToString(EntityParticle.MODE)); + })); + /*group.add(new ButtonSetting("Dynamic Lighting: " + (LightingManager.lightingMode == 0 ? "Fast" : "Fancy"), button -> { diff --git a/src/projectzombie/menu/gui/Alignment.java b/src/projectzombie/menu/gui/Alignment.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/menu/gui/Button.java b/src/projectzombie/menu/gui/Button.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/menu/gui/ButtonGroup.java b/src/projectzombie/menu/gui/ButtonGroup.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/menu/gui/GUI.java b/src/projectzombie/menu/gui/GUI.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/menu/gui/GUIComponent.java b/src/projectzombie/menu/gui/GUIComponent.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/menu/gui/GUIContainer.java b/src/projectzombie/menu/gui/GUIContainer.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/menu/gui/GUISelectable.java b/src/projectzombie/menu/gui/GUISelectable.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/menu/gui/GUISelectableDirection.java b/src/projectzombie/menu/gui/GUISelectableDirection.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/menu/gui/Label.java b/src/projectzombie/menu/gui/Label.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/menu/gui/Overlay.java b/src/projectzombie/menu/gui/Overlay.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/menu/gui/components/ButtonBasic.java b/src/projectzombie/menu/gui/components/ButtonBasic.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/menu/gui/components/ButtonCallback.java b/src/projectzombie/menu/gui/components/ButtonCallback.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/menu/gui/components/ButtonGroupPause.java b/src/projectzombie/menu/gui/components/ButtonGroupPause.java old mode 100644 new mode 100755 index 9d62d87..a4385fe --- a/src/projectzombie/menu/gui/components/ButtonGroupPause.java +++ b/src/projectzombie/menu/gui/components/ButtonGroupPause.java @@ -14,10 +14,6 @@ public class ButtonGroupPause extends ButtonGroup Main.menu.input.mousePos(new Vec2d(0, 0)); Main.menu = new MenuSettings(Main.menu); })); - - add(new ButtonBasic("Quit", button -> { - Main.menu = new MenuMain(); - })); setPos(new Vec2d(0, -2)); } diff --git a/src/projectzombie/menu/gui/components/ButtonSetting.java b/src/projectzombie/menu/gui/components/ButtonSetting.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/menu/gui/components/GUIBackToMenu.java b/src/projectzombie/menu/gui/components/GUIBackToMenu.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/menu/gui/components/LabelMain.java b/src/projectzombie/menu/gui/components/LabelMain.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/menu/gui/components/LabelPause.java b/src/projectzombie/menu/gui/components/LabelPause.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/menu/gui/components/OverlayBackground.java b/src/projectzombie/menu/gui/components/OverlayBackground.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/resources/Resource.java b/src/projectzombie/resources/Resource.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/settings/Cheats.java b/src/projectzombie/settings/Cheats.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/settings/Environment.java b/src/projectzombie/settings/Environment.java old mode 100644 new mode 100755 index c34dcf5..e745d03 --- a/src/projectzombie/settings/Environment.java +++ b/src/projectzombie/settings/Environment.java @@ -1,5 +1,7 @@ package projectzombie.settings; +import projectzombie.world.chunk.Chunk; + public class Environment { public static String gdir = "."; @@ -15,6 +17,10 @@ public class Environment gdir = split[1]; } } + + if(arg.startsWith("--show-chunks")) { + Chunk.SHOW_CHUNKS = true; + } } } } diff --git a/src/projectzombie/settings/SettingQuality.java b/src/projectzombie/settings/SettingQuality.java new file mode 100755 index 0000000..2a112c9 --- /dev/null +++ b/src/projectzombie/settings/SettingQuality.java @@ -0,0 +1,5 @@ +package projectzombie.settings; + +public enum SettingQuality { + OFF, FAST, FANCY +} diff --git a/src/projectzombie/settings/Settings.java b/src/projectzombie/settings/Settings.java old mode 100644 new mode 100755 index 5055443..c557b44 --- a/src/projectzombie/settings/Settings.java +++ b/src/projectzombie/settings/Settings.java @@ -7,6 +7,7 @@ import bdf.types.BdfNamedList; import bdf.types.BdfObject; import bdf.types.BdfTypes; import projectzombie.display.DisplayRenderUI; +import projectzombie.entity.EntityParticle; import projectzombie.world.chunk.Chunk; public class Settings implements IBdfClassManager @@ -41,6 +42,23 @@ public class Settings implements IBdfClassManager } else { DisplayRenderUI.guiScale = 2; } + + switch(nl.get("particles").getByte()) { + + case 0: + EntityParticle.MODE = SettingQuality.FANCY; + break; + case 1: + EntityParticle.MODE = SettingQuality.FAST; + break; + case 2: + EntityParticle.MODE = SettingQuality.OFF; + break; + default: + EntityParticle.MODE = SettingQuality.FANCY; + break; + + } } @Override @@ -50,6 +68,10 @@ public class Settings implements IBdfClassManager nl.set("show_fps", BdfObject.withBoolean(DisplayRenderUI.showFPS)); nl.set("show_pos", BdfObject.withBoolean(DisplayRenderUI.showPos)); nl.set("gui_scale", BdfObject.withInteger(DisplayRenderUI.guiScale)); + nl.set("particles", BdfObject.withByte((byte)( + EntityParticle.MODE == SettingQuality.FANCY ? 0 : + EntityParticle.MODE == SettingQuality.FAST ? 1 : + EntityParticle.MODE == SettingQuality.OFF ? 2 : 0))); } public static void init() { diff --git a/src/projectzombie/text/Text.java b/src/projectzombie/text/Text.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/tiles/Tile.java b/src/projectzombie/tiles/Tile.java old mode 100644 new mode 100755 index c4ea391..edeee39 --- a/src/projectzombie/tiles/Tile.java +++ b/src/projectzombie/tiles/Tile.java @@ -12,7 +12,7 @@ import projectzombie.world.layer.Layer; public class Tile implements ITransparentObject { - private String id; + public short id; public boolean opaqueTile = false; public boolean tileSolid = false; public boolean tileWalkable = true; @@ -20,17 +20,9 @@ public class Tile implements ITransparentObject public double slowness = 0; public boolean unbreakable = false; protected double light_dissipation = 1/8.0; - public boolean emitsLight = true; + public boolean emitsLight = false; public boolean passNaturalLight = true; - public Tile(String id) { - this.id = id; - } - - public String getID() { - return this.id; - } - @Override public void render(Vec2d pos, Camera camera, TileState state) { } diff --git a/src/projectzombie/tiles/TileBossPortal.java b/src/projectzombie/tiles/TileBossPortal.java old mode 100644 new mode 100755 index d3135b0..dfa261e --- a/src/projectzombie/tiles/TileBossPortal.java +++ b/src/projectzombie/tiles/TileBossPortal.java @@ -7,6 +7,7 @@ import projectzombie.Main; import projectzombie.entity.Entity; import projectzombie.entity.particle.ParticleBreak; import projectzombie.entity.player.EntityPlayer; +import projectzombie.init.LayerGenerators; import projectzombie.init.Textures; import projectzombie.util.math.MathHelpers; import projectzombie.util.math.TileState; @@ -20,8 +21,8 @@ public class TileBossPortal extends TileVertical { private static Random rand = new Random(); - public TileBossPortal(String id) { - super(id, Textures.TILE_BOSS_PORTAL, new Vec2d(2, 2)); + public TileBossPortal() { + super(Textures.TILE_BOSS_PORTAL, new Vec2d(2, 2)); this.emitsLight = true; this.opaqueTile = true; @@ -46,11 +47,13 @@ public class TileBossPortal extends TileVertical ep.height = 5; // Create the boss arena - LayerGenBossArena layergen = new LayerGenBossArena(); + LayerGenBossArena layergen = (LayerGenBossArena) LayerGenerators.BOSS_ARENA; layergen.spawnPlayer(ep); layer.setFrontTile(TileState.EMPTY, tpos); - layer.spawnEntity(new ParticleBreak(new Vec2d(tpos.x+0.5, tpos.y+0.5), state)); - Main.world.setLayer(new Layer(rand, layergen, rand.nextInt())); + ParticleBreak.spawnParticles(layer.getChunk(tpos), size, state); + + int id = Main.world.addLayer(new Layer(rand, layergen)); + Main.world.setLayer(id); // Do the arena falling animation Main.mainloop.register(new IMainloopTask() diff --git a/src/projectzombie/tiles/TileBulletBreakable.java b/src/projectzombie/tiles/TileBulletBreakable.java new file mode 100755 index 0000000..cf122c8 --- /dev/null +++ b/src/projectzombie/tiles/TileBulletBreakable.java @@ -0,0 +1,6 @@ +package projectzombie.tiles; + +public interface TileBulletBreakable +{ + public int getBulletBreakChance(); +} diff --git a/src/projectzombie/tiles/TileChest.java b/src/projectzombie/tiles/TileChest.java old mode 100644 new mode 100755 index 653a10d..94a9a03 --- a/src/projectzombie/tiles/TileChest.java +++ b/src/projectzombie/tiles/TileChest.java @@ -15,13 +15,13 @@ import projectzombie.util.math.vec.Vec2i; import projectzombie.world.chunk.Chunk; import projectzombie.world.layer.Layer; -public class TileChest extends TileVertical +public class TileChest extends TileVertical implements TileBulletBreakable { public static final short CHEST_CAVES = 1; public static final short CHEST_LAVA_CAVES = 2; - public TileChest(String id) { - super(id, Textures.TILE_CHEST, new Vec2d(1, 1)); + public TileChest() { + super(Textures.TILE_CHEST, new Vec2d(1, 1)); this.tileSolid = true; this.opaqueTile = true; @@ -110,5 +110,10 @@ public class TileChest extends TileVertical layer.breakFrontTile(tpos); } + + @Override + public int getBulletBreakChance() { + return 25; + } } diff --git a/src/projectzombie/tiles/TileDirt.java b/src/projectzombie/tiles/TileDirt.java old mode 100644 new mode 100755 index 77a18f9..16a74d6 --- a/src/projectzombie/tiles/TileDirt.java +++ b/src/projectzombie/tiles/TileDirt.java @@ -5,8 +5,8 @@ import projectzombie.init.Textures; public class TileDirt extends TileFlatFaded { - public TileDirt(String id) { - super(id, Textures.TILE_DIRT); + public TileDirt() { + super(Textures.TILE_DIRT); } } \ No newline at end of file diff --git a/src/projectzombie/tiles/TileFire.java b/src/projectzombie/tiles/TileFire.java deleted file mode 100644 index 55c4df4..0000000 --- a/src/projectzombie/tiles/TileFire.java +++ /dev/null @@ -1,16 +0,0 @@ -package projectzombie.tiles; - -import projectzombie.init.Textures; -import projectzombie.util.math.vec.Vec2d; - -public class TileFire extends TileVertical -{ - - public TileFire(String id) { - super(id, Textures.TILE_FIRE, new Vec2d(1, 6)); - - // Set some settings - this.opaqueTile = true; - } - -} diff --git a/src/projectzombie/tiles/TileFlat.java b/src/projectzombie/tiles/TileFlat.java old mode 100644 new mode 100755 index 2a73589..96e1e42 --- a/src/projectzombie/tiles/TileFlat.java +++ b/src/projectzombie/tiles/TileFlat.java @@ -14,8 +14,7 @@ public class TileFlat extends Tile implements IHasTexture protected boolean rotates = false; private static final Vec3d default_tile_color = new Vec3d(1, 1, 1); - public TileFlat(String id, TextureReference tex) { - super(id); + public TileFlat(TextureReference tex) { this.tex = tex; } diff --git a/src/projectzombie/tiles/TileFlatFaded.java b/src/projectzombie/tiles/TileFlatFaded.java old mode 100644 new mode 100755 index 9e2dee8..bacec17 --- a/src/projectzombie/tiles/TileFlatFaded.java +++ b/src/projectzombie/tiles/TileFlatFaded.java @@ -9,8 +9,8 @@ import projectzombie.util.math.vec.Vec3d; public class TileFlatFaded extends TileFlat { - public TileFlatFaded(String id, TextureReference tex) { - super(id, tex); + public TileFlatFaded(TextureReference tex) { + super(tex); } @Override diff --git a/src/projectzombie/tiles/TileGrass.java b/src/projectzombie/tiles/TileGrass.java old mode 100644 new mode 100755 index b716948..5a8f21f --- a/src/projectzombie/tiles/TileGrass.java +++ b/src/projectzombie/tiles/TileGrass.java @@ -5,8 +5,8 @@ import projectzombie.init.Textures; public class TileGrass extends TileFlat { - public TileGrass(String id) { - super(id, Textures.TILE_GRASS); + public TileGrass() { + super(Textures.TILE_GRASS); } } diff --git a/src/projectzombie/tiles/TileLadder.java b/src/projectzombie/tiles/TileLadder.java old mode 100644 new mode 100755 index 7deadd4..8326c37 --- a/src/projectzombie/tiles/TileLadder.java +++ b/src/projectzombie/tiles/TileLadder.java @@ -8,8 +8,8 @@ import projectzombie.util.math.vec.Vec2i; public class TileLadder extends TileVertical { - public TileLadder(String id) { - super(id, Textures.TILE_LADDER, new Vec2d(1, 1)); + public TileLadder() { + super(Textures.TILE_LADDER, new Vec2d(1, 1)); this.opaqueTile = true; this.tileSolid = true; diff --git a/src/projectzombie/tiles/TileLadderUp.java b/src/projectzombie/tiles/TileLadderUp.java old mode 100644 new mode 100755 index e01c6ff..55500da --- a/src/projectzombie/tiles/TileLadderUp.java +++ b/src/projectzombie/tiles/TileLadderUp.java @@ -4,7 +4,6 @@ import mainloop.task.IMainloopTask; import projectzombie.Main; import projectzombie.entity.Entity; import projectzombie.entity.player.EntityPlayer; -import projectzombie.init.Layers; import projectzombie.init.Textures; import projectzombie.mainloop.MainloopEventHandler; import projectzombie.util.math.TileState; @@ -15,8 +14,8 @@ import projectzombie.world.layer.Layer; public class TileLadderUp extends TileVertical { - public TileLadderUp(String id) { - super(id, Textures.TILE_LADDER_UP, new Vec2d(1, 16)); + public TileLadderUp() { + super(Textures.TILE_LADDER_UP, new Vec2d(1, 16)); this.opaqueTile = true; this.tileSolid = true; @@ -60,8 +59,12 @@ public class TileLadderUp extends TileVertical if(player.height >= 6 && movingPlayer == 0) { movingPlayer = 1; - Main.world.setLayer(Layers.getLayer(state.meta)); + Main.world.setLayer(state.meta); player.height = -1; + + if(layer.layergen.destroyOnLeave) { + Main.world.removeLayer(state.meta); + } } else if(movingPlayer == 1 && ChunkEventHandler.loaded) diff --git a/src/projectzombie/tiles/TileLantern.java b/src/projectzombie/tiles/TileLantern.java old mode 100644 new mode 100755 index defb996..eb58a39 --- a/src/projectzombie/tiles/TileLantern.java +++ b/src/projectzombie/tiles/TileLantern.java @@ -13,8 +13,8 @@ import projectzombie.world.layer.Layer; public class TileLantern extends TileVertical { - public TileLantern(String id) { - super(id, Textures.TILE_LANTERN, new Vec2d(1, 1)); + public TileLantern() { + super(Textures.TILE_LANTERN, new Vec2d(1, 1)); this.emitsLight = true; this.opaqueTile = true; @@ -22,7 +22,7 @@ public class TileLantern extends TileVertical @Override public double getLightLevel(TileState state, Vec2i pos) { - return 0.8; + return 1; } @Override diff --git a/src/projectzombie/tiles/TileLava.java b/src/projectzombie/tiles/TileLava.java old mode 100644 new mode 100755 index ed53275..0875189 --- a/src/projectzombie/tiles/TileLava.java +++ b/src/projectzombie/tiles/TileLava.java @@ -17,11 +17,13 @@ public class TileLava extends TileFlat { private Random rand = new Random(); - public TileLava(String id) { - super(id, Textures.TILE_LAVA); + public TileLava() { + super(Textures.TILE_LAVA); + this.slowness = 0.5; this.tileWalkable = false; this.emitsLight = true; + this.unbreakable = true; } @Override diff --git a/src/projectzombie/tiles/TileLavaFlow.java b/src/projectzombie/tiles/TileLavaFlow.java old mode 100644 new mode 100755 index 0108f2a..a5ec609 --- a/src/projectzombie/tiles/TileLavaFlow.java +++ b/src/projectzombie/tiles/TileLavaFlow.java @@ -17,10 +17,11 @@ public class TileLavaFlow extends TileFlat { private Random rand = new Random(); - public TileLavaFlow(String id) { - super(id, Textures.TILE_LAVA_FLOW); + public TileLavaFlow() { + super(Textures.TILE_LAVA_FLOW); this.emitsLight = true; + this.unbreakable = true; } @Override diff --git a/src/projectzombie/tiles/TilePortalDown.java b/src/projectzombie/tiles/TilePortalDown.java old mode 100644 new mode 100755 index f8e3d13..4641d00 --- a/src/projectzombie/tiles/TilePortalDown.java +++ b/src/projectzombie/tiles/TilePortalDown.java @@ -4,7 +4,6 @@ import mainloop.task.IMainloopTask; import projectzombie.Main; import projectzombie.entity.Entity; import projectzombie.entity.player.EntityPlayer; -import projectzombie.init.Layers; import projectzombie.init.Textures; import projectzombie.mainloop.MainloopEventHandler; import projectzombie.util.math.TileState; @@ -15,8 +14,8 @@ import projectzombie.world.layer.Layer; public class TilePortalDown extends TileFlat { - public TilePortalDown(String id) { - super(id, Textures.TILE_PORTAL); + public TilePortalDown() { + super(Textures.TILE_PORTAL); this.unbreakable = true; } @@ -57,8 +56,12 @@ public class TilePortalDown extends TileFlat if(player.height < -1 && movingPlayer == 0) { movingPlayer = 1; - Main.world.setLayer(Layers.getLayer(state.meta)); + Main.world.setLayer(state.meta); player.height = 6; + + if(layer.layergen.destroyOnLeave) { + Main.world.removeLayer(state.meta); + } } else if(ChunkEventHandler.loaded && movingPlayer == 1) diff --git a/src/projectzombie/tiles/TileRock.java b/src/projectzombie/tiles/TileRock.java old mode 100644 new mode 100755 index 89d0df9..9585c95 --- a/src/projectzombie/tiles/TileRock.java +++ b/src/projectzombie/tiles/TileRock.java @@ -1,14 +1,20 @@ package projectzombie.tiles; +import projectzombie.entity.Entity; +import projectzombie.entity.EntityItem; +import projectzombie.init.Items; import projectzombie.init.Textures; +import projectzombie.util.math.ItemStack; import projectzombie.util.math.TileState; import projectzombie.util.math.vec.Vec2d; +import projectzombie.util.math.vec.Vec2i; +import projectzombie.world.layer.Layer; -public class TileRock extends TileVertical +public class TileRock extends TileVertical implements TileBulletBreakable { - public TileRock(String id) { - super(id, Textures.TILE_ROCK, new Vec2d(1, 1)); + public TileRock() { + super(Textures.TILE_ROCK, new Vec2d(1, 1)); // Set some settings this.opaqueTile = true; @@ -21,4 +27,17 @@ public class TileRock extends TileVertical return 1/8.0; } + @Override + public void onActivated(Layer layer, Vec2i tpos, Entity entity, TileState state) { + super.onActivated(layer, tpos, entity, state); + + layer.breakFrontTile(tpos); + layer.spawnEntity(new EntityItem(new Vec2d(tpos.x + 0.5, tpos.y + 0.5), new ItemStack(Items.ROCK, 1, (byte)0))); + } + + @Override + public int getBulletBreakChance() { + return 15; + } + } diff --git a/src/projectzombie/tiles/TileSand.java b/src/projectzombie/tiles/TileSand.java old mode 100644 new mode 100755 index 63e8326..8f8b83e --- a/src/projectzombie/tiles/TileSand.java +++ b/src/projectzombie/tiles/TileSand.java @@ -5,8 +5,8 @@ import projectzombie.init.Textures; public class TileSand extends TileFlat { - public TileSand(String id) { - super(id, Textures.TILE_SAND); + public TileSand() { + super(Textures.TILE_SAND); } } \ No newline at end of file diff --git a/src/projectzombie/tiles/TileStone.java b/src/projectzombie/tiles/TileStone.java old mode 100644 new mode 100755 index 235170d..233564b --- a/src/projectzombie/tiles/TileStone.java +++ b/src/projectzombie/tiles/TileStone.java @@ -5,8 +5,8 @@ import projectzombie.init.Textures; public class TileStone extends TileFlatFaded { - public TileStone(String id) { - super(id, Textures.TILE_STONE); + public TileStone() { + super(Textures.TILE_STONE); } } diff --git a/src/projectzombie/tiles/TileTree.java b/src/projectzombie/tiles/TileTree.java old mode 100644 new mode 100755 index f305073..bb76bf7 --- a/src/projectzombie/tiles/TileTree.java +++ b/src/projectzombie/tiles/TileTree.java @@ -4,10 +4,10 @@ import projectzombie.init.Textures; import projectzombie.util.math.TileState; import projectzombie.util.math.vec.Vec2d; -public class TileTree extends TileVertical +public class TileTree extends TileVertical implements TileBulletBreakable { - public TileTree(String id) { - super(id, Textures.TILE_TREE, new Vec2d(1, 4)); + public TileTree() { + super(Textures.TILE_TREE, new Vec2d(1, 4)); // Set some settings this.opaqueTile = true; @@ -20,6 +20,9 @@ public class TileTree extends TileVertical return 1/8.0; } - + @Override + public int getBulletBreakChance() { + return 35; + } } diff --git a/src/projectzombie/tiles/TileVertical.java b/src/projectzombie/tiles/TileVertical.java old mode 100644 new mode 100755 index 0051ce3..488d39d --- a/src/projectzombie/tiles/TileVertical.java +++ b/src/projectzombie/tiles/TileVertical.java @@ -10,11 +10,10 @@ import projectzombie.util.math.vec.Vec2d; public class TileVertical extends Tile implements IHasTexture { - private TextureReference tex; - private Vec2d size; + public final TextureReference tex; + public final Vec2d size; - public TileVertical(String id, TextureReference tex, Vec2d size) { - super(id); + public TileVertical(TextureReference tex, Vec2d size) { // Store some variables this.tex = tex; diff --git a/src/projectzombie/tiles/TileVoid.java b/src/projectzombie/tiles/TileVoid.java old mode 100644 new mode 100755 index 6aed8a4..45c1f7c --- a/src/projectzombie/tiles/TileVoid.java +++ b/src/projectzombie/tiles/TileVoid.java @@ -2,8 +2,7 @@ package projectzombie.tiles; public class TileVoid extends Tile { - public TileVoid(String id) { - super(id); + public TileVoid() { // Set some settings this.tileSolid = false; diff --git a/src/projectzombie/tiles/TileWall.java b/src/projectzombie/tiles/TileWall.java old mode 100644 new mode 100755 index eda5c48..8150a9f --- a/src/projectzombie/tiles/TileWall.java +++ b/src/projectzombie/tiles/TileWall.java @@ -1,19 +1,24 @@ package projectzombie.tiles; import projectzombie.init.Textures; +import projectzombie.util.math.TileState; public class TileWall extends TileFlat { - public TileWall(String id) { - super(id, Textures.TILE_WALL); + public TileWall() { + super(Textures.TILE_WALL); this.tileWalkable = false; this.tileSolid = true; this.tileHitbox = 1; - this.light_dissipation = 1/2.0; this.passNaturalLight = false; } + @Override + public double getLightDissipation(TileState state) { + return 1/2.0; + } + } diff --git a/src/projectzombie/tiles/TileWallUnbreakable.java b/src/projectzombie/tiles/TileWallUnbreakable.java old mode 100644 new mode 100755 index 550a162..272f92e --- a/src/projectzombie/tiles/TileWallUnbreakable.java +++ b/src/projectzombie/tiles/TileWallUnbreakable.java @@ -3,8 +3,7 @@ package projectzombie.tiles; public class TileWallUnbreakable extends TileWall { - public TileWallUnbreakable(String id) { - super(id); + public TileWallUnbreakable() { this.unbreakable = true; } diff --git a/src/projectzombie/tiles/TileWater.java b/src/projectzombie/tiles/TileWater.java old mode 100644 new mode 100755 index aa052f3..500a06a --- a/src/projectzombie/tiles/TileWater.java +++ b/src/projectzombie/tiles/TileWater.java @@ -14,10 +14,11 @@ import projectzombie.world.layer.Layer; public class TileWater extends TileFlat { - public TileWater(String id) { - super(id, Textures.TILE_WATER); + public TileWater() { + super(Textures.TILE_WATER); this.slowness = 0.5; this.rotates = true; + this.unbreakable = true; } @Override diff --git a/src/projectzombie/tiles/TileWaterFlow.java b/src/projectzombie/tiles/TileWaterFlow.java old mode 100644 new mode 100755 index 41fd180..258a9a2 --- a/src/projectzombie/tiles/TileWaterFlow.java +++ b/src/projectzombie/tiles/TileWaterFlow.java @@ -9,8 +9,10 @@ import projectzombie.util.math.vec.Vec2d; public class TileWaterFlow extends TileFlat { - public TileWaterFlow(String id) { - super(id, Textures.TILE_WATER_FLOW); + public TileWaterFlow() { + super(Textures.TILE_WATER_FLOW); + + this.unbreakable = true; } @Override diff --git a/src/projectzombie/time/GameTimer.java b/src/projectzombie/time/GameTimer.java old mode 100644 new mode 100755 index 7d427ec..c47819b --- a/src/projectzombie/time/GameTimer.java +++ b/src/projectzombie/time/GameTimer.java @@ -7,11 +7,14 @@ public class GameTimer implements IMainloopTask { private static long time; - public static long getTime() { return time; } + public static void setTime(long v) { + time = v; + } + public static void forceTimeUpdate(int amount) { time += amount; } @@ -30,6 +33,7 @@ public class GameTimer implements IMainloopTask public void MainLoopUpdate() { if(Main.menu.doGameloop) { time += 1; + //time = 40000; } } diff --git a/src/projectzombie/time/NoSleep.java b/src/projectzombie/time/NoSleep.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/util/gl/GlHelpers.java b/src/projectzombie/util/gl/GlHelpers.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/util/gl/VerticalRender.java b/src/projectzombie/util/gl/VerticalRender.java old mode 100644 new mode 100755 index e9463bf..6e75079 --- a/src/projectzombie/util/gl/VerticalRender.java +++ b/src/projectzombie/util/gl/VerticalRender.java @@ -8,6 +8,10 @@ public class VerticalRender { public static void render(Vec2d pos, Camera camera, TextureReference tex, Vec2d size) { + if(tex == null) { + return; + } + double w = size.x/2.0; double h = size.y; diff --git a/src/projectzombie/util/gl/texture/AnimationEventHandler.java b/src/projectzombie/util/gl/texture/AnimationEventHandler.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/util/gl/texture/AnimationReference.java b/src/projectzombie/util/gl/texture/AnimationReference.java old mode 100644 new mode 100755 index 4206636..2fd16ab --- a/src/projectzombie/util/gl/texture/AnimationReference.java +++ b/src/projectzombie/util/gl/texture/AnimationReference.java @@ -8,7 +8,7 @@ public class AnimationReference extends TextureReference private TextureReference[] references; private int upto = 0; private int speed; - private TextureReference c; + public TextureReference c; public AnimationReference(int speed, TextureReference ... references) { @@ -43,5 +43,10 @@ public class AnimationReference extends TextureReference public int getMaxY() { return c.getMaxY(); } + + @Override + public TextureReference getTextureReference(int start_x, int end_x, int start_y, int end_y) { + return c.getTextureReference(start_x, end_x, start_y, end_y); + } } diff --git a/src/projectzombie/util/gl/texture/IHasTexture.java b/src/projectzombie/util/gl/texture/IHasTexture.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/util/gl/texture/Texture.java b/src/projectzombie/util/gl/texture/Texture.java old mode 100644 new mode 100755 index be8939b..796de7a --- a/src/projectzombie/util/gl/texture/Texture.java +++ b/src/projectzombie/util/gl/texture/Texture.java @@ -23,7 +23,8 @@ public class Texture // Load the texture with STBImage this.texture = STBImage.stbi_load_from_memory( tex.getByteBuffer(), - width, height, channels, STBImage.STBI_rgb_alpha); + width, height, channels, + STBImage.STBI_rgb_alpha); // Check for a failure String failure = STBImage.stbi_failure_reason(); diff --git a/src/projectzombie/util/gl/texture/TextureMap.java b/src/projectzombie/util/gl/texture/TextureMap.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/util/gl/texture/TextureReference.java b/src/projectzombie/util/gl/texture/TextureReference.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/util/gl/texture/TextureReferenceEmpty.java b/src/projectzombie/util/gl/texture/TextureReferenceEmpty.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/util/gl/texture/TextureReferenceRandom.java b/src/projectzombie/util/gl/texture/TextureReferenceRandom.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/util/math/ColorRange.java b/src/projectzombie/util/math/ColorRange.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/util/math/ItemStack.java b/src/projectzombie/util/math/ItemStack.java old mode 100644 new mode 100755 index 7003df9..01a79de --- a/src/projectzombie/util/math/ItemStack.java +++ b/src/projectzombie/util/math/ItemStack.java @@ -1,9 +1,12 @@ package projectzombie.util.math; +import bdf.classes.IBdfClassManager; +import bdf.types.BdfNamedList; +import bdf.types.BdfObject; import projectzombie.init.Items; import projectzombie.items.Item; -public class ItemStack +public class ItemStack implements IBdfClassManager { public short meta; public Item item; @@ -33,4 +36,24 @@ public class ItemStack if(other.meta != meta) return false; return true; } + + @Override + public void BdfClassLoad(BdfObject bdf) { + BdfNamedList nl = bdf.getNamedList(); + meta = nl.get("meta").getShort(); + count = nl.get("count").getInteger(); + item = Items.items.get(nl.get("item").getInteger()); + } + + @Override + public void BdfClassSave(BdfObject bdf) { + BdfNamedList nl = bdf.getNamedList(); + nl.set("meta", BdfObject.withShort(meta)); + nl.set("count", BdfObject.withInteger(count)); + nl.set("item", BdfObject.withInteger(item.id)); + } + + public ItemStack(BdfObject bdf) { + BdfClassLoad(bdf); + } } diff --git a/src/projectzombie/util/math/MathHelpers.java b/src/projectzombie/util/math/MathHelpers.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/util/math/NamedList.java b/src/projectzombie/util/math/NamedList.java new file mode 100755 index 0000000..cfc4fad --- /dev/null +++ b/src/projectzombie/util/math/NamedList.java @@ -0,0 +1,54 @@ +package projectzombie.util.math; + +import java.util.ArrayList; + +class NamedListObject { + String id; + T object; + + public NamedListObject(String id, T object) { + this.object = object; + this.id = id; + } +} + +public class NamedList +{ + private ArrayList> objects; + + public T get(String id) + { + for(NamedListObject o : objects) { + if(o.id.contentEquals(id)) { + return o.object; + } + } + + return null; + } + + public void set(String id, T object) + { + for(NamedListObject o : objects) { + if(o.id.contentEquals(id)) { + o.object = object; + return; + } + } + + objects.add(new NamedListObject(id, object)); + } + + public T remove(String id) + { + for(int i=0;i o = objects.get(i); + if(o.id.contentEquals(id)) { + objects.remove(i); + return o.object; + } + } + + return null; + } +} diff --git a/src/projectzombie/util/math/TileState.java b/src/projectzombie/util/math/TileState.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/util/math/astar/AStar.java b/src/projectzombie/util/math/astar/AStar.java new file mode 100755 index 0000000..c4ba841 --- /dev/null +++ b/src/projectzombie/util/math/astar/AStar.java @@ -0,0 +1,184 @@ +package projectzombie.util.math.astar; +import java.util.ArrayList; +import java.util.List; + +import projectzombie.util.math.vec.Vec2i; + +class Node +{ + int x, y; + int g, h; + Node parent; + + public Node(Node parent, int x, int y, int g, int h) { + this.parent = parent; + this.x = x; + this.y = y; + this.g = g; + this.h = h; + } +} + +public class AStar +{ + AStarSearch search; + + Vec2i start; + Vec2i goal; + int radius; + + List open; + List closed; + + Node now; + Node found; + + public AStar(Vec2i start, int radius, AStarSearch search) + { + this.search = search; + this.start = start; + this.radius = radius; + } + + public Vec2i[] getPath(Vec2i goal) + { + // Goal out of range + if(this.posOutOfRange(goal.x, goal.y)) { + return null; + } + + // Start is a wall + if(search.getWeight(start.x, start.y) == 100) { + return null; + } + + this.goal = goal; + this.open = new ArrayList(); + this.closed = new ArrayList(); + + now = new Node(null, start.x, start.y, 0, 0); + closed.add(now); + + addNeighboursToList(); + + while(open.size() > 0) + { + // Found the goal + if(found != null) + { + Node n = found; + + ArrayList path = new ArrayList(); + + while(n != null) { + path.add(new Vec2i(n.x, n.y)); + n = n.parent; + } + + Vec2i[] path2 = new Vec2i[path.size()]; + + for(int i=0;i nodes, int x, int y) { + for(Node n : nodes) { + if(n.x == x && n.y == y) { + return true; + } + } + return false; + } + + private boolean posOutOfRange(int x, int y) { + return ( + x > start.x + radius || + x < start.x - radius || + y > start.y + radius || + y < start.y - radius); + } + + private void addNeighboursToList() + { + int neighbours[] = { + 1, 0, + -1, 0, + 0, 1, + 0, -1 + }; + + for(int i=0;i 0 || tsb.tile.tileHitbox > 0) { + return 100; + } + + if(tsf.tile.slowness > 0 || tsb.tile.slowness > 0) { + return (int)(MathHelpers.biggest(tsf.tile.slowness, tsb.tile.slowness) * 100); + } + + return 0; + } + +} diff --git a/src/projectzombie/util/math/map/IMap2D.java b/src/projectzombie/util/math/map/IMap2D.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/util/math/map/Map2D.java b/src/projectzombie/util/math/map/Map2D.java old mode 100644 new mode 100755 index b8050be..a428eca --- a/src/projectzombie/util/math/map/Map2D.java +++ b/src/projectzombie/util/math/map/Map2D.java @@ -112,6 +112,10 @@ public class Map2D implements Iterable> // Return false if nothing was found return false; } + + public int size() { + return elements.size(); + } @Override public Iterator> iterator() { diff --git a/src/projectzombie/util/math/map/Map2DElement.java b/src/projectzombie/util/math/map/Map2DElement.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/util/math/random/OpenSimplexNoise.java b/src/projectzombie/util/math/random/OpenSimplexNoise.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/util/math/random/RandomHelpers.java b/src/projectzombie/util/math/random/RandomHelpers.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/util/math/range/Range2i.java b/src/projectzombie/util/math/range/Range2i.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/util/math/range/Range3i.java b/src/projectzombie/util/math/range/Range3i.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/util/math/range/Range4i.java b/src/projectzombie/util/math/range/Range4i.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/util/math/vec/Vec2d.java b/src/projectzombie/util/math/vec/Vec2d.java old mode 100644 new mode 100755 index bebdbcb..e068d9a --- a/src/projectzombie/util/math/vec/Vec2d.java +++ b/src/projectzombie/util/math/vec/Vec2d.java @@ -1,8 +1,10 @@ package projectzombie.util.math.vec; +import bdf.classes.IBdfClassManager; +import bdf.types.BdfObject; import projectzombie.util.math.MathHelpers; -public class Vec2d +public class Vec2d implements IBdfClassManager { public double x; public double y; @@ -41,6 +43,22 @@ public class Vec2d return new Vec2d(this.x / other.x, this.y / other.y); } + public Vec2d add(double v) { + return new Vec2d(this.x + v, this.y + v); + } + + public Vec2d subtract(double v) { + return new Vec2d(this.x - v, this.y - v); + } + + public Vec2d multiply(double v) { + return new Vec2d(this.x * v, this.y * v); + } + + public Vec2d divide(double v) { + return new Vec2d(this.x / v, this.y / v); + } + public Vec2d copy() { return new Vec2d(x, y); } @@ -51,4 +69,26 @@ public class Vec2d double dy = MathHelpers.positive(other.y - y); return MathHelpers.biggest(dx, dy); } + + public Vec2i toInt() { + return new Vec2i(MathHelpers.floor(x), MathHelpers.floor(y)); + } + + @Override + public void BdfClassLoad(BdfObject bdf) { + double array[] = bdf.getDoubleArray(); + if(array.length < 2) return; + x = array[0]; + y = array[1]; + } + + @Override + public void BdfClassSave(BdfObject bdf) { + double array[] = {x, y}; + bdf.setDoubleArray(array); + } + + public Vec2d(BdfObject bdf) { + this.BdfClassLoad(bdf); + } } diff --git a/src/projectzombie/util/math/vec/Vec2i.java b/src/projectzombie/util/math/vec/Vec2i.java old mode 100644 new mode 100755 index 62e3ab9..995dd31 --- a/src/projectzombie/util/math/vec/Vec2i.java +++ b/src/projectzombie/util/math/vec/Vec2i.java @@ -1,9 +1,11 @@ package projectzombie.util.math.vec; +import bdf.classes.IBdfClassManager; +import bdf.types.BdfObject; import projectzombie.util.math.MathHelpers; import projectzombie.util.math.range.Range2i; -public class Vec2i +public class Vec2i implements IBdfClassManager { public int x; public int y; @@ -67,6 +69,22 @@ public class Vec2i return new Vec2i(this.x / other.x, this.y / other.y); } + public Vec2i add(int v) { + return new Vec2i(this.x + v, this.y + v); + } + + public Vec2i subtract(int v) { + return new Vec2i(this.x - v, this.y - v); + } + + public Vec2i multiply(int v) { + return new Vec2i(this.x * v, this.y * v); + } + + public Vec2i divide(int v) { + return new Vec2i(this.x / v, this.y / v); + } + public Vec2i copy() { return new Vec2i(x, y); } @@ -77,4 +95,26 @@ public class Vec2i int dy = MathHelpers.positive(other.y - y); return MathHelpers.biggest(dx, dy); } + + public Vec2d toDouble() { + return new Vec2d(x, y); + } + + @Override + public void BdfClassLoad(BdfObject bdf) { + int array[] = bdf.getIntegerArray(); + if(array.length < 2) return; + x = array[0]; + y = array[1]; + } + + @Override + public void BdfClassSave(BdfObject bdf) { + int array[] = {x, y}; + bdf.setIntegerArray(array); + } + + public Vec2i(BdfObject bdf) { + this.BdfClassLoad(bdf); + } } diff --git a/src/projectzombie/util/math/vec/Vec3d.java b/src/projectzombie/util/math/vec/Vec3d.java old mode 100644 new mode 100755 index c2dd58e..e6d3bdd --- a/src/projectzombie/util/math/vec/Vec3d.java +++ b/src/projectzombie/util/math/vec/Vec3d.java @@ -1,8 +1,10 @@ package projectzombie.util.math.vec; +import bdf.classes.IBdfClassManager; +import bdf.types.BdfObject; import projectzombie.util.math.MathHelpers; -public class Vec3d +public class Vec3d implements IBdfClassManager { public double x; public double y; @@ -43,6 +45,22 @@ public class Vec3d return new Vec3d(this.x / other.x, this.y / other.y, this.z / other.z); } + public Vec3d add(double v) { + return new Vec3d(this.x + v, this.y + v, this.z + v); + } + + public Vec3d subtract(double v) { + return new Vec3d(this.x - v, this.y - v, this.z - v); + } + + public Vec3d multiply(double v) { + return new Vec3d(this.x * v, this.y * v, this.z * v); + } + + public Vec3d divide(double v) { + return new Vec3d(this.x / v, this.y / v, this.z / v); + } + public Vec3d copy() { return new Vec3d(x, y, z); } @@ -57,4 +75,27 @@ public class Vec3d if(dy > dz) return dy; else return dz; } + + public Vec3i toInt() { + return new Vec3i(MathHelpers.floor(x), MathHelpers.floor(y), MathHelpers.floor(z)); + } + + @Override + public void BdfClassLoad(BdfObject bdf) { + double array[] = bdf.getDoubleArray(); + if(array.length < 3) return; + x = array[0]; + y = array[1]; + z = array[2]; + } + + @Override + public void BdfClassSave(BdfObject bdf) { + double array[] = {x, y, z}; + bdf.setDoubleArray(array); + } + + public Vec3d(BdfObject bdf) { + this.BdfClassLoad(bdf); + } } diff --git a/src/projectzombie/util/math/vec/Vec3i.java b/src/projectzombie/util/math/vec/Vec3i.java old mode 100644 new mode 100755 index b1eca5c..646a459 --- a/src/projectzombie/util/math/vec/Vec3i.java +++ b/src/projectzombie/util/math/vec/Vec3i.java @@ -1,9 +1,11 @@ package projectzombie.util.math.vec; +import bdf.classes.IBdfClassManager; +import bdf.types.BdfObject; import projectzombie.util.math.MathHelpers; import projectzombie.util.math.range.Range3i; -public class Vec3i +public class Vec3i implements IBdfClassManager { public int x; public int y; @@ -75,6 +77,22 @@ public class Vec3i return new Vec3i(this.x / other.x, this.y / other.y, this.z / other.z); } + public Vec3i add(int v) { + return new Vec3i(this.x + v, this.y + v, this.z + v); + } + + public Vec3i subtract(int v) { + return new Vec3i(this.x - v, this.y - v, this.z - v); + } + + public Vec3i multiply(int v) { + return new Vec3i(this.x * v, this.y * v, this.z * v); + } + + public Vec3i divide(int v) { + return new Vec3i(this.x / v, this.y / v, this.z / v); + } + public Vec3i copy() { return new Vec3i(x, y, z); } @@ -89,4 +107,27 @@ public class Vec3i if(dy > dz) return dy; else return dz; } + + public Vec3d toDouble() { + return new Vec3d(x, y, z); + } + + @Override + public void BdfClassLoad(BdfObject bdf) { + int array[] = bdf.getIntegerArray(); + if(array.length < 3) return; + x = array[0]; + y = array[1]; + z = array[2]; + } + + @Override + public void BdfClassSave(BdfObject bdf) { + int array[] = {x, y, z}; + bdf.setIntegerArray(array); + } + + public Vec3i(BdfObject bdf) { + this.BdfClassLoad(bdf); + } } diff --git a/src/projectzombie/util/math/vec/Vec4d.java b/src/projectzombie/util/math/vec/Vec4d.java old mode 100644 new mode 100755 index 028fb79..09f4038 --- a/src/projectzombie/util/math/vec/Vec4d.java +++ b/src/projectzombie/util/math/vec/Vec4d.java @@ -1,8 +1,10 @@ package projectzombie.util.math.vec; +import bdf.classes.IBdfClassManager; +import bdf.types.BdfObject; import projectzombie.util.math.MathHelpers; -public class Vec4d +public class Vec4d implements IBdfClassManager { public double x; public double y; @@ -49,6 +51,22 @@ public class Vec4d return new Vec4d(this.x / other.x, this.y / other.y, this.z / other.z, this.m / other.m); } + public Vec4d add(double v) { + return new Vec4d(this.x + v, this.y + v, this.z + v, this.m + v); + } + + public Vec4d subtract(double v) { + return new Vec4d(this.x - v, this.y - v, this.z - v, this.m - v); + } + + public Vec4d multiply(double v) { + return new Vec4d(this.x * v, this.y * v, this.z * v, this.m * v); + } + + public Vec4d divide(double v) { + return new Vec4d(this.x / v, this.y / v, this.z / v, this.m / v); + } + public Vec4d copy() { return new Vec4d(x, y, z, m); } @@ -65,4 +83,28 @@ public class Vec4d if(dz > dm) return dz; else return dm; } + + public Vec4i toInt() { + return new Vec4i(MathHelpers.floor(x), MathHelpers.floor(y), MathHelpers.floor(z), MathHelpers.floor(m)); + } + + @Override + public void BdfClassLoad(BdfObject bdf) { + double array[] = bdf.getDoubleArray(); + if(array.length < 4) return; + x = array[0]; + y = array[1]; + z = array[2]; + m = array[3]; + } + + @Override + public void BdfClassSave(BdfObject bdf) { + double array[] = {x, y, z, m}; + bdf.setDoubleArray(array); + } + + public Vec4d(BdfObject bdf) { + this.BdfClassLoad(bdf); + } } diff --git a/src/projectzombie/util/math/vec/Vec4i.java b/src/projectzombie/util/math/vec/Vec4i.java old mode 100644 new mode 100755 index 0ac8125..d44a3fc --- a/src/projectzombie/util/math/vec/Vec4i.java +++ b/src/projectzombie/util/math/vec/Vec4i.java @@ -1,9 +1,11 @@ package projectzombie.util.math.vec; +import bdf.classes.IBdfClassManager; +import bdf.types.BdfObject; import projectzombie.util.math.MathHelpers; import projectzombie.util.math.range.Range4i; -public class Vec4i { +public class Vec4i implements IBdfClassManager { public int x; public int y; public int z; @@ -86,6 +88,22 @@ public class Vec4i { return new Vec4i(this.x / other.x, this.y / other.y, this.z / other.z, this.m / other.m); } + public Vec4i add(int v) { + return new Vec4i(this.x + v, this.y + v, this.z + v, this.m + v); + } + + public Vec4i subtract(int v) { + return new Vec4i(this.x - v, this.y - v, this.z - v, this.m - v); + } + + public Vec4i multiply(int v) { + return new Vec4i(this.x * v, this.y * v, this.z * v, this.m * v); + } + + public Vec4i divide(int v) { + return new Vec4i(this.x / v, this.y / v, this.z / v, this.m / v); + } + public Vec4i copy() { return new Vec4i(x, y, z, m); } @@ -102,4 +120,28 @@ public class Vec4i { if(dz > dm) return dz; else return dm; } + + public Vec4d toDouble() { + return new Vec4d(x, y, z, m); + } + + @Override + public void BdfClassLoad(BdfObject bdf) { + int array[] = bdf.getIntegerArray(); + if(array.length < 4) return; + x = array[0]; + y = array[1]; + z = array[2]; + m = array[3]; + } + + @Override + public void BdfClassSave(BdfObject bdf) { + int array[] = {x, y, z, m}; + bdf.setIntegerArray(array); + } + + public Vec4i(BdfObject bdf) { + this.BdfClassLoad(bdf); + } } diff --git a/src/projectzombie/world/World.java b/src/projectzombie/world/World.java old mode 100644 new mode 100755 index 099a0f7..956fd80 --- a/src/projectzombie/world/World.java +++ b/src/projectzombie/world/World.java @@ -1,31 +1,111 @@ package projectzombie.world; +import java.util.ArrayList; + +import bdf.classes.IBdfClassManager; +import bdf.types.BdfArray; +import bdf.types.BdfNamedList; +import bdf.types.BdfObject; +import projectzombie.Main; import projectzombie.display.Camera; +import projectzombie.entity.player.EntityPlayer; +import projectzombie.time.GameTimer; import projectzombie.world.chunk.ChunkEventHandler; import projectzombie.world.layer.Layer; -public class World +public class World implements IBdfClassManager { - private Layer layer; + private Layer loaded; + private ArrayList layers = new ArrayList(); public void render(Camera camera) { - layer.render(camera); + loaded.render(camera); } public void tickEntities() { - layer.tickEntities(); + loaded.tickEntities(); } public void spawnRandomEntities() { - layer.spawnRandomEntities(); + loaded.spawnRandomEntities(); } - public void setLayer(Layer layer) { + public void setLayer(int id) { ChunkEventHandler.loaded = false; - this.layer = layer; + this.loaded = layers.get(id); + } + + public void removeLayer(int id) { + layers.remove(id); + } + + public int addLayer(Layer layer) { + int id = layers.size(); + layers.add(layer); + layer.id = id; + return id; } public Layer getLayer() { - return layer; + return loaded; + } + + @Override + public void BdfClassLoad(BdfObject bdf) + { + BdfNamedList nl = bdf.getNamedList(); + + // Get the layers and the loaded layer + BdfArray layers_bdf = nl.get("layers").getArray(); + + for(BdfObject o : layers_bdf) { + layers.add(new Layer(o)); + } + + int loaded_id = nl.get("loaded").getInteger(); + setLayer(loaded_id); + + // Load the player data + BdfArray players = nl.get("players").getArray(); + Main.player = new EntityPlayer(players.get(0)); + + // Set the games time + GameTimer.setTime(nl.get("time").getLong()); + } + + @Override + public void BdfClassSave(BdfObject bdf) + { + BdfNamedList nl = bdf.getNamedList(); + + // Get the current loaded layer + int loaded_id = -1; + for(int i=0;i getNearbyEntities(Vec2d pos, double distance) @@ -399,7 +523,11 @@ public class Chunk } // Tick the tile - ts.tile.tickRandomly(layer, this, ts, pos); + ts.tile.tickRandomly( + layer, + this, + ts, + pos); } } diff --git a/src/projectzombie/world/chunk/ChunkEmpty.java b/src/projectzombie/world/chunk/ChunkEmpty.java old mode 100644 new mode 100755 index 1a759e5..9de7a54 --- a/src/projectzombie/world/chunk/ChunkEmpty.java +++ b/src/projectzombie/world/chunk/ChunkEmpty.java @@ -1,19 +1,40 @@ package projectzombie.world.chunk; import java.util.ArrayList; +import java.util.Random; +import bdf.types.BdfObject; import projectzombie.display.Camera; import projectzombie.entity.Entity; import projectzombie.util.math.TileState; import projectzombie.util.math.vec.Vec2d; import projectzombie.util.math.vec.Vec2i; +import projectzombie.util.math.vec.Vec3d; public class ChunkEmpty extends Chunk { public ChunkEmpty() { - super(null, null, null); + super(null, null, (Random)null); + } + + @Override + public void BdfClassLoad(BdfObject bdf) { + } + + @Override + public void BdfClassSave(BdfObject bdf) { + } + + @Override + public Vec3d getRGBLightLevel(int id) { + return new Vec3d(0, 0, 0); } + @Override + public Vec3d getRGBLightLevel(Vec2i tpos) { + return new Vec3d(0, 0, 0); + } + @Override public void render(Camera camera) {} diff --git a/src/projectzombie/world/chunk/ChunkEventHandler.java b/src/projectzombie/world/chunk/ChunkEventHandler.java old mode 100644 new mode 100755 diff --git a/src/projectzombie/world/layer/Layer.java b/src/projectzombie/world/layer/Layer.java old mode 100644 new mode 100755 index cc42864..963c78b --- a/src/projectzombie/world/layer/Layer.java +++ b/src/projectzombie/world/layer/Layer.java @@ -3,9 +3,14 @@ package projectzombie.world.layer; import java.util.ArrayList; import java.util.Random; +import bdf.classes.IBdfClassManager; +import bdf.types.BdfArray; +import bdf.types.BdfNamedList; +import bdf.types.BdfObject; import projectzombie.Main; import projectzombie.display.Camera; import projectzombie.entity.Entity; +import projectzombie.init.LayerGenerators; import projectzombie.util.math.MathHelpers; import projectzombie.util.math.TileState; import projectzombie.util.math.map.Map2D; @@ -15,24 +20,29 @@ import projectzombie.util.math.vec.Vec2i; import projectzombie.world.chunk.Chunk; import projectzombie.world.layer.layergen.LayerGen; -public class Layer +public class Layer implements IBdfClassManager { public Map2D chunks; private Map2D dirty_chunks; public LayerGen layergen; private Random rand; - private long seed; + public long lseed; + public long seed; public int id; - public Layer(Random rand, LayerGen layergen, int id) + public Layer(Random rand, LayerGen layergen) { // Create the array of tiles this.layergen = layergen; - this.seed = rand.nextLong(); this.rand = new Random(); + this.seed = rand.nextLong(); + this.lseed = this.rand.nextLong(); this.chunks = new Map2D(layergen); this.dirty_chunks = new Map2D(layergen); - this.id = id; + } + + public Layer(BdfObject bdf) { + BdfClassLoad(bdf); } public void render(Camera camera) @@ -106,6 +116,15 @@ public class Layer return chunks.get(c_pos).getBackTile(pos); } + public TileState getFrontTile(Vec2i pos) + { + // Get the chunk pos + Vec2i c_pos = getChunkPosFromPos(pos); + + // Get the chunks front tile + return chunks.get(c_pos).getFrontTile(pos); + } + public void breakBackTile(Vec2i pos) { getChunk(pos).breakBackTile(pos); } @@ -178,15 +197,6 @@ public class Layer chunks.get(c_pos).setDaylightLevel(light, pos); } - public TileState getFrontTile(Vec2i pos) - { - // Get the chunk pos - Vec2i c_pos = getChunkPosFromPos(pos); - - // Get the chunks front tile - return chunks.get(c_pos).getFrontTile(pos); - } - public void spawnEntity(Entity entity) { // Get the chunk pos @@ -211,7 +221,7 @@ public class Layer // Create and generate the chunk Chunk chunk = new Chunk(this, pos, rand); chunks.set(pos, chunk); - layergen.generateChunk(chunk, this, seed, new Random(cseed), pos); + layergen.generateChunk(chunk, this, new Random(cseed), pos); chunk.dirty = false; } } @@ -265,4 +275,59 @@ public class Layer // Send back the list of nearby entities return entities; } + + @Override + public void BdfClassLoad(BdfObject bdf) + { + BdfNamedList nl = bdf.getNamedList(); + + this.layergen = LayerGenerators.loadFromID(nl.get("lgen").getInteger()); + this.dirty_chunks = new Map2D(layergen); + this.chunks = new Map2D(layergen); + this.seed = nl.get("seed").getLong(); + this.lseed = nl.get("lseed").getLong(); + this.id = nl.get("id").getInteger(); + this.rand = new Random(); + + BdfArray bdf_chunks = nl.get("chunks").getArray(); + + for(BdfObject bdf_chunk : bdf_chunks) { + BdfNamedList chunk_nl = bdf_chunk.getNamedList(); + Vec2i cpos = new Vec2i(chunk_nl.get("pos")); + Chunk chunk = new Chunk(this, cpos, chunk_nl.get("chunk")); + dirty_chunks.set(cpos, chunk); + } + } + + @Override + public void BdfClassSave(BdfObject bdf) + { + BdfNamedList nl = bdf.getNamedList(); + + nl.set("lseed", BdfObject.withLong(lseed)); + nl.set("seed", BdfObject.withLong(seed)); + nl.set("id", BdfObject.withInteger(id)); + nl.set("lgen", BdfObject.withInteger(LayerGenerators.getLGID(this.layergen))); + + BdfArray bdf_chunks = nl.get("chunks").getArray(); + + for(Map2DElement chunk : dirty_chunks) { + BdfNamedList chunk_nl = new BdfNamedList(); + chunk.pos.BdfClassSave(chunk_nl.get("pos")); + chunk.o.BdfClassSave(chunk_nl.get("chunk")); + bdf_chunks.add(BdfObject.withNamedList(chunk_nl)); + } + + for(Map2DElement chunk : chunks) { + if(dirty_chunks.contains(chunk.pos)) + continue; + if(!chunk.o.dirty) + continue; + + BdfNamedList chunk_nl = new BdfNamedList(); + chunk.pos.BdfClassSave(chunk_nl.get("pos")); + chunk.o.BdfClassSave(chunk_nl.get("chunk")); + bdf_chunks.add(BdfObject.withNamedList(chunk_nl)); + } + } } diff --git a/src/projectzombie/world/layer/layergen/LayerGen.java b/src/projectzombie/world/layer/layergen/LayerGen.java old mode 100644 new mode 100755 index 12a9313..9905c2d --- a/src/projectzombie/world/layer/layergen/LayerGen.java +++ b/src/projectzombie/world/layer/layergen/LayerGen.java @@ -11,7 +11,10 @@ import projectzombie.world.layer.Layer; public abstract class LayerGen implements IMap2D { - public abstract void generateChunk(Chunk chunk, Layer layer, long seed, Random rand, Vec2i pos); + public int id; + public boolean destroyOnLeave = false; + + public abstract void generateChunk(Chunk chunk, Layer layer, Random rand, Vec2i pos); public abstract void spawnEntities(Layer layer, Random rand); public abstract TileState getTileDestroyed(); public abstract ColorRange getLightLevel(); diff --git a/src/projectzombie/world/layer/layergen/LayerGenBossArena.java b/src/projectzombie/world/layer/layergen/LayerGenBossArena.java old mode 100644 new mode 100755 index 85a1b29..e770f81 --- a/src/projectzombie/world/layer/layergen/LayerGenBossArena.java +++ b/src/projectzombie/world/layer/layergen/LayerGenBossArena.java @@ -21,9 +21,13 @@ public class LayerGenBossArena extends LayerGen implements LayerGenRememberPlaye private final int size = 10; private Vec2d player_pos = new Vec2d(0, 0); private Random rand = new Random(); + + public LayerGenBossArena() { + this.destroyOnLeave = true; + } @Override - public void generateChunk(Chunk chunk, Layer layer, long seed, Random rand, Vec2i pos) + public void generateChunk(Chunk chunk, Layer layer, Random rand, Vec2i pos) { // Fill with stone for(int i=0;i= 40) { 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, @@ -81,7 +77,7 @@ public class LayerGenEarth extends LayerGen @Override public void spawnEntities(Layer layer, Random rand) { - if(rand.nextDouble() > 0.98) + if(rand.nextDouble() > 0.98 && getEarthLight() < -0.3) { Entity zombie = new EntityZombie(new Vec2d( RandomHelpers.randrange(rand, (int)Main.player.pos.x - 128, (int)Main.player.pos.x + 128), @@ -97,10 +93,14 @@ public class LayerGenEarth extends LayerGen return Tiles.DIRT.getDefaultState(); } + private double getEarthLight() { + return Math.sin(GameTimer.getTime() / 7200.0); + } + @Override public ColorRange getLightLevel() { - double light = Math.sin(GameTimer.getTime() / 7200.0); + double light = getEarthLight(); ColorRange daylightRange = new ColorRange( new Vec3d(60/255.0, 74/255.0, 68/255.0), diff --git a/src/projectzombie/world/layer/layergen/LayerGenLavaCaves.java b/src/projectzombie/world/layer/layergen/LayerGenLavaCaves.java old mode 100644 new mode 100755 index 8615619..ec5a918 --- a/src/projectzombie/world/layer/layergen/LayerGenLavaCaves.java +++ b/src/projectzombie/world/layer/layergen/LayerGenLavaCaves.java @@ -20,7 +20,7 @@ public class LayerGenLavaCaves extends LayerGen { @Override - public void generateChunk(Chunk chunk, Layer layer, long seed, Random rand, Vec2i pos) + public void generateChunk(Chunk chunk, Layer layer, Random rand, Vec2i pos) { // Make sure the random generated is the same if(PortalSpawnrates.WorldCavePortal(rand)) { @@ -45,7 +45,7 @@ public class LayerGenLavaCaves extends LayerGen } // Get some noise generators - OpenSimplexNoise noisegen_n = new OpenSimplexNoise(new Random(seed + layer.id).nextLong()); + OpenSimplexNoise noisegen_n = new OpenSimplexNoise(new Random(layer.lseed).nextLong()); // Loop over the chunk for(int x=0;x