From fe1f97f248aea745233fd8bfb3c2c82eb0cc5400 Mon Sep 17 00:00:00 2001 From: josua Date: Wed, 1 Jul 2020 12:37:04 +1000 Subject: [PATCH] Removed lots of unused code --- .../display/DisplayLighting.java | 4 - src/projectzombie/display/DisplayRender.java | 3 +- .../display/DisplayRenderUI.java | 10 ++- src/projectzombie/entity/Entity.java | 79 ++++++------------- src/projectzombie/entity/EntityBoss.java | 4 - src/projectzombie/entity/EntityBullet.java | 2 +- src/projectzombie/entity/EntityTnt.java | 2 - src/projectzombie/entity/EntityZombie.java | 7 +- .../entity/EntityZombieArmored.java | 2 +- .../entity/particle/ParticleBreak.java | 2 +- .../entity/player/EntityPlayer.java | 6 +- 11 files changed, 39 insertions(+), 82 deletions(-) diff --git a/src/projectzombie/display/DisplayLighting.java b/src/projectzombie/display/DisplayLighting.java index 2103ccb..e2234fd 100755 --- a/src/projectzombie/display/DisplayLighting.java +++ b/src/projectzombie/display/DisplayLighting.java @@ -308,10 +308,6 @@ public class DisplayLighting (float)(lighting.y * 16 - Camera.camera.y - 0.5)); } - else { - System.out.println("CAMERA IS NULL"); - } - } public static void clearLighting() diff --git a/src/projectzombie/display/DisplayRender.java b/src/projectzombie/display/DisplayRender.java index 3180093..a4d309c 100755 --- a/src/projectzombie/display/DisplayRender.java +++ b/src/projectzombie/display/DisplayRender.java @@ -14,6 +14,7 @@ import projectzombie.Main; import projectzombie.entity.player.EntityPlayer; import projectzombie.model.Model; import projectzombie.util.math.ColorRange; +import projectzombie.world.chunk.Chunk; import projectzombie.world.chunk.ChunkEventHandler; public class DisplayRender @@ -42,7 +43,7 @@ public class DisplayRender Camera.camera = camera; // Create the projection matrix - Matrix4 projection = Matrix4.projection((double)w / (double)h, 45, 0.1, 1000); + Matrix4 projection = Matrix4.projection((double)w / (double)h, 45, 0.1, Chunk.RENDER_DISTANCE*16+32); projection = Matrix4.multiply(camera.getMatrix(), projection); Matrix4 rotated = Matrix4.rotate(-camera.angle, 0, 1, 0); diff --git a/src/projectzombie/display/DisplayRenderUI.java b/src/projectzombie/display/DisplayRenderUI.java index 40f3e5d..547b5a1 100755 --- a/src/projectzombie/display/DisplayRenderUI.java +++ b/src/projectzombie/display/DisplayRenderUI.java @@ -23,6 +23,10 @@ public class DisplayRenderUI public static Matrix4 camera, projection; + private static float calculateGreen(double a) { + return (float)(-2 * a * (a - 1) + 0.25 * a * a); + } + public static void renderGameGui() { { @@ -85,12 +89,12 @@ public class DisplayRenderUI model_health_f.render(); double temperature = MathHelpers.smoothStep(Main.player.getTemperature()); - double hydration = MathHelpers.squared(1 - Main.player.getHydration()); + double hydration = MathHelpers.smoothStep(1 - Main.player.getHydration()); GL33.glUniform2f(Main.window.glsl_tex_cut, 0, 0); GL33.glUniform4f(Main.window.glsl_color, - (float)temperature, (float)temperature * 0.25f, 1 - (float)temperature, 1); + (float)temperature, calculateGreen(temperature), 1 - (float)temperature, 1); matrix = Matrix4.translate(-(9 * 0.75) / 8, -9.5 + (1.5 * 17) / 16, 0); @@ -98,7 +102,7 @@ public class DisplayRenderUI model_temperature.render(); GL33.glUniform4f(Main.window.glsl_color, - (float)hydration, (float)hydration * 0.25f, 1 - (float)hydration, 1); + (float)hydration * 0.75f, calculateGreen(hydration), 1 - (float)hydration, 1); matrix = Matrix4.translate((1 * 0.75) / 8, -9.5 + (1.5 * 17) / 16, 0); diff --git a/src/projectzombie/entity/Entity.java b/src/projectzombie/entity/Entity.java index 1c2138f..162754a 100755 --- a/src/projectzombie/entity/Entity.java +++ b/src/projectzombie/entity/Entity.java @@ -29,13 +29,10 @@ public abstract class Entity implements IBdfClassManager public Chunk chunk; private TileState tile_front; private TileState tile_back; - public boolean crossUnWalkable = true; - public boolean goThroughSolid = true; protected static final Random rand = new Random(); public boolean emitsLight = false; - public int stepOnTileCooldown = 0; - private boolean dead = false; - protected boolean gravity = true; + private boolean isDead = false; + protected boolean hasGravity = true; private Vec3d pos; private Vec3d velocity; @@ -43,7 +40,7 @@ public abstract class Entity implements IBdfClassManager public abstract IModel getModel(); public boolean isDead() { - return dead; + return isDead; } public Vec3d getPos() { @@ -142,11 +139,8 @@ public abstract class Entity implements IBdfClassManager velocity = new Vec3d(e.get(1)); 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(); - gravity = e.get(8).getBoolean(); + hasGravity = e.get(8).getBoolean(); } @Override @@ -165,18 +159,12 @@ public abstract class Entity implements IBdfClassManager BdfObject velocity_bdf = new BdfObject(); velocity.BdfClassSave(velocity_bdf); - BdfArray e = new BdfArray(); - nl.set("e", BdfObject.withArray(e)); - - e.add(pos_bdf); - e.add(velocity_bdf); - 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)); - e.add(BdfObject.withBoolean(gravity)); + nl.set("pos", pos_bdf); + nl.set("velocity", velocity_bdf); + nl.set("hitbox", BdfObject.withDouble(hitbox)); + nl.set("isSolid", BdfObject.withBoolean(isSolid)); + nl.set("emitsLight", BdfObject.withBoolean(emitsLight)); + nl.set("hasGravity", BdfObject.withBoolean(hasGravity)); } public void tick(Chunk chunk, Layer layer) @@ -189,10 +177,6 @@ public abstract class Entity implements IBdfClassManager tile_back = chunk.getBackTile(tpos); tile_front = chunk.getFrontTile(tpos); - if(stepOnTileCooldown > 0) { - stepOnTileCooldown -= 1; - } - Vec3d new_pos = pos.add(velocity); if(isSolid) { @@ -221,7 +205,7 @@ public abstract class Entity implements IBdfClassManager pos.y = 0; } - if(gravity) { + if(hasGravity) { velocity.y -= MathHelpers.FallSpeed; } @@ -232,11 +216,11 @@ public abstract class Entity implements IBdfClassManager protected void moveAwayFromSolidEntities(Layer layer) { - if(!goThroughSolid) + if(isSolid) { for(Entity e : layer.getNearbyEntities(pos.xz(), hitbox)) { - if(e.isSolid && !e.goThroughSolid && e != this) + if(e.isSolid && e != this) { double distance = pos.distance(e.pos); double angle = MathHelpers.atan2(e.pos.z - pos.z, e.pos.x - pos.x); @@ -255,7 +239,7 @@ public abstract class Entity implements IBdfClassManager public void kill() { chunk.killEntity(this); - dead = true; + isDead = true; } public void activateTile() @@ -271,20 +255,13 @@ public abstract class Entity implements IBdfClassManager public void activateSteppedOnTile() { - // Has the cooldown expired - if(stepOnTileCooldown == 0) - { - // Get the tile position and the layer - Layer layer = Main.world.getLayer(); - Vec2i tpos = new Vec2i(MathHelpers.floor(pos.x)+0, MathHelpers.floor(pos.z)+0); - - // Activate both tiles - tile_front.tile.onWalkedOn(chunk, layer, tpos, this, tile_front); - tile_back.tile.onWalkedOn(chunk, layer, tpos, this, tile_back); + // Get the tile position and the layer + Layer layer = Main.world.getLayer(); + Vec2i tpos = new Vec2i(MathHelpers.floor(pos.x)+0, MathHelpers.floor(pos.z)+0); - // Reset the cooldown - stepOnTileCooldown = 1; - } + // Activate both tiles + tile_front.tile.onWalkedOn(chunk, layer, tpos, this, tile_front); + tile_back.tile.onWalkedOn(chunk, layer, tpos, this, tile_back); } private boolean moveIsLegal(Vec2d pos) @@ -295,7 +272,7 @@ public abstract class Entity implements IBdfClassManager tile_front = chunk.getFrontTile(t_pos); // Is this entity solid - if(!goThroughSolid || !crossUnWalkable) + if(isSolid) { // Check the tile the player is standing on Vec2i tpos = new Vec2i(MathHelpers.floor(pos.x)+0, MathHelpers.floor(pos.y)+0); @@ -304,13 +281,8 @@ public abstract class Entity implements IBdfClassManager // Get the tile Tile t = tile_back.tile; - // Send false if the tile isn't walkable - if((!t.tileWalkable) && (!crossUnWalkable)) { - return false; - } - // Check the tiles hitbox if the tile is solid - if((t.tileSolid) && (!goThroughSolid)) + if(t.tileSolid) { // Is the entity in the tiles hitbox if(pos.squareDistance(new Vec2d(tpos.x + 0.5, tpos.y + 0.5)) < t.tileHitbox) @@ -325,13 +297,8 @@ public abstract class Entity implements IBdfClassManager // Get the front tile Tile t = tile_front.tile; - // Send false if the tile isn't walkable - if((!t.tileWalkable) && (!crossUnWalkable)) { - return false; - } - // Check the tiles hitbox if the tile is solid - if((t.tileSolid) && (!goThroughSolid)) + if(t.tileSolid) { // Is the entity in the tiles hitbox if(pos.squareDistance(new Vec2d(tpos.x + 0.5, tpos.y + 0.5)) < t.tileHitbox) diff --git a/src/projectzombie/entity/EntityBoss.java b/src/projectzombie/entity/EntityBoss.java index ce86c6e..b032138 100755 --- a/src/projectzombie/entity/EntityBoss.java +++ b/src/projectzombie/entity/EntityBoss.java @@ -54,8 +54,6 @@ public class EntityBoss extends Entity implements IBossBar, EntityKillWithPartic 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(); @@ -84,8 +82,6 @@ public class EntityBoss extends Entity implements IBossBar, EntityKillWithPartic super(pos, velocity); this.isSolid = true; - this.goThroughSolid = false; - this.crossUnWalkable = false; this.hitbox = 2; long seed = rand.nextLong(); diff --git a/src/projectzombie/entity/EntityBullet.java b/src/projectzombie/entity/EntityBullet.java index 0fc5b97..e325500 100755 --- a/src/projectzombie/entity/EntityBullet.java +++ b/src/projectzombie/entity/EntityBullet.java @@ -52,7 +52,7 @@ public class EntityBullet extends EntityParticle this.parent = parent; this.damage = damage; this.time = despawn_time; - this.gravity = false; + this.hasGravity = false; // Play the gun sound Sounds.GUN.play(pos, 2); diff --git a/src/projectzombie/entity/EntityTnt.java b/src/projectzombie/entity/EntityTnt.java index 8cb2745..f7f31d9 100755 --- a/src/projectzombie/entity/EntityTnt.java +++ b/src/projectzombie/entity/EntityTnt.java @@ -58,8 +58,6 @@ public class EntityTnt extends Entity implements EntityHoldsEntities Vec2d v = MathHelpers.moveTowards2(0.05, Math.toRadians(angle)); velocity = velocity.add(new Vec3d(v.x, v.y, 0.01)); this.explode_radius = explode_radius; - this.crossUnWalkable = true; - this.goThroughSolid = false; this.explode_damage = explode_damage; this.smoke_particles = new ParticleSpark[100]; diff --git a/src/projectzombie/entity/EntityZombie.java b/src/projectzombie/entity/EntityZombie.java index aca4fd6..84574fb 100755 --- a/src/projectzombie/entity/EntityZombie.java +++ b/src/projectzombie/entity/EntityZombie.java @@ -36,6 +36,7 @@ public class EntityZombie extends Entity implements EntityAlive, EntityKillWithP private Vec3d walk_to; private int walk_scan_cooldown = 0; private boolean can_see_player = false; + protected boolean crossUnwalkable = false; private int walking_for = 0; public EntityZombie(BdfObject bdf) { @@ -44,8 +45,6 @@ public class EntityZombie extends Entity implements EntityAlive, EntityKillWithP // Set some settings hitbox = 0.5; isSolid = true; - goThroughSolid = false; - crossUnWalkable = false; } @Override @@ -99,8 +98,6 @@ public class EntityZombie extends Entity implements EntityAlive, EntityKillWithP // Set some settings hitbox = 0.5; isSolid = true; - goThroughSolid = false; - crossUnWalkable = false; } @Override @@ -122,7 +119,7 @@ public class EntityZombie extends Entity implements EntityAlive, EntityKillWithP (walk_to != null && getPos().toInt().equal(walk_to.toInt()) && player_distance > 2) || walk_scan_cooldown < 1 || walking_for > 200) { - AStar astar = new AStar(getPos().xz().toInt(), 16, new AStarSearcher(layer, crossUnWalkable)); + AStar astar = new AStar(getPos().xz().toInt(), 16, new AStarSearcher(layer)); Vec2i path[] = astar.getPath(Main.player.getPos().xz().toInt()); walk_scan_cooldown = 100; diff --git a/src/projectzombie/entity/EntityZombieArmored.java b/src/projectzombie/entity/EntityZombieArmored.java index 6fd90e4..0a61b96 100755 --- a/src/projectzombie/entity/EntityZombieArmored.java +++ b/src/projectzombie/entity/EntityZombieArmored.java @@ -18,7 +18,7 @@ public class EntityZombieArmored extends EntityZombie this.health = this.health_max; this.gun_level = 3; - this.crossUnWalkable = true; + this.crossUnwalkable = true; } @Override diff --git a/src/projectzombie/entity/particle/ParticleBreak.java b/src/projectzombie/entity/particle/ParticleBreak.java index e0f59c4..ccb9b2c 100755 --- a/src/projectzombie/entity/particle/ParticleBreak.java +++ b/src/projectzombie/entity/particle/ParticleBreak.java @@ -54,7 +54,7 @@ public class ParticleBreak extends EntityParticle implements IModel protected ParticleBreak(Vec3d pos, Vec3d velocity, IModel model, int count, double velocity_up_multiplier) { super(pos, new Vec3d(0, 0, 0)); - this.gravity = false; + this.hasGravity = false; double model_height = model.getHeight(); TextureRef3D[] textures = model.getTextures(); diff --git a/src/projectzombie/entity/player/EntityPlayer.java b/src/projectzombie/entity/player/EntityPlayer.java index 00a38c6..d1386f7 100755 --- a/src/projectzombie/entity/player/EntityPlayer.java +++ b/src/projectzombie/entity/player/EntityPlayer.java @@ -94,15 +94,13 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory } public EntityPlayer() { - super(new Vec3d(0, 0, 0), new Vec3d(0, 0, 0)); + super(new Vec3d(Math.pow(2, 30), 0, -Math.pow(2, 30)), new Vec3d(0, 0, 0)); this.angle = 45; // Set some settings hitbox = 0.5; isSolid = true; - goThroughSolid = false; - crossUnWalkable = false; emitsLight = true; // Create the inventory @@ -190,7 +188,7 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory chunk.getLightLevel(getPos().xz().toInt()) * 0.6) - temperature; temperature += temp_diff / 1000; - hydration -= Math.sqrt(Math.abs(temperature - 0.5)) / 5000; + hydration -= MathHelpers.smoothStep(Math.abs(temperature - 0.4) + 0.1) / 1000; if(temperature < 0.3) { health -= 0.3 - temperature;