diff --git a/src/projectzombie/Main.java b/src/projectzombie/Main.java index 369c6e4..c7488d4 100755 --- a/src/projectzombie/Main.java +++ b/src/projectzombie/Main.java @@ -16,8 +16,10 @@ import projectzombie.init.Entities; import projectzombie.init.Items; import projectzombie.init.LayerGenerators; import projectzombie.init.Layers; +import projectzombie.init.Models; import projectzombie.init.Resources; import projectzombie.init.Sounds; +import projectzombie.init.Tasks; import projectzombie.init.Tiles; import projectzombie.input.JoystickCallback; import projectzombie.input.KeyCallback; @@ -73,6 +75,7 @@ public class Main Items.init(); Entities.init(); + Tasks.init(); Tiles.init(); LayerGenerators.init(); diff --git a/src/projectzombie/audio/AudioObject.java b/src/projectzombie/audio/AudioObject.java index 589be10..bc6fa5a 100755 --- a/src/projectzombie/audio/AudioObject.java +++ b/src/projectzombie/audio/AudioObject.java @@ -22,6 +22,7 @@ import org.lwjgl.system.MemoryStack; import gl_engine.matrix.Matrix4; import gl_engine.vec.Vec3d; +import projectzombie.Main; import projectzombie.display.Camera; import projectzombie.resources.Resource; @@ -88,8 +89,8 @@ public class AudioObject } // Calculate the position relative to the player - Matrix4 matrix = Camera.camera.getMatrix(); - Vec3d vec = Matrix4.multiply(matrix, pos.add(new Vec3d(-0.5, 0, -0.5))); + Matrix4 matrix = Camera.camera.matrix; + Vec3d vec = Matrix4.multiply(matrix, pos.subtract(Main.player.getPos())).multiply(0.125); // Play the sound with a new source int source = AudioSources.getSource(); diff --git a/src/projectzombie/display/Camera.java b/src/projectzombie/display/Camera.java index 082466c..dba326d 100755 --- a/src/projectzombie/display/Camera.java +++ b/src/projectzombie/display/Camera.java @@ -1,20 +1,22 @@ package projectzombie.display; -import gl_engine.MathHelpers; import gl_engine.matrix.Matrix4; -import gl_engine.vec.Vec2d; import gl_engine.vec.Vec3d; import projectzombie.Main; +import projectzombie.world.chunk.Chunk; public class Camera { public double x, y; public double angle = 45; - private Matrix4 matrix; + + public Matrix4 matrix; + public Matrix4 projection; + public Matrix4 projection_matrix; public static Camera camera; - public Camera() + public Camera(int w, int h) { Matrix4 identity = Matrix4.identity(); Vec3d pos = Main.player.getPos(); @@ -27,10 +29,9 @@ public class Camera identity = Matrix4.multiply(identity, Matrix4.rotate(-45, 1, 0, 0)); identity = Matrix4.multiply(identity, Matrix4.translate(0, 0, -16)); + projection_matrix = Matrix4.projection((double)w / (double)h, 45, 0.1, Chunk.RENDER_DISTANCE*16+32); + projection = Matrix4.multiply(identity, projection_matrix); + matrix = identity; } - - public Matrix4 getMatrix() { - return matrix; - } } diff --git a/src/projectzombie/display/DisplayRender.java b/src/projectzombie/display/DisplayRender.java index f0ceda6..c21146b 100755 --- a/src/projectzombie/display/DisplayRender.java +++ b/src/projectzombie/display/DisplayRender.java @@ -5,10 +5,11 @@ import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT; import static org.lwjgl.opengl.GL11.glClear; import static org.lwjgl.opengl.GL11.glViewport; +import java.nio.ByteBuffer; + import org.lwjgl.opengl.GL33; import gl_engine.matrix.Matrix4; -import gl_engine.vec.Vec2d; import gl_engine.vec.Vec3d; import projectzombie.Main; import projectzombie.entity.player.EntityPlayer; @@ -19,6 +20,55 @@ import projectzombie.world.chunk.ChunkEventHandler; public class DisplayRender { + private static int shadow_fbo; + private static int shadow_depth; + + private static int generateDepthTexture(int width, int height) + { + int depth = GL33.glGenTextures(); + + GL33.glBindTexture(GL33.GL_TEXTURE_2D, depth); + + GL33.glTexImage2D( + GL33.GL_TEXTURE_2D, 0, GL33.GL_DEPTH_COMPONENT32, width, height, + 0, GL33.GL_DEPTH_COMPONENT, GL33.GL_FLOAT, (ByteBuffer) null); + + GL33.glTexParameteri(GL33.GL_TEXTURE_2D, GL33.GL_TEXTURE_MIN_FILTER, GL33.GL_LINEAR); + GL33.glTexParameteri(GL33.GL_TEXTURE_2D, GL33.GL_TEXTURE_MAG_FILTER, GL33.GL_LINEAR); + GL33.glFramebufferTexture(GL33.GL_FRAMEBUFFER, GL33.GL_DEPTH_ATTACHMENT, depth, 0); + + return depth; + } + + private static int generateColorTexture(int width, int height) + { + int color = GL33.glGenTextures(); + + GL33.glBindTexture(GL33.GL_TEXTURE_2D, color); + + GL33.glTexImage2D( + GL33.GL_TEXTURE_2D, 0, GL33.GL_RGB, width, height, + 0, GL33.GL_RGB, GL33.GL_FLOAT, (ByteBuffer) null); + + GL33.glTexParameteri(GL33.GL_TEXTURE_2D, GL33.GL_TEXTURE_MIN_FILTER, GL33.GL_LINEAR); + GL33.glTexParameteri(GL33.GL_TEXTURE_2D, GL33.GL_TEXTURE_MAG_FILTER, GL33.GL_LINEAR); + GL33.glFramebufferTexture(GL33.GL_FRAMEBUFFER, GL33.GL_COLOR_ATTACHMENT0, color, 0); + + return color; + } + + public static void init() + { + //int size = 1024; + + //shadow_fbo = GL33.glGenFramebuffers(); + //GL33.glBindFramebuffer(GL33.GL_FRAMEBUFFER, shadow_fbo); + //GL33.glDrawBuffer(GL33.GL_DEPTH_ATTACHMENT); + //GL33.glBindFramebuffer(GL33.GL_FRAMEBUFFER, 0); + + //shadow_depth = generateDepthTexture(size, size); + } + public static void render(int w, int h) { // Setup GL and clear the colour @@ -39,35 +89,23 @@ public class DisplayRender if(ChunkEventHandler.loaded) { EntityPlayer player = Main.player; - Camera camera = new Camera(); + Camera camera = new Camera(w, h); Camera.camera = camera; - // Create the projection matrix - 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); Matrix4 billboard = Matrix4.multiply(Matrix4.rotate(-45, 1, 0, 0), rotated); Main.window.environmentRenderer.use(); GL33.glUniformMatrix4fv(Main.window.glsl_billboard, true, billboard.getArray()); - GL33.glUniformMatrix4fv(Main.window.glsl_projection, true, projection.getArray()); + GL33.glUniformMatrix4fv(Main.window.glsl_projection, true, Camera.camera.projection.getArray()); GL33.glUniformMatrix4fv(Main.window.glsl_rotated, true, rotated.getArray()); GL33.glUniform1i(Main.window.glsl_time, (int)((System.currentTimeMillis() / 10) % 1000)); - // Render the world and the player - Vec3d ppos = Main.player.getPos(); - Main.world.render(camera); - player.chunk = Main.world.getLayer().getChunk(player.getPos().xz()); + Main.world.markPoolDirty(); - if(!Main.player.dead) - { - Model model = player.getModel(); - model.setModel(Matrix4.translate( - ppos.x - Camera.camera.x - 0.5, ppos.y, - ppos.z - Camera.camera.y - 0.5)); - model.render(); - } + Main.world.render(camera); + + player.chunk = Main.world.getLayer().getChunk(player.getPos().xz()); } } diff --git a/src/projectzombie/display/DisplayRenderUI.java b/src/projectzombie/display/DisplayRenderUI.java index 21663bb..f2e8efa 100755 --- a/src/projectzombie/display/DisplayRenderUI.java +++ b/src/projectzombie/display/DisplayRenderUI.java @@ -1,5 +1,7 @@ package projectzombie.display; +import java.text.DecimalFormat; + import org.lwjgl.opengl.GL33; import gl_engine.MathHelpers; @@ -14,11 +16,13 @@ import projectzombie.model.ModelGui; import projectzombie.text.Text; import projectzombie.util.gl.GlHelpers; import projectzombie.util.math.ItemStack; +import projectzombie.world.chunk.ChunkEventHandler; +import projectzombie.world.layer.Layer; public class DisplayRenderUI { public static boolean showFPS = false; - public static boolean showPos = false; + public static boolean debug = false; public static int guiScale = 2; public static Matrix4 camera, projection; @@ -43,7 +47,7 @@ public class DisplayRenderUI Models.UI_ACTIVE_SLOT.setModel(matrix_slot); Models.UI_ACTIVE_SLOT.render(); - for(int i = 0; i < inventory.getSlotCount(); i++) + for(int i = 0; i < 10; i++) { ItemStack stack = inventory.getItem(i); @@ -115,6 +119,8 @@ public class DisplayRenderUI public static void render() { + DecimalFormat dec = new DecimalFormat("0.####"); + camera = Matrix4.identity(); projection = Matrix4.scale(new Vec3d(0.1/GlHelpers.getAspectRatio(), 0.1, 1)); @@ -134,16 +140,47 @@ public class DisplayRenderUI matrix = Matrix4.multiply(matrix, Matrix4.translate(-10 * aspect, 9.5, 0)); if(showFPS) { + + float fps = DisplayStatsEventHandler.fps; + + if(fps >= 120) { + GL33.glUniform4f(Main.window.glsl_color, 0, 1, 0, 1); + } else if(fps >= 60) { + GL33.glUniform4f(Main.window.glsl_color, 1, 1, 0, 1); + } else { + GL33.glUniform4f(Main.window.glsl_color, 1, 0, 0, 1); + } + Text.render("Fps: " + DisplayStatsEventHandler.fps, matrix); - matrix = Matrix4.multiply(matrix, Matrix4.translate(0, -0.35, 0)); + matrix = Matrix4.multiply(matrix, Matrix4.translate(0, -0.7, 0)); } - if(showPos) { - Vec3i pos = Main.player.getPos().toInt(); - Text.render("x="+pos.x+", y="+pos.y+", z="+pos.z, matrix); - matrix = Matrix4.multiply(matrix, Matrix4.translate(0, -0.35, 0)); + if(debug) { + Layer layer = Main.world.getLayer(); + Vec3d pos = Main.player.getPos(); + + GL33.glUniform4f(Main.window.glsl_color, 1, 1, 0, 1); + + if(ChunkEventHandler.loaded) + { + Text.render("temperature: " + dec.format( + layer.layergen.getTemperatureStatic(layer, Main.player.getPos().xz())), matrix); + matrix = Matrix4.multiply(matrix, Matrix4.translate(0, -0.35, 0)); + Text.render("humidity: " + dec.format( + layer.layergen.getHumidity(layer, Main.player.getPos().xz())), matrix); + matrix = Matrix4.multiply(matrix, Matrix4.translate(0, -0.7, 0)); + + Text.render("x: "+dec.format(pos.x), matrix); + matrix = Matrix4.multiply(matrix, Matrix4.translate(0, -0.35, 0)); + Text.render("y: "+dec.format(pos.y), matrix); + matrix = Matrix4.multiply(matrix, Matrix4.translate(0, -0.35, 0)); + Text.render("z: "+dec.format(pos.z), matrix); + matrix = Matrix4.multiply(matrix, Matrix4.translate(0, -0.7, 0)); + } } + GL33.glUniform4f(Main.window.glsl_color, 1, 1, 1, 1); + // Render the loaded menu Main.menu.render(); } diff --git a/src/projectzombie/display/DisplayStatsEventHandler.java b/src/projectzombie/display/DisplayStatsEventHandler.java index ec6af02..9992549 100755 --- a/src/projectzombie/display/DisplayStatsEventHandler.java +++ b/src/projectzombie/display/DisplayStatsEventHandler.java @@ -23,8 +23,6 @@ public class DisplayStatsEventHandler implements IMainloopTask public void MainLoopUpdate() { // Display the fps - Main.window.setTitle("Project Zombie (" + DisplayWindow.fps + " fps)"); - fps = DisplayWindow.fps; DisplayWindow.fps = 0; diff --git a/src/projectzombie/display/DisplayWindow.java b/src/projectzombie/display/DisplayWindow.java index d217ae4..69f0cf7 100755 --- a/src/projectzombie/display/DisplayWindow.java +++ b/src/projectzombie/display/DisplayWindow.java @@ -169,6 +169,8 @@ public class DisplayWindow implements IMainloopTask glVertexAttribPointer(0, 2, GL_FLOAT, false, Float.BYTES * 2, 0); glEnableVertexAttribArray(0); + + DisplayRender.init(); } public void render() @@ -218,8 +220,8 @@ public class DisplayWindow implements IMainloopTask double player_health = Main.player.getHealth() / Main.player.maxHealth(); - if(player_health < 0.5) { - GL33.glUniform1f(glsl_effect_red, (float)(0.5 - player_health)); + if(player_health < 0.25) { + GL33.glUniform1f(glsl_effect_red, (float)Math.min(2 * (0.25 - player_health), 0.5)); GL33.glUniform1i(glsl_effect_red_freq, 20); } else { GL33.glUniform1f(glsl_effect_red, 0); diff --git a/src/projectzombie/entity/Entity.java b/src/projectzombie/entity/Entity.java index 162754a..9a3041e 100755 --- a/src/projectzombie/entity/Entity.java +++ b/src/projectzombie/entity/Entity.java @@ -12,14 +12,12 @@ import gl_engine.MathHelpers; import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2i; import gl_engine.vec.Vec3d; -import mainloop.task.IMainloopTask; import projectzombie.Main; import projectzombie.init.Entities; import projectzombie.model.IModel; import projectzombie.tiles.Tile; import projectzombie.util.math.TileState; import projectzombie.world.chunk.Chunk; -import projectzombie.world.chunk.ChunkEventHandler; import projectzombie.world.layer.Layer; public abstract class Entity implements IBdfClassManager @@ -27,8 +25,8 @@ public abstract class Entity implements IBdfClassManager public double hitbox = 1; public boolean isSolid = false; public Chunk chunk; - private TileState tile_front; - private TileState tile_back; + protected TileState tile_front; + protected TileState tile_back; protected static final Random rand = new Random(); public boolean emitsLight = false; private boolean isDead = false; @@ -74,8 +72,8 @@ public abstract class Entity implements IBdfClassManager } public int getID() { - for(int i=0;i ec = Entities.entities.get(i); + for(int i=0;i ec = Entities.ENTITIES.get(i); if(ec == this.getClass()) { return i; } @@ -92,13 +90,13 @@ public abstract class Entity implements IBdfClassManager int id = nl.get("id").getInteger(); // Send back null if the id is out of range - if(id < 0 || id >= Entities.entities.size()) { + 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); + Class ecl = Entities.ENTITIES.get(id); Constructor econ = ecl.getConstructor(BdfObject.class); // Send back the new entity @@ -171,46 +169,63 @@ public abstract class Entity implements IBdfClassManager { //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.xz()); this.chunk = chunk; + + Vec2i tpos = pos.xz().toInt(); + tile_back = chunk.getBackTile(tpos); tile_front = chunk.getFrontTile(tpos); - Vec3d new_pos = pos.add(velocity); - - if(isSolid) { - if(moveIsLegal(new Vec2d(new_pos.x, pos.z))) { - pos.x = new_pos.x; + if(velocity.x != 0 || velocity.y != 0 || velocity.z != 0) + { + Vec3d new_pos = pos.add(velocity); + + double slipperiness = Math.max( + tile_back.tile.getSlipperiness(tile_back), + tile_front.tile.getSlipperiness(tile_front)); + + if(isSolid) { + + if(moveIsLegal(new Vec2d(new_pos.x, pos.z))) { + pos.x = new_pos.x; + } else { + velocity.x *= -0.25; + } + + if(moveIsLegal(new Vec2d(pos.x, new_pos.z))) { + pos.z = new_pos.z; + } else { + velocity.z *= -0.25; + } + } else { - velocity.x *= 0.5; + pos.x = new_pos.x; + pos.z = new_pos.z; } - if(moveIsLegal(new Vec2d(pos.x, new_pos.z))) { - pos.z = new_pos.z; + if(new_pos.y > 0) { + pos.y = new_pos.y; } else { - velocity.z *= 0.5; + velocity.y *= -0.25; + velocity.x *= slipperiness; + velocity.z *= slipperiness; + pos.y = 0; } - } else { - pos.x = new_pos.x; - pos.z = new_pos.z; - } - - if(new_pos.y > 0) { - pos.y = new_pos.y; - } else { - velocity.y = 0; - velocity.x *= 0.75; - velocity.z *= 0.75; - pos.y = 0; } if(hasGravity) { velocity.y -= MathHelpers.FallSpeed; } - if(isSolid) { + if(isSolid) + { moveAwayFromSolidEntities(layer); + + if(pos.y <= 0) { + tile_back.tile.onWalkedOn(chunk, layer, tpos, this, tile_back); + tile_front.tile.onWalkedOn(chunk, layer, tpos, this, tile_front); + } } } @@ -233,8 +248,31 @@ public abstract class Entity implements IBdfClassManager } } - public void push(Vec3d vec) { - velocity = velocity.add(vec); + public void push(Vec3d vec) + { + if(pos.y <= 0) + { + Layer layer = Main.world.getLayer(); + + Vec2i tpos = pos.xz().toInt(); + tile_back = layer.getBackTile(tpos); + tile_front = layer.getFrontTile(tpos); + + double slipperiness = Math.max( + tile_back.tile.getSlipperiness(tile_back), + tile_front.tile.getSlipperiness(tile_front)); + + double resistance = Math.max( + tile_back.tile.getResistance(tile_back), + tile_front.tile.getResistance(tile_front)); + + velocity = velocity.add(vec.multiply((1 - slipperiness) * (1 - resistance))); + } + + else + { + velocity = velocity.add(vec); + } } public void kill() { @@ -285,7 +323,8 @@ public abstract class Entity implements IBdfClassManager 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) + Vec2d check = pos.subtract(new Vec2d(tpos.x + 0.5, tpos.y + 0.5)); + if(Math.max(Math.abs(check.x), Math.abs(check.y)) <= t.tileHitbox) { // Send back false return false; @@ -301,7 +340,8 @@ public abstract class Entity implements IBdfClassManager 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) + Vec2d check = pos.subtract(new Vec2d(tpos.x + 0.5, tpos.y + 0.5)); + if(Math.max(Math.abs(check.x), Math.abs(check.y)) <= t.tileHitbox) { // Send back false return false; diff --git a/src/projectzombie/entity/EntityAlive.java b/src/projectzombie/entity/EntityAlive.java index 84dc1dd..aa07d04 100755 --- a/src/projectzombie/entity/EntityAlive.java +++ b/src/projectzombie/entity/EntityAlive.java @@ -5,7 +5,6 @@ import projectzombie.world.layer.Layer; public interface EntityAlive { public void addHealth(double amount); - public void removeHealth(double amount); public double getHealth(); public void resetHealth(); public void clearHealth(); @@ -13,6 +12,10 @@ public interface EntityAlive public void setHealth(double health); public int bloodParticles(); + public void addDamage(double amount); + public void addFireDamage(double amount); + public void addBlastDamage(double amount); + public default void onDeath(Layer layer) { } } diff --git a/src/projectzombie/entity/EntityBoss.java b/src/projectzombie/entity/EntityBoss.java index b032138..19e675d 100755 --- a/src/projectzombie/entity/EntityBoss.java +++ b/src/projectzombie/entity/EntityBoss.java @@ -115,11 +115,9 @@ public class EntityBoss extends Entity implements IBossBar, EntityKillWithPartic Vec2d zombie_pos = new Vec2d( RandomHelpers.randrange(rand, -r*m, r*m)/(double)m, RandomHelpers.randrange(rand, -r*m, r*m)/(double)m); - Vec2i zombie_tpos = new Vec2i( - MathHelpers.floor(zombie_pos.x), - MathHelpers.floor(zombie_pos.y)); + Vec2i zombie_tpos = zombie_pos.toInt(); if( - layer.getBackTile(zombie_tpos).tile == layer.layergen.getTileDestroyed().tile && + layer.getBackTile(zombie_tpos).tile == layer.layergen.getTileDestroyed(layer, zombie_tpos).tile && layer.getFrontTile(zombie_tpos).tile == Tiles.VOID) { layer.spawnEntity(new EntityZombie(bpos.add(zombie_pos.xny()), getVelocity())); } @@ -165,9 +163,19 @@ public class EntityBoss extends Entity implements IBossBar, EntityKillWithPartic } @Override - public void removeHealth(double amount) { + public void addDamage(double amount) { this.health -= amount; } + + @Override + public void addFireDamage(double amount) { + + } + + @Override + public void addBlastDamage(double amount) { + addDamage(amount); + } @Override public double getHealth() { @@ -210,7 +218,7 @@ public class EntityBoss extends Entity implements IBossBar, EntityKillWithPartic } public void moveTowards(double angle) { - this.push(MathHelpers.moveTowards2(0.01, Math.toRadians(angle)).xny()); + this.push(MathHelpers.moveTowards2(0.04, Math.toRadians(angle)).xny()); } @Override @@ -221,16 +229,7 @@ public class EntityBoss extends Entity implements IBossBar, EntityKillWithPartic Drop some powerful loot */ - // Pick level 5 defence or level 5 gun upgrade - ItemStack stack; - if(rand.nextBoolean()) { - stack = new ItemStack(Items.DEFENCE_UPGRADE, 1, (byte)6); - } else { - stack = new ItemStack(Items.GUN_UPGRADE, 1, (byte)6); - } - // Spawn the loot - layer.spawnEntity(new EntityItem(getPos(), getVelocity(), stack)); layer.spawnEntity(new EntityItem(getPos(), getVelocity(), new ItemStack( Items.HEALTH_POTION, RandomHelpers.randrange(rand, 20), (byte)50))); layer.spawnEntity(new EntityItem(getPos(), getVelocity(), new ItemStack( diff --git a/src/projectzombie/entity/EntityBullet.java b/src/projectzombie/entity/EntityBullet.java index e325500..503f02f 100755 --- a/src/projectzombie/entity/EntityBullet.java +++ b/src/projectzombie/entity/EntityBullet.java @@ -2,12 +2,13 @@ package projectzombie.entity; import bdf.types.BdfNamedList; import bdf.types.BdfObject; -import gl_engine.MathHelpers; +import gl_engine.texture.TextureRef3D; import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2i; import gl_engine.vec.Vec3d; import projectzombie.entity.particle.ParticleBlood; import projectzombie.init.Models; +import projectzombie.init.Resources; import projectzombie.init.Sounds; import projectzombie.model.Model; import projectzombie.tiles.Tile; @@ -18,6 +19,8 @@ import projectzombie.world.layer.Layer; public class EntityBullet extends EntityParticle { + private static final TextureRef3D BULLET = Resources.ATLAS.get("/particle/bullet.png"); + private int time = 0; private Entity parent; @@ -111,9 +114,7 @@ public class EntityBullet extends EntityParticle EntityAlive ea = (EntityAlive)e; // Spawn some blood particles - if(!EntityParticle.DISABLED) { - chunk.spawnEntity(new ParticleBlood(getPos(), e.getVelocity().add(getVelocity()).divide(8))); - } + chunk.spawnEntity(new ParticleBlood(getPos(), e.getVelocity().add(getVelocity()).divide(8))); // Knock the entity back abit e.push(getVelocity()); @@ -124,7 +125,7 @@ public class EntityBullet extends EntityParticle Sounds.HIT.play(new Vec3d(pos.x, pos.y, pos.z), 1); // Harm the entity - ea.removeHealth(damage); + ea.addDamage(damage); // Kill the bullet chunk.killEntity(this); @@ -139,9 +140,19 @@ public class EntityBullet extends EntityParticle chunk.killEntity(this); } } + + @Override + public int getParticleCount() { + return 1; + } @Override - public Model getModel() { - return Models.PARTICLE_BULLET; + public boolean shouldKillParticle() { + return false; + } + + @Override + public EntityParticlePart getParticleAt(int id) { + return new EntityParticlePart(BULLET, getPos(), 0.1, 0b1000); } } diff --git a/src/projectzombie/entity/EntityContainer.java b/src/projectzombie/entity/EntityContainer.java index 84187f1..2cfc31d 100644 --- a/src/projectzombie/entity/EntityContainer.java +++ b/src/projectzombie/entity/EntityContainer.java @@ -3,7 +3,6 @@ package projectzombie.entity; import bdf.types.BdfArray; import bdf.types.BdfNamedList; import bdf.types.BdfObject; -import gl_engine.vec.Vec2d; import gl_engine.vec.Vec3d; import projectzombie.init.Models; import projectzombie.model.Model; diff --git a/src/projectzombie/entity/EntityDummy.java b/src/projectzombie/entity/EntityDummy.java index 0a1b84d..3326f20 100755 --- a/src/projectzombie/entity/EntityDummy.java +++ b/src/projectzombie/entity/EntityDummy.java @@ -1,7 +1,6 @@ package projectzombie.entity; import bdf.types.BdfObject; -import gl_engine.vec.Vec2d; import gl_engine.vec.Vec3d; import projectzombie.init.Models; import projectzombie.model.Model; @@ -24,11 +23,25 @@ public class EntityDummy extends Entity implements EntityAlive } @Override - public void removeHealth(double amount) { + public void addDamage(double amount) { int l = 4; amount = amount / (l / 2.5 + 1); System.out.println("Dummy Damage Aount: "+amount); } + + @Override + public void addFireDamage(double amount) { + int l = 4; + amount = amount / (l / 2.5 + 1); + System.out.println("Dummy Fire Damage Aount: "+amount); + } + + @Override + public void addBlastDamage(double amount) { + int l = 4; + amount = amount / (l / 2.5 + 1); + System.out.println("Dummy Blast Damage Aount: "+amount); + } @Override public double getHealth() { diff --git a/src/projectzombie/entity/EntityExplosion.java b/src/projectzombie/entity/EntityExplosion.java index 80cdfc7..0c743d5 100755 --- a/src/projectzombie/entity/EntityExplosion.java +++ b/src/projectzombie/entity/EntityExplosion.java @@ -55,7 +55,7 @@ public class EntityExplosion extends Entity super.tick(chunk, layer); boolean killed_entities = false; - Vec2d pos = getPos().xy(); + Vec2d pos = getPos().xz(); // Kill all the nearby entities for(Entity e : layer.getNearbyEntities(pos, radius)) @@ -70,11 +70,11 @@ public class EntityExplosion extends Entity double distance = e.getPos().distance(getPos()); if(distance == 0) { - ea.removeHealth(damage); + ea.addBlastDamage(damage); } else { - ea.removeHealth(damage / distance); + ea.addBlastDamage(damage / distance); } } } @@ -106,7 +106,7 @@ public class EntityExplosion extends Entity TileState fts = l.getFrontTile(tpos); // Is this tile the same as the "empty" tile - TileState ets = l.layergen.getTileDestroyed(); + TileState ets = l.layergen.getTileDestroyed(layer, tpos); // Set the tiles if(!bts.tile.unbreakable) { @@ -125,12 +125,21 @@ public class EntityExplosion extends Entity continue; } + Vec3d spos = new Vec3d(px, 0, py); + Vec3d svel; + + if(distance == 0) { + svel = MathHelpers.moveTowards2(0.01, Math.random() * MathHelpers.TWO_PI).xny(); + } else { + svel = spos.xz().subtract(pos).divide(distance * 100).xny(); + } + // Spawn some blood if entities were killed if(killed_entities) - entities[upto + 1] = new ParticleBlood(new Vec3d(px, 0, py), new Vec3d(0, 0, 0)); + entities[upto + 1] = new ParticleBlood(new Vec3d(px, 0, py), new Vec3d(0, 0, 0), 1); // Spawn some smoke - entities[upto] = new ParticleSmoke(new Vec3d(px, 0, py), new Vec3d(0, 0, 0)); + entities[upto] = new ParticleSmoke(spos, svel); upto += multiplier; } @@ -140,7 +149,7 @@ public class EntityExplosion extends Entity layer.spawnEntity(new EntityContainer(getPos(), getVelocity(), entities)); // Play the explosion sound - Sounds.EXPLOSION.play(new Vec3d(pos.x, pos.y, 0), 1); + Sounds.EXPLOSION.play(new Vec3d(pos.x, 0, pos.y), 1); // Kill the explosion entity kill(); diff --git a/src/projectzombie/entity/EntityFlare.java b/src/projectzombie/entity/EntityFlare.java index 64ef3c5..8e21afb 100755 --- a/src/projectzombie/entity/EntityFlare.java +++ b/src/projectzombie/entity/EntityFlare.java @@ -1,7 +1,6 @@ package projectzombie.entity; import bdf.types.BdfObject; -import gl_engine.vec.Vec2d; import gl_engine.vec.Vec3d; import projectzombie.init.Models; import projectzombie.model.Model; @@ -25,20 +24,7 @@ public class EntityFlare extends EntityTnt } @Override - public double getLightLevel() - { - if(this.explode_time > 1950) { - return 0; - } - - if(this.explode_time > 1900) { - return (1950 - this.explode_time) / 50.0; - } - - if(this.explode_time < 200) { - return this.explode_time / 200.0; - } - + public double getLightLevel() { return 1; } diff --git a/src/projectzombie/entity/EntityGrapplingHook.java b/src/projectzombie/entity/EntityGrapplingHook.java index df083ee..9554f0a 100755 --- a/src/projectzombie/entity/EntityGrapplingHook.java +++ b/src/projectzombie/entity/EntityGrapplingHook.java @@ -2,7 +2,6 @@ package projectzombie.entity; import bdf.types.BdfNamedList; import bdf.types.BdfObject; -import gl_engine.vec.Vec2d; import gl_engine.vec.Vec3d; import projectzombie.Main; import projectzombie.entity.player.EntityPlayer; diff --git a/src/projectzombie/entity/EntityHasArmor.java b/src/projectzombie/entity/EntityHasArmor.java new file mode 100644 index 0000000..2bcc19a --- /dev/null +++ b/src/projectzombie/entity/EntityHasArmor.java @@ -0,0 +1,8 @@ +package projectzombie.entity; + +import projectzombie.inventory.IInventoryArmor; +import projectzombie.inventory.InventoryArmor; + +public interface EntityHasArmor { + public IInventoryArmor getInventoryArmor(); +} diff --git a/src/projectzombie/entity/EntityHasClothing.java b/src/projectzombie/entity/EntityHasClothing.java new file mode 100644 index 0000000..647cf6a --- /dev/null +++ b/src/projectzombie/entity/EntityHasClothing.java @@ -0,0 +1,9 @@ +package projectzombie.entity; + +import projectzombie.inventory.IInventoryClothing; +import projectzombie.inventory.InventoryArmor; +import projectzombie.inventory.InventoryClothing; + +public interface EntityHasClothing { + public IInventoryClothing getInventoryClothing(); +} diff --git a/src/projectzombie/entity/EntityHasInventory.java b/src/projectzombie/entity/EntityHasInventory.java new file mode 100755 index 0000000..16baf8c --- /dev/null +++ b/src/projectzombie/entity/EntityHasInventory.java @@ -0,0 +1,9 @@ +package projectzombie.entity; + +import projectzombie.inventory.IInventory; +import projectzombie.inventory.Inventory; + +public interface EntityHasInventory +{ + public IInventory getInventory(); +} diff --git a/src/projectzombie/entity/EntityHasTasks.java b/src/projectzombie/entity/EntityHasTasks.java new file mode 100644 index 0000000..3fcb1c4 --- /dev/null +++ b/src/projectzombie/entity/EntityHasTasks.java @@ -0,0 +1,8 @@ +package projectzombie.entity; + +import projectzombie.task.Task; + +public interface EntityHasTasks +{ + public void addTask(Task task); +} diff --git a/src/projectzombie/entity/EntityInventory.java b/src/projectzombie/entity/EntityInventory.java deleted file mode 100755 index 7e3b59f..0000000 --- a/src/projectzombie/entity/EntityInventory.java +++ /dev/null @@ -1,8 +0,0 @@ -package projectzombie.entity; - -import projectzombie.inventory.Inventory; - -public interface EntityInventory -{ - public Inventory getInventory(); -} diff --git a/src/projectzombie/entity/EntityItem.java b/src/projectzombie/entity/EntityItem.java index eaedb49..bb7a4b8 100755 --- a/src/projectzombie/entity/EntityItem.java +++ b/src/projectzombie/entity/EntityItem.java @@ -3,15 +3,14 @@ package projectzombie.entity; import bdf.types.BdfNamedList; import bdf.types.BdfObject; import gl_engine.MathHelpers; -import gl_engine.vec.Vec2d; import gl_engine.vec.Vec3d; import projectzombie.model.Model; +import projectzombie.model.ModelItem; import projectzombie.util.math.ItemStack; -import projectzombie.util.math.random.RandomHelpers; import projectzombie.world.chunk.Chunk; import projectzombie.world.layer.Layer; -public class EntityItem extends Entity +public class EntityItem extends EntityParticle { private ItemStack stack; private int pickup_time = 200; @@ -51,7 +50,7 @@ public class EntityItem extends Entity this.emitsLight = true; this.stack = stack; - push(new Vec3d(MathHelpers.moveTowards2(0.025, angle), 0.025)); + push(MathHelpers.moveTowards2(0.05, angle).xny().add(new Vec3d(0, 0.1, 0))); } public EntityItem(Vec3d pos, Vec3d velocity, ItemStack stack) { @@ -69,9 +68,10 @@ public class EntityItem extends Entity super.tick(chunk, layer); age += 1; + pickup_time -= 1; // Merge nearby stacks - for(Entity e : layer.getNearbyEntities(getPos().xz(), 1)) + for(Entity e : layer.getNearbyEntities(getPos().xz(), 2)) { if(e instanceof EntityItem && e != this) { EntityItem ei = (EntityItem) e; @@ -79,25 +79,29 @@ public class EntityItem extends Entity if( ei.stack.meta == this.stack.meta && ei.stack.item == this.stack.item && + ei.stack.count + this.stack.count <= this.stack.item.max && ei.age > this.age ) { - this.pickup_time = 200; - this.stack.count += ei.stack.count; - setPos(ei.getPos().divide(2).add(getPos().divide(2))); - setVelocity(ei.getVelocity().divide(2).add(getVelocity().divide(2))); - ei.kill(); + if(ei.getPos().squareDistance(getPos()) < 0.1) { + this.pickup_time = 200; + this.stack.count += ei.stack.count; + setPos(ei.getPos().divide(2).add(getPos().divide(2))); + setVelocity(ei.getVelocity().divide(2).add(getVelocity().divide(2))); + ei.kill(); + } + + else { + push(ei.getPos().subtract(getPos()).normalize().multiply(0.001)); + } } } - } - - if(pickup_time == 0) - { - for(Entity e : layer.getNearbyEntities(getPos().xz(), 1)) + + if(pickup_time <= 0 && e instanceof EntityHasInventory) { - if(e instanceof EntityInventory) - { - // Pick the stack up if its an inventory + if(e.getPos().squareDistance(getPos()) < 0.5) { stack.item.onPickedUp(stack, layer, chunk, e); + } else { + push(e.getPos().subtract(getPos()).normalize().multiply(0.05)); } } } @@ -108,10 +112,24 @@ public class EntityItem extends Entity return; } } + + @Override + public boolean shouldKillParticle() { + return false; + } @Override - public Model getModel() { - return stack.item.getModel(stack.meta).getItemModel(); + public EntityParticlePart getParticleAt(int id) { + ModelItem model = stack.item.getModel(stack.meta); + EntityParticlePart particle = new EntityParticlePart(model.tex, getPos().add(new Vec3d(0, 0.25, 0)), 0.5, 0b1000); + particle.animationSize = model.animationSize; + particle.animationSpeed = model.animationSpeed; + return particle; + } + + @Override + public int getParticleCount() { + return 1; } diff --git a/src/projectzombie/entity/EntityParticle.java b/src/projectzombie/entity/EntityParticle.java index 5286aa5..e4fedd0 100755 --- a/src/projectzombie/entity/EntityParticle.java +++ b/src/projectzombie/entity/EntityParticle.java @@ -1,17 +1,16 @@ package projectzombie.entity; import bdf.types.BdfObject; -import gl_engine.texture.TextureRef3D; -import gl_engine.vec.Vec2d; import gl_engine.vec.Vec3d; import projectzombie.Main; +import projectzombie.model.IModel; import projectzombie.world.chunk.Chunk; import projectzombie.world.layer.Layer; public abstract class EntityParticle extends Entity { - public static boolean DISABLED = false; - protected TextureRef3D tex; + public abstract int getParticleCount(); + public abstract EntityParticlePart getParticleAt(int id); public EntityParticle(BdfObject bdf) { super(bdf); @@ -26,6 +25,15 @@ public abstract class EntityParticle extends Entity super.tick(chunk, layer); // Kill the particle if the player can't see it to reduce lag - if(Main.player.getPos().squareDistance(getPos()) > Chunk.RENDER_DISTANCE * 16) this.kill(); + if(shouldKillParticle()) this.kill(); + } + + public boolean shouldKillParticle() { + return Main.player.getPos().squareDistance(getPos()) > Chunk.RENDER_DISTANCE * 16; + } + + @Override + public IModel getModel() { + return null; } } diff --git a/src/projectzombie/entity/EntityParticlePart.java b/src/projectzombie/entity/EntityParticlePart.java new file mode 100644 index 0000000..acc6ca1 --- /dev/null +++ b/src/projectzombie/entity/EntityParticlePart.java @@ -0,0 +1,29 @@ +package projectzombie.entity; + +import gl_engine.texture.TextureRef3D; +import gl_engine.vec.Vec3d; + +public class EntityParticlePart +{ + public int animationSize = 1; + public int animationSpeed = 1; + public TextureRef3D tex; + public double size; + public Vec3d pos; + public int flags; + + public double getFade() { + return 1; + } + + public boolean isFlat() { + return false; + } + + public EntityParticlePart(TextureRef3D tex, Vec3d pos, double size, int flags) { + this.tex = tex; + this.pos = pos; + this.size = size; + this.flags = flags; + } +} diff --git a/src/projectzombie/entity/EntityTnt.java b/src/projectzombie/entity/EntityTnt.java index f8d6b92..3db4197 100755 --- a/src/projectzombie/entity/EntityTnt.java +++ b/src/projectzombie/entity/EntityTnt.java @@ -27,7 +27,7 @@ public class EntityTnt extends Entity implements EntityHoldsEntities public EntityTnt(BdfObject bdf) { super(bdf); - this.smoke_particles = new ParticleSmokeTrail(this, 1); + this.smoke_particles = new ParticleSmokeTrail(this); } @Override @@ -53,13 +53,13 @@ public class EntityTnt extends Entity implements EntityHoldsEntities } public EntityTnt(Vec3d pos, Vec3d velocity, double angle, int explode_radius, double explode_damage) { - super(pos, velocity); + super(pos, velocity.add(new Vec3d(0, 0.1, 0))); 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.explode_damage = explode_damage; - this.smoke_particles = new ParticleSmokeTrail(this, 1); + this.smoke_particles = new ParticleSmokeTrail(this); // Set to 2.5 seconds this.explode_time = 250; @@ -78,8 +78,6 @@ public class EntityTnt extends Entity implements EntityHoldsEntities if(!active) { - smoke_particles.stopParticles(); - if(smoke_particles.noMoreParticles()) { kill(); } @@ -90,6 +88,7 @@ public class EntityTnt extends Entity implements EntityHoldsEntities // Explode if it is time for the tnt to blow up explode_time -= 1; if(explode_time < 0) { + smoke_particles.stopParticles(); active = false; explode(layer); } diff --git a/src/projectzombie/entity/EntityZombie.java b/src/projectzombie/entity/EntityZombie.java index 84574fb..9189aa6 100755 --- a/src/projectzombie/entity/EntityZombie.java +++ b/src/projectzombie/entity/EntityZombie.java @@ -4,8 +4,6 @@ import java.util.Random; import bdf.types.BdfNamedList; import bdf.types.BdfObject; -import gl_engine.MathHelpers; -import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2i; import gl_engine.vec.Vec3d; import projectzombie.Main; @@ -137,11 +135,7 @@ public class EntityZombie extends Entity implements EntityAlive, EntityKillWithP // Walk towards the player if(walk_to != null) { - push(walk_to.subtract(getPos()).normalize().multiply(0.016)); - - if(Double.isNaN(walk_to.x + walk_to.y + walk_to.z + getPos().x + getPos().y + getPos().z + getVelocity().x + getVelocity().y + getVelocity().z)) { - Double.isFinite(0); - } + push(walk_to.subtract(getPos()).normalize().multiply(0.064)); walking_for += 1; } @@ -157,7 +151,7 @@ public class EntityZombie extends Entity implements EntityAlive, EntityKillWithP int d = (int)(1 + gun_level / 5.0); Vec3d bullet_velocity = getVelocity().add(Main.player.getPos().subtract(getPos())).normalize().multiply(0.2); Vec3d bullet_pos = getPos().add(new Vec3d(0, 0.4, 0)); - //Main.world.getLayer().spawnEntity(new EntityBullet(bullet_pos, bullet_velocity, this, 20*d*d, 60)); + Main.world.getLayer().spawnEntity(new EntityBullet(bullet_pos, bullet_velocity, this, 20*d*d, 60)); } } } @@ -177,9 +171,19 @@ public class EntityZombie extends Entity implements EntityAlive, EntityKillWithP } @Override - public void removeHealth(double amount) { + public void addDamage(double amount) { health -= amount; } + + @Override + public void addBlastDamage(double amount) { + addDamage(amount); + } + + @Override + public void addFireDamage(double amount) { + addDamage(amount); + } @Override public double getHealth() { diff --git a/src/projectzombie/entity/EntityZombieArmored.java b/src/projectzombie/entity/EntityZombieArmored.java index 0a61b96..900395e 100755 --- a/src/projectzombie/entity/EntityZombieArmored.java +++ b/src/projectzombie/entity/EntityZombieArmored.java @@ -1,7 +1,6 @@ package projectzombie.entity; import bdf.types.BdfObject; -import gl_engine.vec.Vec2d; import gl_engine.vec.Vec3d; import projectzombie.init.Models; import projectzombie.model.Model; diff --git a/src/projectzombie/entity/particle/ParticleBlood.java b/src/projectzombie/entity/particle/ParticleBlood.java index 6d4441c..622d4b0 100755 --- a/src/projectzombie/entity/particle/ParticleBlood.java +++ b/src/projectzombie/entity/particle/ParticleBlood.java @@ -1,6 +1,5 @@ package projectzombie.entity.particle; -import gl_engine.vec.Vec2d; import gl_engine.vec.Vec3d; import projectzombie.init.Models; @@ -11,12 +10,12 @@ public class ParticleBlood extends ParticleBreak } public ParticleBlood(Vec3d pos, Vec3d velocity) { - this(pos, velocity, 400); + this(pos, velocity, 100); } @Override - public Vec2d getParticleSize() { - return new Vec2d(0.05, 0.05); + public double getParticleSize() { + return 0.05; } } diff --git a/src/projectzombie/entity/particle/ParticleBreak.java b/src/projectzombie/entity/particle/ParticleBreak.java index 44cdb33..0a00905 100755 --- a/src/projectzombie/entity/particle/ParticleBreak.java +++ b/src/projectzombie/entity/particle/ParticleBreak.java @@ -1,49 +1,59 @@ package projectzombie.entity.particle; -import static org.lwjgl.opengl.GL15.glBindBuffer; -import static org.lwjgl.opengl.GL15.glBufferData; -import static org.lwjgl.opengl.GL15.glGenBuffers; - import java.util.Random; -import org.lwjgl.opengl.GL33; - import gl_engine.MathHelpers; -import gl_engine.matrix.Matrix4; import gl_engine.texture.TextureRef3D; -import gl_engine.vec.Vec2d; -import gl_engine.vec.Vec2i; import gl_engine.vec.Vec3d; import projectzombie.Main; import projectzombie.entity.EntityParticle; -import projectzombie.init.Models; +import projectzombie.entity.EntityParticlePart; import projectzombie.model.IModel; import projectzombie.model.Model; -import projectzombie.model.ModelVertical; import projectzombie.world.chunk.Chunk; import projectzombie.world.layer.Layer; -public class ParticleBreak extends EntityParticle implements IModel +public class ParticleBreak extends EntityParticle { protected static final Random rand = new Random(); - protected class Break { - TextureRef3D ref; - Vec3d velocity; - Vec3d pos; - boolean moving; - int time, flags; + protected class Break extends EntityParticlePart + { + public Vec3d velocity; + public boolean moving; + + public Break(TextureRef3D tex, Vec3d pos, Vec3d velocity, boolean moving, double size, int flags) { + super(tex, pos, size, flags); + + this.velocity = velocity; + this.moving = moving; + } + + @Override + public boolean isFlat() { + return isStill(this); + } + + @Override + public double getFade() { + return getParticleFade(); + } } protected Break[] particles; - private int ibo, vbo, vao; - private boolean generated; - protected int dead, still, time; + protected int still, time; protected double still_ypos; - protected boolean do_gravity; - public Vec2d getParticleSize() { - return new Vec2d(0.1, 0.1); + protected double getParticleFade() { + return time / 1000.0; + } + + public double getParticleSize() { + return 0.1; + } + + protected double getParticleSpeed() { + return 0.01; } public ParticleBreak(Vec3d pos, Vec3d velocity, IModel model) { @@ -54,24 +64,6 @@ public class ParticleBreak extends EntityParticle implements IModel this(pos, velocity, model, count, 0.05); } - protected Break createParticle( - IModel model, TextureRef3D ref, int tex_id, - Vec3d pos, Vec3d velocity, float[] verticies, - double velocity_up_multiplier, double model_height, int i) - { - Break particle = new Break(); - - particle.pos = pos.add(new Vec3d(0, rand.nextDouble() * model_height, 0)); - particle.velocity = velocity.multiply(rand.nextDouble()).add( - MathHelpers.moveTowards2(0.01, rand.nextDouble() * MathHelpers.TWO_PI).xny().add( - new Vec3d(0, rand.nextDouble() * velocity_up_multiplier, 0))); - particle.ref = ref; - particle.moving = true; - particle.flags = ((int)verticies[tex_id * Model.SIZE + Model.SIZE - 1] & 0b0110) | 0b1000; - - return particle; - } - protected ParticleBreak(Vec3d pos, Vec3d velocity, IModel model, int count, double velocity_up_multiplier) { super(new Vec3d(pos.x, 0, pos.z), new Vec3d(0, 0, 0)); @@ -81,66 +73,61 @@ public class ParticleBreak extends EntityParticle implements IModel this.hasGravity = false; - double model_height = model.getHeight(); - TextureRef3D[] textures = model.getTextures(); + double model_height = getHeight(model); float[] verticies = model.getVerticies(); - count *= model_height; + if(model_height > 1) { + count *= model_height; + } + + if(model.getSize() == 0) { + count = 0; + } + particles = new Break[count]; for(int i=0;i 0.75) { - dead += 1; + if(time < 0) { + onAllDead(); } } protected void onAllDead() { - if(getPos().squareDistance(Main.player.getPos()) > 32) { - kill(); - } + kill(); } protected boolean isStill(Break particle) { - return particle.pos.y < 0; + return particle.pos.y <= still_ypos; } protected void onStill(Break particle) { particle.moving = false; particle.pos.y = still_ypos; + particle.flags &= 0b0110; still += 1; } @@ -154,17 +141,12 @@ public class ParticleBreak extends EntityParticle implements IModel time -= 1; - if(dead == particles.length - 1) { - onAllDead(); - return; - } - if(still == particles.length) { onAllStill(); return; } - for(int i=0;i<(particles.length - dead);i++) + for(int i=0;i 32 || opacity <= 0 || getPos().y > 16) { - kill(); - } - - opacity -= disappear_speed; - - if(DISABLED) { - kill(); - } + setVelocity(getVelocity().multiply(new Vec3d(0.995, 1, 0.995))); } @Override - public Model getModel() { - return model; + public int getParticleCount() { + return 1; + } + + @Override + public EntityParticlePart getParticleAt(int id) { + return new EntityParticlePart(model.getTextures()[0], getPos(), 1, 0b1000); } } diff --git a/src/projectzombie/entity/particle/ParticleSmokeTrail.java b/src/projectzombie/entity/particle/ParticleSmokeTrail.java index 784ed47..fb9fab1 100755 --- a/src/projectzombie/entity/particle/ParticleSmokeTrail.java +++ b/src/projectzombie/entity/particle/ParticleSmokeTrail.java @@ -1,6 +1,6 @@ package projectzombie.entity.particle; -import java.util.Random; +import java.util.Arrays; import gl_engine.MathHelpers; import gl_engine.texture.TextureRef3D; @@ -8,89 +8,109 @@ import gl_engine.vec.Vec2d; import gl_engine.vec.Vec3d; import projectzombie.entity.Entity; import projectzombie.entity.EntityParticle; +import projectzombie.entity.EntityParticlePart; import projectzombie.init.Models; -import projectzombie.model.IModel; -import projectzombie.model.Model; +import projectzombie.util.math.comparator.Comparators; import projectzombie.world.chunk.Chunk; import projectzombie.world.layer.Layer; -public class ParticleSmokeTrail extends ParticleBreak +public class ParticleSmokeTrail extends EntityParticle { + protected class SmokeTrail extends EntityParticlePart + { + Vec3d velocity; + int time; + + SmokeTrail(TextureRef3D tex, Vec3d pos, Vec3d velocity) { + super(tex, pos.add(new Vec3d(0, 0.5, 0)), 0, 0b1000); + + time = 500; + + this.velocity = velocity; + } + + boolean isDead() { + return time <= 0; + } + + void update() + { + if(time <= 0) { + return; + } + + time -= 1; + pos = pos.add(velocity); + size = time / 10000.0; + } + + @Override + public double getFade() { + return 0.5; + } + } + private Entity parent; - private double offset; + private int dead; private boolean generating_particles = true; + private SmokeTrail[] particles; - public ParticleSmokeTrail(Entity parent, double offset, int count) { - super(parent.getPos(), parent.getVelocity(), Models.PARTICLE_SMOKE_TRAIL, count); + public ParticleSmokeTrail(Entity parent) { + this(parent, 1000); + } + + private ParticleSmokeTrail(Entity parent, int size) { + super(parent.getPos(), new Vec3d(0, 0, 0)); - time = count; - do_gravity = false; + dead = size; + particles = new SmokeTrail[size]; - this.offset = offset; this.parent = parent; } - @Override - public Vec2d getParticleSize() { - return new Vec2d(0.04, 0.04); - } - - public ParticleSmokeTrail(Entity parent, double offset) { - this(parent, offset, 2000); - } - - @Override - protected Break createParticle( - IModel model, TextureRef3D ref, int tex_id, Vec3d pos, Vec3d velocity, - float[] verticies, double velocity_up_multiplier, double model_height, int i) - { - Break particle = new Break(); - - particle.moving = false; - particle.pos = pos.copy(); - particle.velocity = new Vec3d(0, 0, 0); - particle.flags = ((int)verticies[tex_id * Model.SIZE + Model.SIZE - 1] & 0b0110) | 0b1000; - particle.ref = ref; - - return particle; - } - @Override public void tick(Chunk chunk, Layer layer) { super.tick(chunk, layer); - for(int i=0;i= particles.length) { - dead = particles.length - 1; - kill(); + if(!generating_particles) { + return; + } + + for(int i=0;i tasks; private Inventory inventory; - public int inventory_hand = 0; + private InventoryArmor armor; + private InventoryClothing clothing; - public int defence_level = 0; - public int gun_level = 0; + public int inventory_hand = 0; public double angle; @@ -57,21 +73,29 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory public EntityPlayer(BdfObject bdf) { super(bdf); + tasks = new ArrayList(); } @Override public void BdfClassLoad(BdfObject bdf) { super.BdfClassLoad(bdf); BdfNamedList nl = bdf.getNamedList(); - bullet_frequency = nl.get("bullet_frequency").getInteger(); health = nl.get("health").getDouble(); dead = nl.get("dead").getBoolean(); inventory = new Inventory(nl.get("inventory")); - defence_level = nl.get("defence_level").getInteger(); - gun_level = nl.get("gun_level").getInteger(); + armor = new InventoryArmor(nl.get("armor")); + clothing = new InventoryClothing(nl.get("clothing")); angle = nl.get("angle").getDouble(); temperature = nl.get("temperature").getDouble(); hydration = nl.get("hydration").getDouble(); + + tasks = new ArrayList(); + + Task[] tasks = Task.loadTasks(this, nl.get("tasks")); + + for(int i=0;i(); - inventory.addItem(new ItemStack(Items.AMMO, 999, (short)0)); - inventory.addItem(new ItemStack(Items.SPAWN_DUMMY, 999, (short)0)); - inventory.addItem(new ItemStack(Items.SPAWN_ZOMBIE, 999, (short)0)); - inventory.addItem(new ItemStack(Items.LANTERN, 999, (short)0)); - inventory.addItem(new ItemStack(Items.FLARE, 999, (short)0)); + // Create the inventory + inventory = new Inventory(42); + armor = new InventoryArmor(); + clothing = new InventoryClothing(); } @Override @@ -136,19 +158,13 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory { chunk = layer.getChunk(getPos().xz()); - temperature = 0.5; - health = health_max; - hydration = 1; - if(chunk != null && chunk.c_pos != null && (last_chunk == null || !chunk.c_pos.equal(last_chunk))) { last_chunk = chunk.c_pos; DisplayLighting.setDirty(); } - if(dead) return; - // Handle player deaths - if(health <= 0) + if(health <= 0 && !dead) { chunk.spawnEntity(new ParticleBreak(getPos(), getVelocity(), getModel())); @@ -159,27 +175,18 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory else { dead = true; health = 0; - - Main.mainloop.register(new IMainloopTask() { - - @Override - public void MainLoopUpdate() { - Main.menu = new MenuDeath(); - } - - @Override - public boolean MainLoopRepeat() { - return false; - } - - @Override - public boolean MainLoopDelay(long millis) { - return millis > 2500; - } - }); + addTask(new TaskDeathScreen(this)); + } + } + + for(int i=0;i 0.7) { - health -= temperature - 0.7; + health -= 4 * (temperature - 0.7); } if(hydration <= 0) { @@ -229,11 +236,6 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory if(MOVE_BACKWARD) { this.moveTowards(this.angle + 180); } - - // Use the gun - if(GUN) { - this.fireBullet(0); - } } @Override @@ -255,37 +257,76 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory } public void moveTowards(double angle) { - this.moveTowards(angle, 0.02); + this.moveTowards(angle, 0.08); } - public void fireBullet(double angle) - { + public void leftClick() { if(dead || in_animation) return; - bullet_frequency += 1; - bullet_frequency %= 10; + Layer layer = Main.world.getLayer(); + ItemStack is = inventory.getItem(inventory_hand); - // Is there enough ammo and are the bullets at the right frequency - if(bullet_frequency == 0 && getAmmo() > 0) + if(is.isEmpty() || !is.item.onPlayerLeftClick(is, Main.world.getLayer(), chunk, this)) { - // Remove some ammo - inventory.removeItem(Items.AMMO, 1); + ItemTool tool = (is.item instanceof ItemTool) ? (ItemTool) is.item : null; - // Summon bullets at this angle relative to the player - int d = (int)(1 + gun_level / 4.0); - Vec3d bullet_velocity = getVelocity().add(MathHelpers.moveTowards2(0.2, Math.toRadians(angle + this.angle)).xny()); - Vec3d bullet_pos = getPos().add(new Vec3d(0, 0.4, 0)); - Main.world.getLayer().spawnEntity(new EntityBullet(bullet_pos, bullet_velocity, this, 20*d*d, 60)); + Vec2i pos = getPos().xz().add(MathHelpers.moveTowards2(0.5, Math.toRadians(angle))).toInt(); + + for(int ti=0;ti<2;ti++) + { + TileState ts; + + if(ti == 0) { + ts = layer.getFrontTile(pos); + } else { + ts = layer.getBackTile(pos); + } + + if(ts.tile.canTileBreak(tile_front, is, tool)) + { + break_progress += 1; + + if(!pos.equal(break_pos)) { + break_progress = 0; + break_pos = pos; + } + + if(break_progress > ts.tile.hardness) + { + ItemStack[] stacks = ts.tile.getTileDrops(tile_front); + + for(ItemStack stack : stacks) { + layer.spawnEntity(new EntityItem( + pos.toDouble().add(new Vec2d(0.5, 0.5)).xny(), + new Vec3d(0, 0, 0), stack)); + } + + if(ti == 0) { + layer.breakFrontTile(pos); + } else { + layer.breakBackTile(pos); + } + + break_progress = 0; + + if(tool != null) { + tool.toolOnUse(is); + } + } + + break; + } + } } } - public void activateItem() { + public void rightClick() { if(dead || in_animation) return; ItemStack is = inventory.getItem(inventory_hand); - if(!is.isEmpty()) { - is.item.onPlayerAction(is, Main.world.getLayer(), chunk, this); + if(is.isEmpty() || !is.item.onPlayerRightClick(is, Main.world.getLayer(), chunk, this)) { + activateTile(); } } @@ -296,10 +337,20 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory } @Override - public void removeHealth(double amount) { - amount = amount / (defence_level / 2.5 + 1); + public void addDamage(double amount) { + //amount = amount / (defence_level / 2.5 + 1); health -= amount; } + + @Override + public void addFireDamage(double amount) { + addDamage(amount); + } + + @Override + public void addBlastDamage(double amount) { + addDamage(amount); + } @Override public double getHealth() { @@ -350,7 +401,7 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory @Override public Model getModel() { - return moving ? PLAYER_MOVING : PLAYER_STILL; + return moving ? MODEL.model_back_moving : MODEL.model_back_still; } public double getTemperature() { @@ -360,4 +411,31 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory public double getHydration() { return hydration; } + + public void setInAnimation(boolean status) + { + in_animation = status; + hasGravity = !status; + isSolid = !status; + moving = status; + } + + @Override + public void addTask(Task task) { + tasks.add(task); + } + + public void rehydrate() { + hydration += 0.001; + } + + @Override + public InventoryClothing getInventoryClothing() { + return clothing; + } + + @Override + public InventoryArmor getInventoryArmor() { + return armor; + } } diff --git a/src/projectzombie/init/Entities.java b/src/projectzombie/init/Entities.java index 6c3d862..12a0b09 100755 --- a/src/projectzombie/init/Entities.java +++ b/src/projectzombie/init/Entities.java @@ -19,7 +19,7 @@ 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) { @@ -30,7 +30,7 @@ public class Entities System.exit(1); } - entities.add(e); + ENTITIES.add(e); } public static void init() diff --git a/src/projectzombie/init/Items.java b/src/projectzombie/init/Items.java index 1028477..d849e09 100755 --- a/src/projectzombie/init/Items.java +++ b/src/projectzombie/init/Items.java @@ -3,14 +3,18 @@ package projectzombie.init; import java.util.ArrayList; import projectzombie.items.Item; +import projectzombie.items.ItemAcorn; import projectzombie.items.ItemAmmo; -import projectzombie.items.ItemDefenceUpgrade; import projectzombie.items.ItemEmpty; import projectzombie.items.ItemFlare; +import projectzombie.items.ItemFlint; import projectzombie.items.ItemGrapplingHook; -import projectzombie.items.ItemGunUpgrade; import projectzombie.items.ItemHealthPotion; +import projectzombie.items.ItemHempSeed; +import projectzombie.items.ItemInfestation; import projectzombie.items.ItemLantern; +import projectzombie.items.ItemLog; +import projectzombie.items.ItemPlantFibre; import projectzombie.items.ItemRock; import projectzombie.items.ItemTnt; import projectzombie.items.spawner.ItemSpawnDummy; @@ -30,8 +34,6 @@ public class Items register(EMPTY); register(AMMO); - register(DEFENCE_UPGRADE); - register(GUN_UPGRADE); register(HEALTH_POTION); register(TNT); register(LANTERN); @@ -42,13 +44,18 @@ public class Items register(SPAWN_DUMMY); register(ROCK); + register(FLINT); + register(LOG); + register(ACORN); + register(PLANT_FIBRE); + register(HEMP_SEED); register(AMMO); + + register(INFESTATION); } 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(); @@ -60,4 +67,11 @@ public class Items public static final Item SPAWN_DUMMY = new ItemSpawnDummy(); public static final Item ROCK = new ItemRock(); + public static final Item FLINT = new ItemFlint(); + public static final Item LOG = new ItemLog(); + public static final Item ACORN = new ItemAcorn(); + public static final Item HEMP_SEED = new ItemHempSeed(); + public static final Item PLANT_FIBRE = new ItemPlantFibre(); + + public static final Item INFESTATION = new ItemInfestation(); } diff --git a/src/projectzombie/init/Layers.java b/src/projectzombie/init/Layers.java index d4f9510..27b19b4 100755 --- a/src/projectzombie/init/Layers.java +++ b/src/projectzombie/init/Layers.java @@ -5,6 +5,7 @@ import java.util.Random; import projectzombie.Main; import projectzombie.world.World; import projectzombie.world.layer.Layer; +import projectzombie.world.layer.layergen.LayerGenBossArena; public class Layers { diff --git a/src/projectzombie/init/Models.java b/src/projectzombie/init/Models.java index 532e97a..66216e6 100755 --- a/src/projectzombie/init/Models.java +++ b/src/projectzombie/init/Models.java @@ -2,34 +2,65 @@ package projectzombie.init; import gl_engine.vec.Vec2d; import projectzombie.model.Model; +import projectzombie.model.ModelBox; +import projectzombie.model.ModelCactus; +import projectzombie.model.ModelCross; import projectzombie.model.ModelEmpty; import projectzombie.model.ModelGrass; import projectzombie.model.ModelGui; import projectzombie.model.ModelItem; +import projectzombie.model.ModelPlayer; import projectzombie.model.ModelRandom; +import projectzombie.model.ModelRock; +import projectzombie.model.ModelTallGrass; import projectzombie.model.ModelTile; import projectzombie.model.ModelTree; +import projectzombie.model.ModelTreeSnow; import projectzombie.model.ModelVertical; +import projectzombie.model.player.ModelPlayerHead; public class Models { public static final Model EMPTY = new ModelEmpty(); - public static final Model TILE_GRASS = new ModelGrass(); - public static final Model TILE_TREE = new ModelTree(); + public static final Model TILE_TALL_GRASS = new ModelTallGrass(); + public static final Model TILE_GRASS = new ModelGrass(); + public static final Model TILE_TREE = new ModelTree(); + public static final Model TILE_TREE_SNOW = new ModelTreeSnow(); - public static final Model TILE_CACTUS_1 = new ModelVertical(Resources.ATLAS.get("/tile/cactus1.png"), new Vec2d(1, 4)); - public static final Model TILE_CACTUS_2 = new ModelVertical(Resources.ATLAS.get("/tile/cactus2.png"), new Vec2d(1, 4)); - public static final Model TILE_CACTUS_3 = new ModelVertical(Resources.ATLAS.get("/tile/cactus3.png"), new Vec2d(1, 4)); - public static final Model TILE_CACTUS_4 = new ModelVertical(Resources.ATLAS.get("/tile/cactus4.png"), new Vec2d(1, 4)); + public static final Model TILE_SAPLING_1 = new ModelCross(Resources.ATLAS.get("/tile/sapling1.png")); + public static final Model TILE_SAPLING_2 = new ModelCross(Resources.ATLAS.get("/tile/sapling2.png")); + public static final Model TILE_SAPLING_3 = new ModelCross(Resources.ATLAS.get("/tile/sapling3.png")); + public static final Model TILE_SAPLING_4 = new ModelCross(Resources.ATLAS.get("/tile/sapling4.png")); + + public static final Model TILE_CACTUS_1 = new ModelCactus(Resources.ATLAS.get("/tile/cactus1.png"), 0.5); + public static final Model TILE_CACTUS_2 = new ModelCactus(Resources.ATLAS.get("/tile/cactus2.png"), 1.0); + public static final Model TILE_CACTUS_3 = new ModelCactus(Resources.ATLAS.get("/tile/cactus3.png"), 1.5); + public static final Model TILE_CACTUS_4 = new ModelCactus(Resources.ATLAS.get("/tile/cactus4.png"), 2.0); + + public static final Model[] TILE_HEMP = new Model[] { + new ModelBox(Resources.ATLAS.get("/tile/hemp1.png")), + new ModelBox(Resources.ATLAS.get("/tile/hemp2.png")), + new ModelBox(Resources.ATLAS.get("/tile/hemp3.png")), + new ModelBox(Resources.ATLAS.get("/tile/hemp4.png")), + new ModelBox(Resources.ATLAS.get("/tile/hemp5.png"), new Vec2d(1, 2)), + new ModelBox(Resources.ATLAS.get("/tile/hemp6.png"), new Vec2d(1, 2)), + new ModelBox(Resources.ATLAS.get("/tile/hemp7.png"), new Vec2d(1, 2)), + new ModelBox(Resources.ATLAS.get("/tile/hemp8.png"), new Vec2d(1, 2)), + }; public static final Model TILE_SNOW = new ModelTile(Resources.ATLAS.get("/tile/snow.png")); + public static final Model TILE_ICE = new ModelTile(Resources.ATLAS.get("/tile/ice.png")); + public static final Model TILE_ICE_WALL = new ModelTile(Resources.ATLAS.get("/tile/ice_wall.png")); + public static final Model TILE_SANDSTONE = new ModelTile(Resources.ATLAS.get("/tile/sandstone.png")); + public static final Model TILE_SANDSTONE_WALL = new ModelTile(Resources.ATLAS.get("/tile/sandstone_wall.png")); + public static final Model TILE_GRASS_INFESTED = new ModelTile(Resources.ATLAS.get("/tile/grass_infested.png")); public static final Model TILE_SAND = new ModelTile(Resources.ATLAS.get("/tile/sand.png")); public static final Model TILE_STONE = new ModelTile(Resources.ATLAS.get("/tile/stone.png")); public static final Model TILE_DIRT = new ModelTile(Resources.ATLAS.get("/tile/dirt.png")); - public static final Model TILE_ROCK = new ModelVertical(Resources.ATLAS.get("/tile/rock.png")); - public static final Model TILE_SNOW_PILE = new ModelVertical(Resources.ATLAS.get("/tile/snow_pile.png")); - public static final Model TILE_ROCK_SANDSTONE = new ModelVertical(Resources.ATLAS.get("/tile/rock_sandstone.png")); + public static final Model TILE_ROCK = new ModelPlayerHead();//new ModelRock(Resources.ATLAS.get("/tile/rock.png")); + public static final Model TILE_ROCK_ICE = new ModelRock(Resources.ATLAS.get("/tile/rock_ice.png")); + public static final Model TILE_ROCK_SANDSTONE = new ModelRock(Resources.ATLAS.get("/tile/rock_sandstone.png")); public static final Model TILE_LADDER = new ModelVertical(Resources.ATLAS.get("/tile/ladder.png")); public static final Model TILE_PORTAL = new ModelTile(Resources.ATLAS.get("/tile/tunnel_down.png")); public static final Model TILE_WALL = new ModelTile(Resources.ATLAS.get("/tile/wall.png")); @@ -45,14 +76,15 @@ public class Models public static final Model ENTITY_BOSS_FIRING = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_firing.png"), new Vec2d(4, 4), 4, 50); public static final Model ENTITY_BOSS_WALKING = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_walking.png"), new Vec2d(4, 4), 4, 50); public static final Model ENTITY_BOSS_WALKING_AND_FIRING = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_walking_firing.png"), new Vec2d(4, 4), 4, 50); - public static final Model ENTITY_TNT = new ModelVertical(Resources.ATLAS.get("/entity/tnt.png")); - public static final Model ENTITY_FLARE = new ModelVertical(Resources.ATLAS.get("/entity/flare.png")); + public static final Model ENTITY_TNT = new ModelVertical(Resources.ATLAS.get("/entity/tnt.png"), new Vec2d(0.5, 0.5)); + public static final Model ENTITY_FLARE = new ModelVertical(Resources.ATLAS.get("/entity/flare.png"), new Vec2d(0.5, 0.5)); public static final Model ENTITY_DUMMY = new ModelVertical(Resources.ATLAS.get("/entity/dummy.png")); public static final Model ENTITY_GRAPPLING_HOOK = new ModelVertical(Resources.ATLAS.get("/entity/grappling_hook.png")); public static final Model PARTICLE_BLOOD = new ModelVertical(Resources.ATLAS.get("/particle/blood.png"), new Vec2d(1, 1)); + public static final Model PARTICLE_WATER = new ModelVertical(Resources.ATLAS.get("/particle/water.png"), new Vec2d(1, 1)); public static final Model PARTICLE_SMOKE_TRAIL = new ModelVertical(Resources.ATLAS.get("/particle/smoke_trail.png"), new Vec2d(1, 1)); - public static final Model PARTICLE_BULLET = new ModelVertical(Resources.ATLAS.get("/particle/bullet.png"), new Vec2d(0.1, 0.1)); + public static final ModelRandom PARTICLE_SMOKE_RANDOM = new ModelRandom( new ModelVertical(Resources.ATLAS.get("/particle/smoke_0.png")), @@ -69,34 +101,53 @@ public class Models public static final ModelGui UI_HEALTH_BG = new ModelGui(Resources.ATLAS.get("/gui/health_empty.png"), new Vec2d(6, 0.375)); public static final ModelGui UI_ITEM_SLOTS = new ModelGui(Resources.ATLAS.get("/gui/hotbar.png"), new Vec2d(15, 1.5)); public static final ModelGui UI_ACTIVE_SLOT = new ModelGui(Resources.ATLAS.get("/gui/hotbar_selected.png"), new Vec2d(1.5, 1.5)); - - public static final ModelGui UI_DEFENCE_LEVEL = new ModelGui(Resources.ATLAS.get("/gui/shield.png")); - public static final ModelGui UI_GUN_LEVEL = new ModelGui(Resources.ATLAS.get("/gui/gun.png")); + public static final ModelGui UI_INVENTORY = new ModelGui(Resources.ATLAS.get("/gui/inventory.png"), new Vec2d(12, 12)); public static final ModelGui UI_TEMPERATURE = new ModelGui(Resources.ATLAS.get("/gui/temperature.png"), new Vec2d(0.75, 0.75)); public static final ModelGui UI_WATER = new ModelGui(Resources.ATLAS.get("/gui/water.png"), new Vec2d(0.75, 0.75)); + public static final ModelGui UI_ITEM_HOVER = new ModelGui(Resources.ATLAS.get("/gui/pixel_black.png")).setOpacity(0.25); + + public static final ModelItem UI_SLOT_ARMOR_HELMET = new ModelItem(Resources.ATLAS.get("/gui/slot_armor_helmet.png")); + public static final ModelItem UI_SLOT_ARMOR_CHEST = new ModelItem(Resources.ATLAS.get("/gui/slot_armor_chest.png")); + public static final ModelItem UI_SLOT_ARMOR_LEGS = new ModelItem(Resources.ATLAS.get("/gui/slot_armor_legs.png")); + public static final ModelItem UI_SLOT_CLOTHING_SHIRT = new ModelItem(Resources.ATLAS.get("/gui/slot_clothing_shirt.png")); + public static final ModelItem UI_SLOT_CLOTHING_PANTS = new ModelItem(Resources.ATLAS.get("/gui/slot_clothing_pants.png")); + public static final ModelItem UI_SLOT_CLOTHING_BOOTS = new ModelItem(Resources.ATLAS.get("/gui/slot_clothing_boots.png")); public static final ModelItem ITEM_EMPTY = ModelItem.createEmpty(); public static final ModelItem ITEM_GRAPPLING_HOOK = new ModelItem(Resources.ATLAS.get("/item/grappling_hook.png")); public static final ModelItem ITEM_HEALTH_POTION = new ModelItem(Resources.ATLAS.get("/item/health_potion.png")); public static final ModelItem ITEM_AMMO_BOX = new ModelItem(Resources.ATLAS.get("/item/ammo_box.png")); - public static final ModelItem ITEM_GUN_UPGRADE = new ModelItem(Resources.ATLAS.get("/item/gun_upgrade.png")); - public static final ModelItem ITEM_DEFENCE_UPGRADE = new ModelItem(Resources.ATLAS.get("/item/shield_upgrade.png")); - public static final ModelItem ITEM_ROCK = new ModelItem(Resources.ATLAS.get("/tile/rock.png")); public static final ModelItem ITEM_TNT = new ModelItem(Resources.ATLAS.get("/entity/tnt.png")); public static final ModelItem ITEM_FLARE = new ModelItem(Resources.ATLAS.get("/entity/flare.png")); public static final ModelItem ITEM_LANTERN = new ModelItem(Resources.ATLAS.get("/tile/lantern.png"), 4, 5); + public static final ModelItem ITEM_SPAWN_ZOMBIE = new ModelItem(Resources.ATLAS.get("/entity/zombie_front_moving.png"), 4, 10); public static final ModelItem ITEM_SPAWN_DUMMY = new ModelItem(Resources.ATLAS.get("/entity/dummy.png")); - // Player Back White Varient - public static final Model ENTITY_PLAYER_B_W_STILL = new ModelVertical(Resources.ATLAS.get("/player/player_white_back_still.png")); - public static final Model ENTITY_PLAYER_B_W_MOVING = new ModelVertical(Resources.ATLAS.get("/player/player_white_back_moving.png"), 4, 10); - public static final Model ENTITY_PLAYER_F_W_STILL = new ModelVertical(Resources.ATLAS.get("/player/player_white_front_still.png")); - public static final Model ENTITY_PLAYER_F_W_MOVING = new ModelVertical(Resources.ATLAS.get("/player/player_white_front_moving.png"), 4, 10); - public static final Model ENTITY_PLAYER_B_B_STILL = new ModelVertical(Resources.ATLAS.get("/player/player_black_back_still.png")); - public static final Model ENTITY_PLAYER_B_B_MOVING = new ModelVertical(Resources.ATLAS.get("/player/player_black_back_moving.png"), 4, 10); - public static final Model ENTITY_PLAYER_F_B_STILL = new ModelVertical(Resources.ATLAS.get("/player/player_black_front_still.png")); - public static final Model ENTITY_PLAYER_F_B_MOVING = new ModelVertical(Resources.ATLAS.get("/player/player_blacl_front_moving.png"), 4, 10); + public static final ModelItem ITEM_ROCK = new ModelItem(Resources.ATLAS.get("/item/rock.png")); + public static final ModelItem ITEM_SNOW_PILE = new ModelItem(Resources.ATLAS.get("/item/snow_pile.png")); + public static final ModelItem ITEM_SANDSTONE = new ModelItem(Resources.ATLAS.get("/item/sandstone.png")); + public static final ModelItem ITEM_FLINT = new ModelItem(Resources.ATLAS.get("/item/flint.png")); + + public static final ModelItem ITEM_PLANT_FIBRE = new ModelItem(Resources.ATLAS.get("/item/plant_fibre.png")); + public static final ModelItem ITEM_HEMP_SEED = new ModelItem(Resources.ATLAS.get("/item/hemp_seed.png")); + public static final ModelItem ITEM_ACORN = new ModelItem(Resources.ATLAS.get("/item/acorn.png")); + public static final ModelItem ITEM_LOG = new ModelItem(Resources.ATLAS.get("/item/log.png")); + public static final ModelItem ITEM_LOG_SNOW = new ModelItem(Resources.ATLAS.get("/item/log_snow.png")); + + // Player varients + public static final ModelPlayer ENTITY_PLAYER_W = new ModelPlayer( + Resources.ATLAS.get("/player/player_white_back_still.png"), + Resources.ATLAS.get("/player/player_white_back_moving.png"), + Resources.ATLAS.get("/player/player_white_front_still.png"), + Resources.ATLAS.get("/player/player_white_front_moving.png")); + + public static final ModelPlayer ENTITY_PLAYER_B = new ModelPlayer( + Resources.ATLAS.get("/player/player_black_back_still.png"), + Resources.ATLAS.get("/player/player_black_back_moving.png"), + Resources.ATLAS.get("/player/player_black_front_still.png"), + Resources.ATLAS.get("/player/player_black_front_moving.png")); + public static final Model ENTITY_ZOMBIE_B = new ModelVertical(Resources.ATLAS.get("/entity/zombie_back_moving.png"), 4, 10); public static final Model ENTITY_ZOMBIE_F = new ModelVertical(Resources.ATLAS.get("/entity/zombie_front_moving.png"), 4, 10); diff --git a/src/projectzombie/init/Resources.java b/src/projectzombie/init/Resources.java index 47047cd..ec27f55 100755 --- a/src/projectzombie/init/Resources.java +++ b/src/projectzombie/init/Resources.java @@ -1,6 +1,7 @@ package projectzombie.init; import gl_engine.texture.TextureAtlas3D; +import gl_engine.texture.TextureRef3D; import projectzombie.resources.Resource; public class Resources @@ -10,6 +11,8 @@ public class Resources ATLAS = TextureAtlas3D.loadAll("/resources/texture/list.txt"); ATLAS.generate(); + TEX_EMPTY = ATLAS.get(""); + GUN_OGG_0.load(); GUN_OGG_1.load(); GUN_OGG_2.load(); @@ -29,6 +32,7 @@ public class Resources } public static TextureAtlas3D ATLAS; + public static TextureRef3D TEX_EMPTY; public static final Resource GUN_OGG_0 = new Resource("/sound/gun0.ogg"); public static final Resource GUN_OGG_1 = new Resource("/sound/gun1.ogg"); diff --git a/src/projectzombie/init/Tasks.java b/src/projectzombie/init/Tasks.java new file mode 100644 index 0000000..39d45fc --- /dev/null +++ b/src/projectzombie/init/Tasks.java @@ -0,0 +1,34 @@ +package projectzombie.init; + +import java.util.ArrayList; + +import bdf.types.BdfObject; +import projectzombie.entity.Entity; +import projectzombie.task.Task; +import projectzombie.task.TaskDeathScreen; +import projectzombie.task.TaskLadderDown; +import projectzombie.task.TaskLadderUp; + +public class Tasks +{ + public static final ArrayList> TASKS = new ArrayList<>(); + + private static void register(Class t) + { + try { + t.getConstructor(Entity.class, BdfObject.class); + } catch (NoSuchMethodException | SecurityException err) { + err.printStackTrace(); + System.exit(1); + } + + TASKS.add(t); + } + + public static void init() + { + register(TaskLadderDown.class); + register(TaskLadderUp.class); + register(TaskDeathScreen.class); + } +} diff --git a/src/projectzombie/init/Tiles.java b/src/projectzombie/init/Tiles.java index 0e864a6..d6c7883 100755 --- a/src/projectzombie/init/Tiles.java +++ b/src/projectzombie/init/Tiles.java @@ -8,6 +8,10 @@ import projectzombie.tiles.TileCactus; import projectzombie.tiles.TileChest; import projectzombie.tiles.TileDirt; import projectzombie.tiles.TileGrass; +import projectzombie.tiles.TileGrassInfested; +import projectzombie.tiles.TileHemp; +import projectzombie.tiles.TileIce; +import projectzombie.tiles.TileIceWall; import projectzombie.tiles.TileLadder; import projectzombie.tiles.TileLadderUp; import projectzombie.tiles.TileLantern; @@ -16,12 +20,15 @@ import projectzombie.tiles.TileLavaFlow; import projectzombie.tiles.TilePortalDown; import projectzombie.tiles.TileRock; import projectzombie.tiles.TileSand; +import projectzombie.tiles.TileSandstone; +import projectzombie.tiles.TileSandstoneWall; +import projectzombie.tiles.TileSapling; import projectzombie.tiles.TileSnow; import projectzombie.tiles.TileStone; +import projectzombie.tiles.TileTallGrass; import projectzombie.tiles.TileTree; import projectzombie.tiles.TileVoid; import projectzombie.tiles.TileWall; -import projectzombie.tiles.TileWallUnbreakable; import projectzombie.tiles.TileWater; public class Tiles @@ -59,8 +66,14 @@ public class Tiles register(LADDER_UP); register(CHEST); register(LANTERN); - register(WALL_UNBREAKABLE); register(BOSS_PORTAL); + register(ICE); + register(ICE_WALL); + register(SANDSTONE); + register(SANDSTONE_WALL); + register(GRASS_INFESTED); + register(TALL_GRASS); + register(SAPLING); } public static final Tile GRASS = new TileGrass(); @@ -81,6 +94,13 @@ public class Tiles 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(); + public static final Tile ICE = new TileIce(); + public static final Tile ICE_WALL = new TileIceWall(); + public static final Tile SANDSTONE = new TileSandstone(); + public static final Tile SANDSTONE_WALL = new TileSandstoneWall(); + public static final Tile GRASS_INFESTED = new TileGrassInfested(); + public static final Tile TALL_GRASS = new TileTallGrass(); + public static final Tile SAPLING = new TileSapling(); + public static final Tile HEMP = new TileHemp(); } diff --git a/src/projectzombie/input/CursorPosCallback.java b/src/projectzombie/input/CursorPosCallback.java index ef6f295..518b6dd 100755 --- a/src/projectzombie/input/CursorPosCallback.java +++ b/src/projectzombie/input/CursorPosCallback.java @@ -5,9 +5,12 @@ import org.lwjgl.glfw.GLFWCursorPosCallbackI; import gl_engine.vec.Vec2d; import projectzombie.Main; +import projectzombie.util.gl.GlHelpers; public class CursorPosCallback implements GLFWCursorPosCallbackI { + public static double mx, my; + @Override public void invoke(long window, double x, double y) { @@ -16,13 +19,16 @@ public class CursorPosCallback implements GLFWCursorPosCallbackI Main.window.setMouseVisibility(!Main.menu.keepMouse); InputMode.Controller = false; + int wx = Main.window.getWidth(); + int wy = Main.window.getHeight(); + + mx = (x / Main.window.getWidth() * 20 - 10) * GlHelpers.getAspectRatio(); + my = -y / Main.window.getHeight() * 20 + 10; + if(!Main.menu.keepMouse) { return; } - int wx = Main.window.getWidth(); - int wy = Main.window.getHeight(); - x = (x / wx - 0.5); y = (y / wy - 0.5); diff --git a/src/projectzombie/input/GameInput.java b/src/projectzombie/input/GameInput.java index e8954ef..5225a23 100755 --- a/src/projectzombie/input/GameInput.java +++ b/src/projectzombie/input/GameInput.java @@ -18,5 +18,7 @@ class GameInput static boolean moveRight = false; static boolean moveUp = false; static boolean moveDown = false; - static boolean fireGun = false; + + static boolean buttonL = false; + static boolean buttonR = false; } diff --git a/src/projectzombie/input/JoystickCallback.java b/src/projectzombie/input/JoystickCallback.java index 19246d7..dbc9f40 100755 --- a/src/projectzombie/input/JoystickCallback.java +++ b/src/projectzombie/input/JoystickCallback.java @@ -1,17 +1,6 @@ package projectzombie.input; -import static projectzombie.input.GameInput.activateItem_last; -import static projectzombie.input.GameInput.activateTile_last; -import static projectzombie.input.GameInput.activate_last; -import static projectzombie.input.GameInput.backButton_last; -import static projectzombie.input.GameInput.dropItem_last; -import static projectzombie.input.GameInput.fireGun; -import static projectzombie.input.GameInput.hotbar_l; -import static projectzombie.input.GameInput.hotbar_r; -import static projectzombie.input.GameInput.moveDown; -import static projectzombie.input.GameInput.moveUp; -import static projectzombie.input.GameInput.move_last; -import static projectzombie.input.GameInput.startButton_last; +import static projectzombie.input.GameInput.*; import java.nio.ByteBuffer; import java.nio.FloatBuffer; @@ -179,7 +168,7 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask } // Gun trigger - if(right_trigger > 0.3 && !fireGun) { + if(right_trigger > 0.3) { input.fire(true); InputMode.Controller = true; Main.window.setMouseVisibility(false); @@ -189,11 +178,7 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask if(left_trigger > 0.3) { InputMode.Controller = true; Main.window.setMouseVisibility(false); - if(!activateItem_last) - { - activateItem_last = true; - input.itemAction(true); - } + input.itemAction(true); } else { @@ -226,20 +211,6 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask hotbar_r = false; } - // Activate tile - if(button_x) { - InputMode.Controller = true; - Main.window.setMouseVisibility(false); - if(!activateTile_last) { - input.activateTile(true); - activateTile_last = true; - } - } - - else if(activateTile_last) { - activateTile_last = false; - } - // Activate button (A Button) if(button_a) { InputMode.Controller = true; @@ -252,6 +223,7 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask else if(activate_last) { activate_last = false; + input.activate(false); } // Drop item diff --git a/src/projectzombie/input/KeyCallback.java b/src/projectzombie/input/KeyCallback.java index 94caf20..289b433 100755 --- a/src/projectzombie/input/KeyCallback.java +++ b/src/projectzombie/input/KeyCallback.java @@ -19,13 +19,7 @@ import static org.lwjgl.glfw.GLFW.GLFW_KEY_Q; import static org.lwjgl.glfw.GLFW.GLFW_KEY_S; import static org.lwjgl.glfw.GLFW.GLFW_KEY_W; import static org.lwjgl.glfw.GLFW.GLFW_RELEASE; -import static projectzombie.input.GameInput.backButton_last; -import static projectzombie.input.GameInput.fireGun; -import static projectzombie.input.GameInput.moveDown; -import static projectzombie.input.GameInput.moveLeft; -import static projectzombie.input.GameInput.moveRight; -import static projectzombie.input.GameInput.moveUp; -import static projectzombie.input.GameInput.move_last; +import static projectzombie.input.GameInput.*; import org.lwjgl.glfw.GLFWKeyCallbackI; @@ -33,14 +27,16 @@ import gl_engine.vec.Vec2d; import mainloop.task.IMainloopTask; import projectzombie.Main; import projectzombie.input.types.Input; +import projectzombie.menu.MenuInventory; public class KeyCallback implements GLFWKeyCallbackI, IMainloopTask { private boolean itemDrop_last = false; private boolean esc_last = false; - private boolean action_last = false; private boolean fullscreen_last = false; - private boolean fireGun_last = false; + private boolean buttonL_last = false; + private boolean buttonR_last = false; + private boolean inventory_last = false; @Override public void invoke(long window, int key, int scancode, int action, int mods) @@ -97,18 +93,6 @@ public class KeyCallback implements GLFWKeyCallbackI, IMainloopTask input.hotbarGoto(true, 9); } - if(key == GLFW_KEY_E) { - if(pressed) { - if(!action_last) { - action_last = true; - input.activateTile(true); - } - } - else if(action_last) { - action_last = false; - } - } - if(key == GLFW_KEY_Q) { if(pressed) { if(!itemDrop_last) { @@ -121,6 +105,18 @@ public class KeyCallback implements GLFWKeyCallbackI, IMainloopTask } } + if(key == GLFW_KEY_E) { + if(pressed) { + if(!inventory_last) { + inventory_last = true; + } + } + else if(inventory_last) { + inventory_last = false; + input.openInventory(); + } + } + if(key == GLFW_KEY_ESCAPE) { if(pressed) { if(!esc_last) { @@ -194,15 +190,25 @@ public class KeyCallback implements GLFWKeyCallbackI, IMainloopTask input.move(true, angle); } - if(fireGun) { - fireGun_last = true; + if(buttonL) { + buttonL_last = true; input.fire(true); } - else if(fireGun_last) { - fireGun_last = false; + else if(buttonL_last) { + buttonL_last = false; input.fire(false); } + + if(buttonR) { + buttonR_last = true; + input.itemAction(true); + } + + else if(buttonR_last) { + buttonR_last = false; + input.itemAction(false); + } } } diff --git a/src/projectzombie/input/MouseButtonCallback.java b/src/projectzombie/input/MouseButtonCallback.java index 69ef006..792c6e0 100755 --- a/src/projectzombie/input/MouseButtonCallback.java +++ b/src/projectzombie/input/MouseButtonCallback.java @@ -14,12 +14,11 @@ public class MouseButtonCallback implements GLFWMouseButtonCallbackI InputMode.Controller = false; if(button == GLFW.GLFW_MOUSE_BUTTON_LEFT) { - GameInput.fireGun = action == 1; + GameInput.buttonL = action == 1; } - if(button == GLFW.GLFW_MOUSE_BUTTON_RIGHT && action == 1) { - GameInput.activateItem_last = true; - Main.menu.input.itemAction(true); + if(button == GLFW.GLFW_MOUSE_BUTTON_RIGHT) { + GameInput.buttonR = action == 1; } } diff --git a/src/projectzombie/input/types/Input.java b/src/projectzombie/input/types/Input.java index 37eee85..2b3d70a 100755 --- a/src/projectzombie/input/types/Input.java +++ b/src/projectzombie/input/types/Input.java @@ -6,7 +6,6 @@ public interface Input { public void move(boolean state, double angle); public void fire(boolean state); - public void activateTile(boolean state); public void camera(boolean state, double amount); public void itemAction(boolean state); public void itemDrop(boolean state); @@ -16,4 +15,5 @@ public interface Input public void mousePos(Vec2d pos); public void back(boolean state); public void activate(boolean state); + public void openInventory(); } diff --git a/src/projectzombie/input/types/InputGUI.java b/src/projectzombie/input/types/InputGUI.java index 40df85a..62d4f69 100755 --- a/src/projectzombie/input/types/InputGUI.java +++ b/src/projectzombie/input/types/InputGUI.java @@ -1,17 +1,20 @@ package projectzombie.input.types; import gl_engine.vec.Vec2d; +import projectzombie.Main; import projectzombie.menu.gui.GUI; +import projectzombie.util.gl.GlHelpers; public class InputGUI implements Input { private GUI gui; private boolean gunStateLast = false; + private boolean actionStateLast = false; public InputGUI(GUI gui) { this.gui = gui; } - + @Override public void move(boolean state, double angle) { this.gui.onMove(state, angle); @@ -29,14 +32,20 @@ public class InputGUI implements Input } } - @Override - public void activateTile(boolean state) {} - @Override public void camera(boolean state, double amount) {} @Override - public void itemAction(boolean state) {} + public void itemAction(boolean state) { + if(state) { + actionStateLast = true; + } + + else if(actionStateLast) { + actionStateLast = false; + gui.onRightClick(); + } + } @Override public void itemDrop(boolean state) {} @@ -51,8 +60,12 @@ public class InputGUI implements Input public void hotbarShift(boolean state, int amount) {} @Override - public void mousePos(Vec2d pos) { - this.gui.updateMousePos(pos); + public void mousePos(Vec2d pos) + { + double mx = (pos.x / Main.window.getWidth() * 20 - 10) * GlHelpers.getAspectRatio(); + double my = -pos.y / Main.window.getHeight() * 20 + 10; + + this.gui.updateMousePos(new Vec2d(mx, my)); } @Override @@ -64,5 +77,9 @@ public class InputGUI implements Input public void activate(boolean state) { gui.onActivate(); } + + @Override + public void openInventory() { + } } diff --git a/src/projectzombie/input/types/InputGame.java b/src/projectzombie/input/types/InputGame.java index f3b7a00..35181c2 100755 --- a/src/projectzombie/input/types/InputGame.java +++ b/src/projectzombie/input/types/InputGame.java @@ -4,6 +4,7 @@ import gl_engine.MathHelpers; import gl_engine.vec.Vec2d; import projectzombie.Main; import projectzombie.menu.MenuGamePause; +import projectzombie.menu.MenuInventory; import projectzombie.world.chunk.ChunkEventHandler; public class InputGame implements Input @@ -30,12 +31,7 @@ public class InputGame implements Input @Override public void fire(boolean state) { - Main.player.fireBullet(0); - } - - @Override - public void activateTile(boolean state) { - Main.player.activateTile(); + Main.player.leftClick(); } @Override @@ -45,7 +41,7 @@ public class InputGame implements Input @Override public void itemAction(boolean state) { - Main.player.activateItem(); + Main.player.rightClick(); } @Override @@ -67,7 +63,7 @@ public class InputGame implements Input @Override public void hotbarShift(boolean state, int amount) { Main.player.inventory_hand += amount; - Main.player.inventory_hand = MathHelpers.mod(Main.player.inventory_hand, Main.player.getInventory().getSlotCount()); + Main.player.inventory_hand = MathHelpers.mod(Main.player.inventory_hand, 10); } @Override @@ -81,5 +77,10 @@ public class InputGame implements Input @Override public void activate(boolean state) { } + + @Override + public void openInventory() { + Main.menu = new MenuInventory(Main.menu); + } } diff --git a/src/projectzombie/inventory/IInventory.java b/src/projectzombie/inventory/IInventory.java index 5cc9447..d7ad6e8 100755 --- a/src/projectzombie/inventory/IInventory.java +++ b/src/projectzombie/inventory/IInventory.java @@ -1,11 +1,17 @@ package projectzombie.inventory; +import projectzombie.items.Item; import projectzombie.util.math.ItemStack; public interface IInventory { - public ItemStack getItem(int slot); public int getSlotCount(); + public ItemStack getItem(int slot); + + public void addItem(ItemStack stack); public void setItem(ItemStack stack, int slot); + public ItemStack removeItem(int slot); + public void removeItem(ItemStack stack); + public void removeItem(Item item, int count); } diff --git a/src/projectzombie/inventory/IInventoryArmor.java b/src/projectzombie/inventory/IInventoryArmor.java new file mode 100644 index 0000000..cf5e23e --- /dev/null +++ b/src/projectzombie/inventory/IInventoryArmor.java @@ -0,0 +1,14 @@ +package projectzombie.inventory; + +import projectzombie.util.math.ItemStack; + +public interface IInventoryArmor +{ + public ItemStack getHelmet(); + public ItemStack getChest(); + public ItemStack getLeggings(); + + public void setHelmet(ItemStack stack); + public void setChest(ItemStack stack); + public void setLeggings(ItemStack stack); +} diff --git a/src/projectzombie/inventory/IInventoryClothing.java b/src/projectzombie/inventory/IInventoryClothing.java new file mode 100644 index 0000000..bf77782 --- /dev/null +++ b/src/projectzombie/inventory/IInventoryClothing.java @@ -0,0 +1,14 @@ +package projectzombie.inventory; + +import projectzombie.util.math.ItemStack; + +public interface IInventoryClothing +{ + public ItemStack getShirt(); + public ItemStack getPants(); + public ItemStack getBoots(); + + public void setShirt(ItemStack stack); + public void setPants(ItemStack stack); + public void setBoots(ItemStack stack); +} diff --git a/src/projectzombie/inventory/Inventory.java b/src/projectzombie/inventory/Inventory.java index d5eeae7..671972d 100755 --- a/src/projectzombie/inventory/Inventory.java +++ b/src/projectzombie/inventory/Inventory.java @@ -21,15 +21,8 @@ public class Inventory implements IInventory, IBdfClassManager } @Override - public ItemStack getItem(int slot) - { - if(items[slot].isEmpty()) { - return ItemStack.getEmpty(); - } - - else { - return items[slot]; - } + public ItemStack getItem(int slot) { + return items[slot]; } @Override diff --git a/src/projectzombie/inventory/InventoryArmor.java b/src/projectzombie/inventory/InventoryArmor.java new file mode 100644 index 0000000..09f8209 --- /dev/null +++ b/src/projectzombie/inventory/InventoryArmor.java @@ -0,0 +1,69 @@ +package projectzombie.inventory; + +import bdf.classes.IBdfClassManager; +import bdf.types.BdfNamedList; +import bdf.types.BdfObject; +import projectzombie.util.math.ItemStack; + +public class InventoryArmor implements IBdfClassManager, IInventoryArmor +{ + private ItemStack helmet, chest, leggings; + + public InventoryArmor() { + helmet = ItemStack.getEmpty(); + chest = ItemStack.getEmpty(); + leggings = ItemStack.getEmpty(); + } + + public InventoryArmor(BdfObject bdf) { + BdfClassLoad(bdf); + } + + @Override + public ItemStack getHelmet() { + return helmet; + } + + @Override + public ItemStack getChest() { + return chest; + } + + @Override + public ItemStack getLeggings() { + return leggings; + } + + @Override + public void setHelmet(ItemStack stack) { + helmet = stack; + } + + @Override + public void setChest(ItemStack stack) { + chest = stack; + } + + @Override + public void setLeggings(ItemStack stack) { + leggings = stack; + } + + @Override + public void BdfClassLoad(BdfObject bdf) { + BdfNamedList nl = bdf.getNamedList(); + helmet = new ItemStack(nl.get("helmet")); + chest = new ItemStack(nl.get("chest")); + leggings = new ItemStack(nl.get("leggings")); + } + + @Override + public void BdfClassSave(BdfObject bdf) { + BdfNamedList nl = new BdfNamedList(); + helmet.BdfClassSave(nl.get("helmet")); + chest.BdfClassSave(nl.get("chest")); + leggings.BdfClassSave(nl.get("leggings")); + bdf.setNamedList(nl); + } + +} diff --git a/src/projectzombie/inventory/InventoryClothing.java b/src/projectzombie/inventory/InventoryClothing.java new file mode 100644 index 0000000..2f92e08 --- /dev/null +++ b/src/projectzombie/inventory/InventoryClothing.java @@ -0,0 +1,68 @@ +package projectzombie.inventory; + +import bdf.classes.IBdfClassManager; +import bdf.types.BdfNamedList; +import bdf.types.BdfObject; +import projectzombie.util.math.ItemStack; + +public class InventoryClothing implements IBdfClassManager, IInventoryClothing +{ + private ItemStack shirt, pants, boots; + + public InventoryClothing() { + shirt = ItemStack.getEmpty(); + pants = ItemStack.getEmpty(); + boots = ItemStack.getEmpty(); + } + + public InventoryClothing(BdfObject bdf) { + BdfClassLoad(bdf); + } + + @Override + public ItemStack getShirt() { + return shirt; + } + + @Override + public ItemStack getPants() { + return pants; + } + + @Override + public ItemStack getBoots() { + return boots; + } + + @Override + public void setShirt(ItemStack stack) { + shirt = stack; + } + + @Override + public void setPants(ItemStack stack) { + pants = stack; + } + + @Override + public void setBoots(ItemStack stack) { + boots = stack; + } + + @Override + public void BdfClassLoad(BdfObject bdf) { + BdfNamedList nl = bdf.getNamedList(); + shirt = new ItemStack(nl.get("shirt")); + pants = new ItemStack(nl.get("pants")); + boots = new ItemStack(nl.get("boots")); + } + + @Override + public void BdfClassSave(BdfObject bdf) { + BdfNamedList nl = new BdfNamedList(); + shirt.BdfClassSave(nl.get("shirt")); + pants.BdfClassSave(nl.get("pants")); + boots.BdfClassSave(nl.get("boots")); + bdf.setNamedList(nl); + } +} diff --git a/src/projectzombie/items/Item.java b/src/projectzombie/items/Item.java index 52452e7..5111662 100755 --- a/src/projectzombie/items/Item.java +++ b/src/projectzombie/items/Item.java @@ -1,8 +1,9 @@ package projectzombie.items; import projectzombie.entity.Entity; -import projectzombie.entity.EntityInventory; +import projectzombie.entity.EntityHasInventory; import projectzombie.entity.player.EntityPlayer; +import projectzombie.inventory.IInventory; import projectzombie.inventory.Inventory; import projectzombie.model.ModelItem; import projectzombie.util.math.ItemStack; @@ -14,8 +15,12 @@ public abstract class Item public int id; public int max = 99; - public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) { - stack.count -= 1; + public boolean onPlayerLeftClick(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) { + return false; + } + + public boolean onPlayerRightClick(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) { + return false; } public String getName(short meta) { @@ -34,10 +39,10 @@ public abstract class Item if(stack.isEmpty()) return; // Does the entity have an inventory - if(entity instanceof EntityInventory) + if(entity instanceof EntityHasInventory) { // Get the entities inventory - Inventory entity_i = ((EntityInventory) entity).getInventory(); + IInventory entity_i = ((EntityHasInventory) entity).getInventory(); // Add the item to the entities inventory entity_i.addItem(stack); diff --git a/src/projectzombie/items/ItemAcorn.java b/src/projectzombie/items/ItemAcorn.java new file mode 100644 index 0000000..326c875 --- /dev/null +++ b/src/projectzombie/items/ItemAcorn.java @@ -0,0 +1,41 @@ +package projectzombie.items; + +import gl_engine.vec.Vec2i; +import projectzombie.entity.player.EntityPlayer; +import projectzombie.init.Models; +import projectzombie.init.Tiles; +import projectzombie.model.ModelItem; +import projectzombie.tiles.Tile; +import projectzombie.util.math.ItemStack; +import projectzombie.world.chunk.Chunk; +import projectzombie.world.layer.Layer; + +public class ItemAcorn extends Item +{ + + @Override + public ModelItem getModel(short meta) { + return Models.ITEM_ACORN; + } + + @Override + public String getName(short meta) { + return "Acorn"; + } + + @Override + public boolean onPlayerRightClick(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) { + + Vec2i tpos = player.getPos().xz().toInt(); + Tile bt = chunk.getBackTile(tpos).tile; + + if((bt == Tiles.GRASS || bt == Tiles.SNOW) && chunk.getFrontTile(tpos).tile == Tiles.VOID) { + chunk.setFrontTile(Tiles.SAPLING.getDefaultState(), tpos); + stack.count -= 1; + return true; + } + + return false; + } + +} diff --git a/src/projectzombie/items/ItemAmmo.java b/src/projectzombie/items/ItemAmmo.java index c3297e9..142f287 100755 --- a/src/projectzombie/items/ItemAmmo.java +++ b/src/projectzombie/items/ItemAmmo.java @@ -1,7 +1,11 @@ package projectzombie.items; +import projectzombie.entity.player.EntityPlayer; import projectzombie.init.Models; import projectzombie.model.ModelItem; +import projectzombie.util.math.ItemStack; +import projectzombie.world.chunk.Chunk; +import projectzombie.world.layer.Layer; public class ItemAmmo extends Item { diff --git a/src/projectzombie/items/ItemArmor.java b/src/projectzombie/items/ItemArmor.java new file mode 100644 index 0000000..bcb6526 --- /dev/null +++ b/src/projectzombie/items/ItemArmor.java @@ -0,0 +1,10 @@ +package projectzombie.items; + +import projectzombie.util.math.ItemStack; + +public interface ItemArmor +{ + public boolean isHelmet(ItemStack stack); + public boolean isChestplate(ItemStack stack); + public boolean isLeggings(ItemStack stack); +} diff --git a/src/projectzombie/items/ItemClothing.java b/src/projectzombie/items/ItemClothing.java new file mode 100644 index 0000000..e95d4b6 --- /dev/null +++ b/src/projectzombie/items/ItemClothing.java @@ -0,0 +1,10 @@ +package projectzombie.items; + +import projectzombie.util.math.ItemStack; + +public interface ItemClothing +{ + public boolean isShirt(ItemStack stack); + public boolean isPants(ItemStack stack); + public boolean isBoots(ItemStack stack); +} diff --git a/src/projectzombie/items/ItemDefenceUpgrade.java b/src/projectzombie/items/ItemDefenceUpgrade.java deleted file mode 100755 index 64f977e..0000000 --- a/src/projectzombie/items/ItemDefenceUpgrade.java +++ /dev/null @@ -1,36 +0,0 @@ -package projectzombie.items; - -import projectzombie.Main; -import projectzombie.entity.player.EntityPlayer; -import projectzombie.init.Models; -import projectzombie.model.ModelItem; -import projectzombie.util.math.ItemStack; -import projectzombie.world.chunk.Chunk; -import projectzombie.world.layer.Layer; - -public class ItemDefenceUpgrade extends Item -{ - public ItemDefenceUpgrade() { - this.max = 1; - } - - @Override - public ModelItem getModel(short meta) { - return Models.ITEM_DEFENCE_UPGRADE; - } - - @Override - public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) - { - if(Main.player.defence_level < stack.meta) { - super.onPlayerAction(stack, layer, chunk, player); - Main.player.defence_level = stack.meta; - } - } - - @Override - public String getName(short meta) { - return "Defence Upgrade level "+meta; - } - -} diff --git a/src/projectzombie/items/ItemEmpty.java b/src/projectzombie/items/ItemEmpty.java index 6fa2c31..75f1384 100755 --- a/src/projectzombie/items/ItemEmpty.java +++ b/src/projectzombie/items/ItemEmpty.java @@ -14,10 +14,6 @@ public class ItemEmpty extends Item public ItemEmpty() { } - @Override - public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) { - } - @Override public void onPickedUp(ItemStack stack, Layer layer, Chunk chunk, Entity entity) { } diff --git a/src/projectzombie/items/ItemFlare.java b/src/projectzombie/items/ItemFlare.java index 6a5265c..d352010 100755 --- a/src/projectzombie/items/ItemFlare.java +++ b/src/projectzombie/items/ItemFlare.java @@ -17,9 +17,10 @@ public class ItemFlare extends Item } @Override - public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) { - super.onPlayerAction(stack, layer, chunk, player); + public boolean onPlayerRightClick(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) { layer.spawnEntity(new EntityFlare(player.getPos(), player.getVelocity(), player.angle)); + stack.count -= 1; + return true; } @Override diff --git a/src/projectzombie/items/ItemFlint.java b/src/projectzombie/items/ItemFlint.java new file mode 100644 index 0000000..82aba11 --- /dev/null +++ b/src/projectzombie/items/ItemFlint.java @@ -0,0 +1,20 @@ +package projectzombie.items; + +import projectzombie.init.Models; +import projectzombie.model.ModelItem; +import projectzombie.util.math.ItemStack; + +public class ItemFlint extends Item +{ + + @Override + public ModelItem getModel(short meta) { + return Models.ITEM_FLINT; + } + + @Override + public String getName(short meta) { + return "Flint"; + } + +} diff --git a/src/projectzombie/items/ItemGrapplingHook.java b/src/projectzombie/items/ItemGrapplingHook.java index 7e5aa9c..5fd0b92 100755 --- a/src/projectzombie/items/ItemGrapplingHook.java +++ b/src/projectzombie/items/ItemGrapplingHook.java @@ -1,8 +1,5 @@ package projectzombie.items; -import gl_engine.MathHelpers; -import gl_engine.vec.Vec2d; -import gl_engine.vec.Vec3d; import projectzombie.entity.EntityGrapplingHook; import projectzombie.entity.player.EntityPlayer; import projectzombie.init.Models; @@ -25,10 +22,10 @@ public class ItemGrapplingHook extends Item } @Override - public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) { - super.onPlayerAction(stack, layer, chunk, player); - + public boolean onPlayerRightClick(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) { layer.spawnEntity(new EntityGrapplingHook(player.getPos(), stack.meta, player)); + stack.count -= 1; + return true; } } diff --git a/src/projectzombie/items/ItemGunUpgrade.java b/src/projectzombie/items/ItemGunUpgrade.java deleted file mode 100755 index ccec474..0000000 --- a/src/projectzombie/items/ItemGunUpgrade.java +++ /dev/null @@ -1,36 +0,0 @@ -package projectzombie.items; - -import projectzombie.Main; -import projectzombie.entity.player.EntityPlayer; -import projectzombie.init.Models; -import projectzombie.model.ModelItem; -import projectzombie.util.math.ItemStack; -import projectzombie.world.chunk.Chunk; -import projectzombie.world.layer.Layer; - -public class ItemGunUpgrade extends Item -{ - public ItemGunUpgrade() { - this.max = 1; - } - - @Override - public ModelItem getModel(short meta) { - return Models.ITEM_GUN_UPGRADE; - } - - @Override - public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) - { - if(Main.player.gun_level < stack.meta) { - super.onPlayerAction(stack, layer, chunk, player); - Main.player.gun_level = stack.meta; - } - } - - @Override - public String getName(short meta) { - return "Gun Upgrade level "+meta; - } - -} diff --git a/src/projectzombie/items/ItemHealthPotion.java b/src/projectzombie/items/ItemHealthPotion.java index 89597c5..82e360e 100755 --- a/src/projectzombie/items/ItemHealthPotion.java +++ b/src/projectzombie/items/ItemHealthPotion.java @@ -21,10 +21,9 @@ public class ItemHealthPotion extends Item } @Override - public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) { - super.onPlayerAction(stack, layer, chunk, player); - - // Heal the player + public boolean onPlayerRightClick(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) { player.addHealth(stack.meta); + stack.count -= 1; + return true; } } diff --git a/src/projectzombie/items/ItemHempSeed.java b/src/projectzombie/items/ItemHempSeed.java new file mode 100644 index 0000000..80f916d --- /dev/null +++ b/src/projectzombie/items/ItemHempSeed.java @@ -0,0 +1,39 @@ +package projectzombie.items; + +import gl_engine.vec.Vec2i; +import projectzombie.entity.player.EntityPlayer; +import projectzombie.init.Models; +import projectzombie.init.Tiles; +import projectzombie.model.ModelItem; +import projectzombie.util.math.ItemStack; +import projectzombie.world.chunk.Chunk; +import projectzombie.world.layer.Layer; + +public class ItemHempSeed extends Item +{ + + @Override + public ModelItem getModel(short meta) { + return Models.ITEM_HEMP_SEED; + } + + @Override + public String getName(short meta) { + return "Hemp Seed"; + } + + @Override + public boolean onPlayerRightClick(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) { + + Vec2i tpos = player.getPos().xz().toInt(); + + if(chunk.getBackTile(tpos).tile == Tiles.GRASS && chunk.getFrontTile(tpos).tile == Tiles.VOID) { + chunk.setFrontTile(Tiles.HEMP.getDefaultState(), tpos); + stack.count -= 1; + return true; + } + + return false; + } + +} diff --git a/src/projectzombie/items/ItemInfestation.java b/src/projectzombie/items/ItemInfestation.java new file mode 100644 index 0000000..6530ded --- /dev/null +++ b/src/projectzombie/items/ItemInfestation.java @@ -0,0 +1,26 @@ +package projectzombie.items; + +import projectzombie.entity.player.EntityPlayer; +import projectzombie.init.Models; +import projectzombie.init.Tiles; +import projectzombie.model.ModelItem; +import projectzombie.util.math.ItemStack; +import projectzombie.world.chunk.Chunk; +import projectzombie.world.layer.Layer; + +public class ItemInfestation extends Item +{ + + @Override + public ModelItem getModel(short meta) { + return Models.ITEM_ROCK; + } + + @Override + public boolean onPlayerRightClick(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) { + chunk.setBackTile(Tiles.GRASS_INFESTED.getDefaultState(), player.getPos().xz().toInt()); + stack.count -= 1; + return true; + } + +} diff --git a/src/projectzombie/items/ItemLantern.java b/src/projectzombie/items/ItemLantern.java index aea299e..304588c 100755 --- a/src/projectzombie/items/ItemLantern.java +++ b/src/projectzombie/items/ItemLantern.java @@ -24,13 +24,16 @@ public class ItemLantern extends Item } @Override - public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) + public boolean onPlayerRightClick(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) { Vec2i tpos = new Vec2i(MathHelpers.floor(player.getPos().x), MathHelpers.floor(player.getPos().z)); if(layer.getFrontTile(tpos).tile == Tiles.VOID) { layer.setFrontTile(Tiles.LANTERN.getDefaultState(), tpos); - super.onPlayerAction(stack, layer, chunk, player); + stack.count -= 1; + return true; } + + return false; } @Override diff --git a/src/projectzombie/items/ItemLog.java b/src/projectzombie/items/ItemLog.java new file mode 100644 index 0000000..bd420b4 --- /dev/null +++ b/src/projectzombie/items/ItemLog.java @@ -0,0 +1,24 @@ +package projectzombie.items; + +import projectzombie.init.Models; +import projectzombie.model.ModelItem; + +public class ItemLog extends Item +{ + + @Override + public ModelItem getModel(short meta) + { + switch(meta) + { + case 1: return Models.ITEM_LOG_SNOW; + default: return Models.ITEM_LOG; + } + } + + @Override + public String getName(short meta) { + return "Log"; + } + +} diff --git a/src/projectzombie/items/ItemPlantFibre.java b/src/projectzombie/items/ItemPlantFibre.java new file mode 100644 index 0000000..2886ced --- /dev/null +++ b/src/projectzombie/items/ItemPlantFibre.java @@ -0,0 +1,17 @@ +package projectzombie.items; + +import projectzombie.init.Models; +import projectzombie.model.ModelItem; + +public class ItemPlantFibre extends Item +{ + @Override + public ModelItem getModel(short meta) { + return Models.ITEM_PLANT_FIBRE; + } + + @Override + public String getName(short meta) { + return "Plant Fibre"; + } +} diff --git a/src/projectzombie/items/ItemRock.java b/src/projectzombie/items/ItemRock.java index 3acc59b..c9d6d92 100755 --- a/src/projectzombie/items/ItemRock.java +++ b/src/projectzombie/items/ItemRock.java @@ -7,12 +7,17 @@ import projectzombie.util.math.ItemStack; import projectzombie.world.chunk.Chunk; import projectzombie.world.layer.Layer; -public class ItemRock extends Item +public class ItemRock extends Item implements ItemTool { @Override - public ModelItem getModel(short meta) { - return Models.ITEM_ROCK; + public ModelItem getModel(short meta) + { + switch(meta) { + case 1: return Models.ITEM_SNOW_PILE; + case 2: return Models.ITEM_SANDSTONE; + default: return Models.ITEM_ROCK; + } } @Override @@ -21,8 +26,40 @@ public class ItemRock extends Item } @Override - public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) { - //super.onAction(stack, layer, chunk, entity); + public void toolOnUse(ItemStack stack) { + + if(stack.meta == 1) { + return; + } + + stack.count -= 1; } + @Override + public int toolPowerAxe(ItemStack stack) + { + if(stack.meta == 1) { + return 0; + } + + return 1; + } + + @Override + public int toolPowerPickaxe(ItemStack stack) { + return 0; + } + + @Override + public int toolPowerShovel(ItemStack stack) { + return 0; + } + + @Override + public int toolSpeed(ItemStack stack) { + return 1; + } + + + } diff --git a/src/projectzombie/items/ItemSpawn.java b/src/projectzombie/items/ItemSpawn.java index 489b565..ea1990f 100755 --- a/src/projectzombie/items/ItemSpawn.java +++ b/src/projectzombie/items/ItemSpawn.java @@ -1,6 +1,5 @@ package projectzombie.items; -import gl_engine.vec.Vec2d; import gl_engine.vec.Vec3d; import projectzombie.entity.player.EntityPlayer; import projectzombie.util.math.ItemStack; @@ -10,10 +9,10 @@ import projectzombie.world.layer.Layer; public abstract class ItemSpawn extends Item { @Override - public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) { - super.onPlayerAction(stack, layer, chunk, player); - + public boolean onPlayerRightClick(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) { this.spawnEntity(layer, chunk, player.getPos(), player.getVelocity()); + stack.count -= 1; + return true; } public void spawnEntity(Layer layer, Chunk chunk, Vec3d pos, Vec3d velocity) { diff --git a/src/projectzombie/items/ItemTnt.java b/src/projectzombie/items/ItemTnt.java index a0bfa2f..14bd972 100755 --- a/src/projectzombie/items/ItemTnt.java +++ b/src/projectzombie/items/ItemTnt.java @@ -21,10 +21,10 @@ public class ItemTnt extends Item } @Override - public void onPlayerAction(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) { - super.onPlayerAction(stack, layer, chunk, player); - + public boolean onPlayerRightClick(ItemStack stack, Layer layer, Chunk chunk, EntityPlayer player) { layer.spawnEntity(new EntityTnt(player.getPos(), player.getVelocity(), player.angle, stack.meta, 5000)); + stack.count -= 1; + return true; } } diff --git a/src/projectzombie/items/ItemTool.java b/src/projectzombie/items/ItemTool.java new file mode 100644 index 0000000..23b4c7e --- /dev/null +++ b/src/projectzombie/items/ItemTool.java @@ -0,0 +1,12 @@ +package projectzombie.items; + +import projectzombie.util.math.ItemStack; + +public interface ItemTool +{ + public int toolPowerAxe(ItemStack stack); + public int toolPowerPickaxe(ItemStack stack); + public int toolPowerShovel(ItemStack stack); + public int toolSpeed(ItemStack stack); + public void toolOnUse(ItemStack stack); +} diff --git a/src/projectzombie/items/spawner/ItemSpawnDummy.java b/src/projectzombie/items/spawner/ItemSpawnDummy.java index f8a3455..d19b28e 100644 --- a/src/projectzombie/items/spawner/ItemSpawnDummy.java +++ b/src/projectzombie/items/spawner/ItemSpawnDummy.java @@ -1,6 +1,5 @@ package projectzombie.items.spawner; -import gl_engine.vec.Vec2d; import gl_engine.vec.Vec3d; import projectzombie.entity.EntityDummy; import projectzombie.init.Models; diff --git a/src/projectzombie/items/spawner/ItemSpawnZombie.java b/src/projectzombie/items/spawner/ItemSpawnZombie.java index ec94e19..9f08018 100755 --- a/src/projectzombie/items/spawner/ItemSpawnZombie.java +++ b/src/projectzombie/items/spawner/ItemSpawnZombie.java @@ -1,6 +1,5 @@ package projectzombie.items.spawner; -import gl_engine.vec.Vec2d; import gl_engine.vec.Vec3d; import projectzombie.entity.EntityZombie; import projectzombie.init.Models; diff --git a/src/projectzombie/menu/MenuDeath.java b/src/projectzombie/menu/MenuDeath.java index ce3d852..f404951 100755 --- a/src/projectzombie/menu/MenuDeath.java +++ b/src/projectzombie/menu/MenuDeath.java @@ -2,7 +2,7 @@ package projectzombie.menu; import projectzombie.Main; import projectzombie.input.types.InputGUI; -import projectzombie.menu.gui.ButtonGroup; +import projectzombie.menu.gui.GUIButtonGroup; import projectzombie.menu.gui.GUI; import projectzombie.menu.gui.components.ButtonBasic; import projectzombie.menu.gui.components.ButtonGroupPause; @@ -22,7 +22,7 @@ public class MenuDeath extends Menu gui.add(new OverlayBackground()); - ButtonGroup group = new ButtonGroupPause(); + GUIButtonGroup group = new ButtonGroupPause(); group.add(new ButtonBasic("Quit", button -> { Main.menu = new MenuMain(); diff --git a/src/projectzombie/menu/MenuGamePause.java b/src/projectzombie/menu/MenuGamePause.java index 5654634..253fc42 100755 --- a/src/projectzombie/menu/MenuGamePause.java +++ b/src/projectzombie/menu/MenuGamePause.java @@ -6,7 +6,7 @@ import java.util.zip.DeflaterOutputStream; import bdf.types.BdfObject; import projectzombie.Main; import projectzombie.input.types.InputGUI; -import projectzombie.menu.gui.ButtonGroup; +import projectzombie.menu.gui.GUIButtonGroup; import projectzombie.menu.gui.GUI; import projectzombie.menu.gui.components.ButtonBasic; import projectzombie.menu.gui.components.ButtonGroupPause; @@ -29,7 +29,7 @@ public class MenuGamePause extends Menu gui.add(new OverlayBackground()); gui.add(new LabelPause("Game Paused")); - ButtonGroup group = new ButtonGroupPause(); + GUIButtonGroup group = new ButtonGroupPause(); group.add(new ButtonBasic("Save And Exit", button -> { saveAndQuit(); diff --git a/src/projectzombie/menu/MenuInventory.java b/src/projectzombie/menu/MenuInventory.java new file mode 100644 index 0000000..638358b --- /dev/null +++ b/src/projectzombie/menu/MenuInventory.java @@ -0,0 +1,244 @@ +package projectzombie.menu; + +import gl_engine.MathHelpers; +import gl_engine.matrix.Matrix4; +import gl_engine.vec.Vec2d; +import gl_engine.vec.Vec3d; +import projectzombie.Main; +import projectzombie.display.Camera; +import projectzombie.init.Items; +import projectzombie.init.Models; +import projectzombie.input.CursorPosCallback; +import projectzombie.input.types.InputGUI; +import projectzombie.inventory.Inventory; +import projectzombie.inventory.InventoryArmor; +import projectzombie.inventory.InventoryClothing; +import projectzombie.items.ItemArmor; +import projectzombie.items.ItemClothing; +import projectzombie.menu.gui.GUIButton; +import projectzombie.menu.gui.GUIItemHolder; +import projectzombie.menu.gui.GUIItemSlot; +import projectzombie.menu.gui.GUIItemSlotGetter; +import projectzombie.menu.gui.GUIItemSlotGetterStorage; +import projectzombie.menu.gui.GUI; +import projectzombie.menu.gui.components.GUIBackToMenu; +import projectzombie.model.Model; +import projectzombie.util.gl.GlHelpers; +import projectzombie.util.math.ItemStack; + +public class MenuInventory extends Menu +{ + private Menu parent; + private GUI gui; + + private GUIItemSlot[] item_slots; + private GUIItemSlot[] armor_slots; + + public MenuInventory(Menu parent) + { + this.parent = parent; + + doGameloop = parent.doGameloop; + doGameRender = parent.doGameRender; + playerEmitsLight = parent.playerEmitsLight; + showIngameGUI = parent.showIngameGUI; + + keepMouse = false; + + gui = new GUIBackToMenu(parent); + input = new InputGUI(gui); + + Inventory inventory = Main.player.getInventory(); + GUIItemHolder itemHolder = new GUIItemHolder(); + + item_slots = new GUIItemSlot[42]; + armor_slots = new GUIItemSlot[6]; + + { + double offset = Models.UI_ITEM_SLOTS.getWidth() / 10; + + double inv_w = Models.UI_INVENTORY.getWidth(); + double inv_h = Models.UI_INVENTORY.getHeight(); + + for(int i=0;i<10;i++) + { + GUIItemSlot slot = new GUIItemSlot(itemHolder, 1, false, new GUIItemSlotGetterStorage(inventory, i)); + + slot.setPos(new Vec2d((i - 5) * offset + 0.325, 0.65 / 2 - 9.5)); + + gui.add(slot); + item_slots[i] = slot; + } + + for(int i=10;i<42;i++) + { + int row = (i - 10) / 4; + int col = (i - 10) % 4; + + GUIItemSlot slot = new GUIItemSlot(itemHolder, 1.5, true, new GUIItemSlotGetterStorage(inventory, i)); + + slot.setPos(new Vec2d(col * offset - inv_w + 0.325, -row * offset + inv_h / 2 - 1.175)); + + gui.add(slot); + item_slots[i] = slot; + } + + InventoryArmor armor = Main.player.getInventoryArmor(); + InventoryClothing clothing = Main.player.getInventoryClothing(); + + double[] positions = new double[] { + 156, 76, + 156, 42, + 156, 8, + 196, 76, + 196, 42, + 196, 8, + }; + + ItemStack[] armor_item_slots = new ItemStack[] { + armor.getHelmet(), armor.getChest(), armor.getLeggings(), + clothing.getShirt(), clothing.getPants(), clothing.getBoots(), + }; + + for(int i=0;i<6;i++) + { + int[] id = {i}; + + GUIItemSlot slot = new GUIItemSlot(itemHolder, 1.5, true, new GUIItemSlotGetter() { + + @Override + public void setItemStack(ItemStack stack) { + armor_item_slots[id[0]] = stack; + } + + @Override + public boolean isAllowed(ItemStack stack) + { + if(id[0] < 3) + { + if(stack.item instanceof ItemArmor) + { + ItemArmor ia = (ItemArmor) stack.item; + + switch(id[0]) + { + case 0: return ia.isHelmet(stack); + case 1: return ia.isChestplate(stack); + case 2: return ia.isLeggings(stack); + } + } + } + + else + { + if(stack.item instanceof ItemClothing) + { + ItemClothing ic = (ItemClothing) stack.item; + + switch(id[0]) + { + case 3: return ic.isShirt(stack); + case 4: return ic.isPants(stack); + case 5: return ic.isBoots(stack); + } + } + } + + return false; + } + + @Override + public ItemStack getItemStack() { + return armor_item_slots[id[0]]; + } + }); + + switch(i) + { + case 0: + slot.setModelEmpty(Models.UI_SLOT_ARMOR_HELMET); + break; + case 1: + slot.setModelEmpty(Models.UI_SLOT_ARMOR_CHEST); + break; + case 2: + slot.setModelEmpty(Models.UI_SLOT_ARMOR_LEGS); + break; + case 3: + slot.setModelEmpty(Models.UI_SLOT_CLOTHING_SHIRT); + break; + case 4: + slot.setModelEmpty(Models.UI_SLOT_CLOTHING_PANTS); + break; + case 5: + slot.setModelEmpty(Models.UI_SLOT_CLOTHING_BOOTS); + break; + } + + slot.setPos(new Vec2d( + inv_w * (positions[i*2] / 256) - inv_w + 0.325, + inv_h * (positions[i*2+1] / 256) - inv_h / 2 + 0.325)); + + //slot.setItemStack(new ItemStack(Items.ACORN, 3, (short)0)); + + armor_slots[i] = slot; + gui.add(slot); + } + } + + + + gui.add(itemHolder); + } + + @Override + public void render() + { + parent.render(); + + double width = Models.UI_INVENTORY.getWidth(); + double height = Models.UI_INVENTORY.getHeight(); + + Matrix4 matrix = Matrix4.translate(-width, -height / 2, 0); + + // Render the inventory gui + Models.UI_INVENTORY.setModel(matrix); + Models.UI_INVENTORY.render(); + + { + // Render the player in the gui + Model player_model = Main.player.MODEL.model_gui; + + double px = width * (160 / 256.0); + double py = height * (128 / 256.0); + + Matrix4 player_matrix = Matrix4.multiply(matrix, Matrix4.translate(px, py, 0)); + + player_matrix = Matrix4.multiply(Matrix4.scale(new Vec3d(3, 3, 3)), player_matrix); + + player_model.setModel(player_matrix); + player_model.render(); + } + + /*// Get the angles between the player character and the mouse + double ax = Math.toDegrees(MathHelpers.atan2(-CursorPosCallback.mx - px / 20, 3.2)); + double ay = Math.toDegrees(MathHelpers.atan2(-CursorPosCallback.my - py / 20, 3.2)); + + player_matrix = Matrix4.multiply(Matrix4.scale(new Vec3d(6, 6, 6)), player_matrix); + player_matrix = Matrix4.multiply(Matrix4.projection(1, 90, 1, 50), player_matrix); + player_matrix = Matrix4.multiply(Matrix4.translate(0, 0, -2), player_matrix); + player_matrix = Matrix4.multiply(Matrix4.rotate(ax, 0, 1, 0), player_matrix); + player_matrix = Matrix4.multiply(Matrix4.rotate(ay, 1, 0, 0), player_matrix); + player_matrix = Matrix4.multiply(Matrix4.translate(-width * (10.8 / 256.0), -height * (10.8 / 256.0), 0), player_matrix);*/ + + gui.render(); + } + + @Override + public void update() { + super.update(); + + gui.update(new Vec2d(CursorPosCallback.mx, CursorPosCallback.my)); + } + +} diff --git a/src/projectzombie/menu/MenuMain.java b/src/projectzombie/menu/MenuMain.java index 95a03b6..ee02466 100755 --- a/src/projectzombie/menu/MenuMain.java +++ b/src/projectzombie/menu/MenuMain.java @@ -3,7 +3,7 @@ package projectzombie.menu; import gl_engine.vec.Vec3d; import projectzombie.Main; import projectzombie.input.types.InputGUI; -import projectzombie.menu.gui.ButtonGroup; +import projectzombie.menu.gui.GUIButtonGroup; import projectzombie.menu.gui.GUI; import projectzombie.menu.gui.components.ButtonBasic; import projectzombie.menu.gui.components.LabelMain; @@ -24,7 +24,7 @@ public class MenuMain extends Menu gui.add(new LabelMain()); - ButtonGroup group = new ButtonGroup(); + GUIButtonGroup group = new GUIButtonGroup(); group.add(new ButtonBasic("Play", button -> { Main.respawn(); diff --git a/src/projectzombie/menu/MenuSettings.java b/src/projectzombie/menu/MenuSettings.java index 9c856d1..7fd5c23 100755 --- a/src/projectzombie/menu/MenuSettings.java +++ b/src/projectzombie/menu/MenuSettings.java @@ -5,11 +5,11 @@ 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; +import projectzombie.menu.gui.GUIButton; +import projectzombie.menu.gui.GUIButtonGroup; import projectzombie.menu.gui.GUI; import projectzombie.menu.gui.GUISelectableDirection; -import projectzombie.menu.gui.Label; +import projectzombie.menu.gui.GUILabel; import projectzombie.menu.gui.components.ButtonBasic; import projectzombie.menu.gui.components.ButtonSetting; import projectzombie.menu.gui.components.GUIBackToMenu; @@ -22,10 +22,6 @@ public class MenuSettings extends Menu private GUI gui; private Menu menuOld; - private String qualitySettingToString(boolean status) { - return status ? "On" : "Off"; - } - public MenuSettings(Menu menuOld) { this.menuOld = menuOld; @@ -36,7 +32,7 @@ public class MenuSettings extends Menu playerEmitsLight = menuOld.playerEmitsLight; keepMouse = false; - ButtonGroup group = new ButtonGroup(); + GUIButtonGroup group = new GUIButtonGroup(); group.setPos(new Vec2d(-1, 4)); group.add(new ButtonSetting("FPS: " + (DisplayRenderUI.showFPS ? "On" : "Off"), button -> { @@ -45,27 +41,20 @@ public class MenuSettings extends Menu Settings.update(); })); - group.add(new ButtonSetting("Pos Indicator: " + (DisplayRenderUI.showPos ? "On" : "Off"), + group.add(new ButtonSetting("Debug mode: " + (DisplayRenderUI.debug ? "On" : "Off"), button -> { - DisplayRenderUI.showPos = !DisplayRenderUI.showPos; - button.setText("Pos Indicator: " + (DisplayRenderUI.showPos ? "On" : "Off")); + DisplayRenderUI.debug = !DisplayRenderUI.debug; + button.setText("Debug mode: " + (DisplayRenderUI.debug ? "On" : "Off")); Settings.update(); })); - group.add(new ButtonSetting("Render Distance: "+Chunk.RENDER_DISTANCE, button -> { + group.add(new ButtonSetting("Render distance: "+Chunk.RENDER_DISTANCE, button -> { Chunk.RENDER_DISTANCE += 1; if(Chunk.RENDER_DISTANCE > 8) { Chunk.RENDER_DISTANCE = 2; } - button.setText("Render Distance: "+Chunk.RENDER_DISTANCE); - Settings.update(); - })); - - group.add(new ButtonSetting("Particles: " + qualitySettingToString(!EntityParticle.DISABLED), button -> - { - EntityParticle.DISABLED = !EntityParticle.DISABLED; - button.setText("Particles: " + qualitySettingToString(!EntityParticle.DISABLED)); + button.setText("Render distance: "+Chunk.RENDER_DISTANCE); Settings.update(); })); @@ -91,13 +80,13 @@ public class MenuSettings extends Menu gui.add(group); - Label labelSettings = new Label(); + GUILabel labelSettings = new GUILabel(); labelSettings.setText("Settings"); labelSettings.setSize(new Vec2d(1, 1)); labelSettings.setPos(new Vec2d(0, 6.8)); gui.add(labelSettings); - Button buttonBack = new ButtonBasic("Back", new Vec2d(0, -8), button -> { + GUIButton buttonBack = new ButtonBasic("Back", new Vec2d(0, -8), button -> { Main.menu = menuOld; }); diff --git a/src/projectzombie/menu/gui/GUI.java b/src/projectzombie/menu/gui/GUI.java index 80dc515..c7e0d10 100755 --- a/src/projectzombie/menu/gui/GUI.java +++ b/src/projectzombie/menu/gui/GUI.java @@ -103,10 +103,23 @@ public class GUI implements GUIContainer } } + @Override + public void onRightClick(Vec2d pos) { + for(GUIComponent c : components) { + if(c.checkMouseHover(mousePos)) { + c.onRightClick(mousePos); + } + } + } + public void onMouseClick() { this.onMouseClick(mousePos); } + public void onRightClick() { + this.onRightClick(mousePos); + } + @Override public void onBack() { for(GUIComponent c : components) { @@ -120,5 +133,12 @@ public class GUI implements GUIContainer c.onActivate(); } } + + @Override + public void update(Vec2d mousePos) { + for(GUIComponent c : components) { + c.update(mousePos); + } + } } diff --git a/src/projectzombie/menu/gui/Alignment.java b/src/projectzombie/menu/gui/GUIAlignment.java similarity index 67% rename from src/projectzombie/menu/gui/Alignment.java rename to src/projectzombie/menu/gui/GUIAlignment.java index ca4a71c..8f9f9f9 100755 --- a/src/projectzombie/menu/gui/Alignment.java +++ b/src/projectzombie/menu/gui/GUIAlignment.java @@ -1,5 +1,5 @@ package projectzombie.menu.gui; -public enum Alignment { +public enum GUIAlignment { LEFT, CENTRE, RIGHT } diff --git a/src/projectzombie/menu/gui/Button.java b/src/projectzombie/menu/gui/GUIButton.java similarity index 86% rename from src/projectzombie/menu/gui/Button.java rename to src/projectzombie/menu/gui/GUIButton.java index 0aa6315..318220a 100755 --- a/src/projectzombie/menu/gui/Button.java +++ b/src/projectzombie/menu/gui/GUIButton.java @@ -10,11 +10,11 @@ import projectzombie.model.ModelGui; import projectzombie.text.Text; import projectzombie.util.gl.GlHelpers; -public class Button implements GUIComponent, GUISelectable +public class GUIButton implements GUIComponent, GUISelectable { private Vec2d pos = new Vec2d(0, 0); private String text = ""; - private Alignment alignment = Alignment.CENTRE; + private GUIAlignment alignment = GUIAlignment.CENTRE; private Matrix4 matrix, matrix_text; private boolean selected = false; @@ -46,10 +46,10 @@ public class Button implements GUIComponent, GUISelectable matrix_text = Matrix4.multiply(Matrix4.scale(new Vec3d(0.5, 0.5, 0.5)), matrix_text); } - public Button() + public GUIButton() { this.text = ""; - this.alignment = Alignment.CENTRE; + this.alignment = GUIAlignment.CENTRE; this.dirty = true; } @@ -63,7 +63,7 @@ public class Button implements GUIComponent, GUISelectable this.dirty = true; } - public void setAlign(Alignment alignment) { + public void setAlign(GUIAlignment alignment) { this.alignment = alignment; this.dirty = true; } @@ -100,13 +100,10 @@ public class Button implements GUIComponent, GUISelectable double offset = getOffset(); - double mx = (pos.x / Main.window.getWidth() * 20 - 10) * GlHelpers.getAspectRatio(); - double my = -pos.y / Main.window.getHeight() * 20 + 10; - ModelGui model = Models.UI_BUTTON; - return (mx > this.pos.x - offset && mx < this.pos.x + model.getWidth() - offset && - my > this.pos.y && my < this.pos.y + model.getHeight()); + return (pos.x > this.pos.x - offset && pos.x < this.pos.x + model.getWidth() - offset && + pos.y > this.pos.y && pos.y < this.pos.y + model.getHeight()); } @Override @@ -167,4 +164,13 @@ public class Button implements GUIComponent, GUISelectable this.onMouseClick(new Vec2d(0, 0)); } } + + @Override + public void update(Vec2d mousePos) { + } + + @Override + public void onRightClick(Vec2d pos) { + + } } diff --git a/src/projectzombie/menu/gui/ButtonGroup.java b/src/projectzombie/menu/gui/GUIButtonGroup.java similarity index 64% rename from src/projectzombie/menu/gui/ButtonGroup.java rename to src/projectzombie/menu/gui/GUIButtonGroup.java index 5bd5136..4416623 100755 --- a/src/projectzombie/menu/gui/ButtonGroup.java +++ b/src/projectzombie/menu/gui/GUIButtonGroup.java @@ -4,16 +4,16 @@ import java.util.ArrayList; import gl_engine.vec.Vec2d; -public class ButtonGroup implements GUIContainer +public class GUIButtonGroup implements GUIContainer { - private ArrayList