diff --git a/src/shootergame/entity/Entity.java b/src/shootergame/entity/Entity.java index 4d4433a..acd4b4e 100644 --- a/src/shootergame/entity/Entity.java +++ b/src/shootergame/entity/Entity.java @@ -17,6 +17,8 @@ public class Entity implements ITransparentObject public Vec2d pos; public double angle; public boolean opaqueTile = true; + public double hitbox = 1; + public boolean isSolid = false; public Entity(Vec2d pos, double angle) { diff --git a/src/shootergame/entity/EntityAlive.java b/src/shootergame/entity/EntityAlive.java new file mode 100644 index 0000000..e05fea3 --- /dev/null +++ b/src/shootergame/entity/EntityAlive.java @@ -0,0 +1,12 @@ +package shootergame.entity; + +public interface EntityAlive +{ + public void addHealth(double amount); + public void removeHealth(double amount); + public double getHealth(); + public void resetHealth(); + public void clearHealth(); + public double maxHealth(); + public void setHealth(double health); +} diff --git a/src/shootergame/entity/EntityBlood.java b/src/shootergame/entity/EntityBlood.java new file mode 100644 index 0000000..f2f5ef6 --- /dev/null +++ b/src/shootergame/entity/EntityBlood.java @@ -0,0 +1,68 @@ +package shootergame.entity; + +import java.util.Random; + +import shootergame.display.Camera; +import shootergame.util.gl.GlHelpers; +import shootergame.util.math.random.RandomHelpers; +import shootergame.util.math.vec.Vec2d; +import shootergame.world.chunk.Chunk; +import shootergame.world.layer.Layer; + +public class EntityBlood extends EntityParticle +{ + private double r_color; + private double speed = 0.1; + private double time = 1000; + private double height = 0; + private double height_velocity = 0; + + public EntityBlood(Random rand, Vec2d pos, double angle) { + super(rand.nextDouble() / 5, 0); + + this.pos = pos; + this.angle = angle + RandomHelpers.randrange(rand, -100, 100); + this.speed = rand.nextDouble() / 10; + this.height = rand.nextDouble(); + this.height_velocity = rand.nextDouble() / 10; + this.pos.x += 0.5; + this.pos.y += 0.5; + r_color = RandomHelpers.randrange(rand, 200, 800) / 1000.0; + } + + @Override + public void tick(Chunk chunk, Layer layer) + { + // Call super + super.tick(chunk, layer); + + // Move in the velocity and remove some of it + moveBackward(speed); + height += height_velocity; + speed /= 1.05; + height_velocity -= 0.001; + if(height < 0) { + height = 0; + height_velocity = 0; + } + + // Remove some time + time -= 1; + + // Should this particle too old; destroy it + if(time < 0) chunk.killEntity(this); + } + + @Override + public void render(Vec2d pos, Camera camera) + { + // Set some settings + GlHelpers.pushMatrix(); + GlHelpers.color3(r_color, 0, 0); + GlHelpers.translate(0, 0, height); + + // Call super + super.render(pos, camera); + GlHelpers.popMatrix(); + } +} diff --git a/src/shootergame/entity/EntityBullet.java b/src/shootergame/entity/EntityBullet.java index 63db052..b4fafbd 100644 --- a/src/shootergame/entity/EntityBullet.java +++ b/src/shootergame/entity/EntityBullet.java @@ -1,20 +1,28 @@ package shootergame.entity; +import java.util.Random; + import shootergame.display.Camera; -import shootergame.init.Textures; import shootergame.util.gl.GlHelpers; +import shootergame.util.math.random.RandomHelpers; import shootergame.util.math.vec.Vec2d; import shootergame.world.chunk.Chunk; import shootergame.world.layer.Layer; -public class EntityBullet extends Entity +public class EntityBullet extends EntityParticle { private int time = 0; + private Random rand; + private Entity parent; - public EntityBullet() - { - // Set some settings - this.opaqueTile = false; + public EntityBullet(Random rand, Vec2d pos, Entity parent, double angle) { + super(0.2, 0.4); + + // Store some specified values + this.rand = rand; + this.pos = pos; + this.angle = angle; + this.parent = parent; } @Override @@ -27,11 +35,21 @@ public class EntityBullet extends Entity // Loop over the nearby entities for(Entity e : layer.getNearbyEntities(pos, 0.5)) { - // Is this a zombie - if(e instanceof EntityZombie) + // Is this entity alive and not the parent + if(e instanceof EntityAlive && e != parent) { - //System.out.println("Found Zombie"); + // Get the alive entity + EntityAlive ea = (EntityAlive)e; + // Spawn some blood particles + for(int i=0;i<20;i++) { + chunk.spawnEntity(new EntityBlood(rand, pos.copy(), angle)); + } + + // Harm the entity + ea.removeHealth(10); + + // Kill the bullet chunk.killEntity(this); return; } @@ -48,36 +66,10 @@ public class EntityBullet extends Entity @Override public void render(Vec2d pos, Camera camera) { + // Set the colour + GlHelpers.color3(0.6, 0.6, 0); + // Call super super.render(pos, camera); - - // Push the matrix, disable textures, colour, and translate the bullet - GlHelpers.pushMatrix(); - GlHelpers.color3(0.8, 0.8, 0); - GlHelpers.disableTexture2d(); - - // Get the angle between the camera and the bullet - double angle_r = camera.angle.x; - - // Make the bullet upright - GlHelpers.translate(0.1, 0, 0); - GlHelpers.translate(pos.x, pos.y, 0.4); - GlHelpers.rotate(-angle_r, 0, 0, 1); - GlHelpers.translate(-0.1, 0, 0); - - // Draw the bullet - GlHelpers.begin(); - { - GlHelpers.vertex3(0.0f, 0, 0.0f); - GlHelpers.vertex3(0.2f, 0, 0.0f); - GlHelpers.vertex3(0.2f, 0, 0.2f); - GlHelpers.vertex3(0.0f, 0, 0.2f); - } - GlHelpers.end(); - - // Pop the matrix, remove the colour, and enable textures - GlHelpers.enableTexture2d(); - GlHelpers.color3(1, 1, 1); - GlHelpers.popMatrix(); } } diff --git a/src/shootergame/entity/EntityParticle.java b/src/shootergame/entity/EntityParticle.java new file mode 100644 index 0000000..3c6941c --- /dev/null +++ b/src/shootergame/entity/EntityParticle.java @@ -0,0 +1,54 @@ +package shootergame.entity; + +import shootergame.display.Camera; +import shootergame.util.gl.GlHelpers; +import shootergame.util.math.vec.Vec2d; + +public class EntityParticle extends Entity +{ + private double height; + private double size; + + public EntityParticle(double size, double height) + { + // Set some settings + this.opaqueTile = false; + this.height = height; + this.size = size; + } + + @Override + public void render(Vec2d pos, Camera camera) + { + // Call super + super.render(pos, camera); + + // Push the matrix, disable textures, colour, and translate the bullet + GlHelpers.pushMatrix(); + GlHelpers.disableTexture2d(); + + // Get the angle between the camera and the bullet + double angle_r = camera.angle.x; + + // Make the bullet upright + GlHelpers.translate(size/2, 0, 0); + GlHelpers.translate(pos.x, pos.y, height); + GlHelpers.rotate(-angle_r, 0, 0, 1); + GlHelpers.translate(-size/2, 0, 0); + + // Draw the bullet + GlHelpers.begin(); + { + GlHelpers.vertex3(0.0f, 0, 0.0f); + GlHelpers.vertex3(size, 0, 0.0f); + GlHelpers.vertex3(size, 0, size); + GlHelpers.vertex3(0.0f, 0, size); + } + GlHelpers.end(); + + // Pop the matrix, remove the colour, and enable textures + GlHelpers.enableTexture2d(); + GlHelpers.color3(1, 1, 1); + GlHelpers.popMatrix(); + } +} diff --git a/src/shootergame/entity/EntityZombie.java b/src/shootergame/entity/EntityZombie.java index 2aca487..a85fd40 100644 --- a/src/shootergame/entity/EntityZombie.java +++ b/src/shootergame/entity/EntityZombie.java @@ -3,24 +3,28 @@ package shootergame.entity; import java.util.Random; import shootergame.Main; -import shootergame.display.Camera; import shootergame.init.Textures; import shootergame.util.math.random.OpenSimplexNoise; -import shootergame.util.math.vec.Vec2d; import shootergame.world.chunk.Chunk; import shootergame.world.layer.Layer; -public class EntityZombie extends EntityVertical +public class EntityZombie extends EntityVertical implements EntityAlive { private Random rand; private OpenSimplexNoise noise; private double time; + private double health_max = 100; + private double health = health_max; public EntityZombie() { super(Textures.ENTITY_ZOMBIE, 1); rand = new Random(); noise = new OpenSimplexNoise(rand.nextLong()); time = 0; + + // Set some settings + hitbox = 0.5; + isSolid = true; } @Override @@ -35,5 +39,40 @@ public class EntityZombie extends EntityVertical this.moveForward(0.05); } + + @Override + public void addHealth(double amount) { + health += amount; + } + + @Override + public void removeHealth(double amount) { + health -= amount; + } + + @Override + public double getHealth() { + return health; + } + + @Override + public void resetHealth() { + health = health_max; + } + + @Override + public void clearHealth() { + health = 0; + } + + @Override + public double maxHealth() { + return health_max; + } + + @Override + public void setHealth(double health) { + this.health = health; + } } diff --git a/src/shootergame/entity/player/EntityPlayer.java b/src/shootergame/entity/player/EntityPlayer.java index 136b56b..2c3b183 100644 --- a/src/shootergame/entity/player/EntityPlayer.java +++ b/src/shootergame/entity/player/EntityPlayer.java @@ -1,8 +1,11 @@ package shootergame.entity.player; +import java.util.Random; + import shootergame.Main; import shootergame.display.Camera; import shootergame.entity.Entity; +import shootergame.entity.EntityAlive; import shootergame.entity.EntityBullet; import shootergame.entity.EntityVertical; import shootergame.init.Textures; @@ -13,7 +16,7 @@ import shootergame.util.math.vec.Vec2i; import shootergame.world.chunk.Chunk; import shootergame.world.layer.Layer; -public class EntityPlayer extends EntityVertical +public class EntityPlayer extends EntityVertical implements EntityAlive { public boolean MOVE_FORWARD = false; public boolean MOVE_BACKWARD = false; @@ -22,9 +25,17 @@ public class EntityPlayer extends EntityVertical public boolean moving = false; private int bullet_frequency = 0; + private Random rand; + private double health_max = 100; + private double health = health_max; public EntityPlayer() { this.angle = 45; + rand = new Random(); + + // Set some settings + hitbox = 0.5; + isSolid = true; } @Override @@ -75,10 +86,42 @@ public class EntityPlayer extends EntityVertical if(bullet_frequency == 0) { // Summon bullets at this angle relative to the player - Entity bullet = new EntityBullet(); - bullet.angle = angle + this.angle; - bullet.pos = pos.copy(); - Main.world.getLayer().spawnEntity(bullet); + Main.world.getLayer().spawnEntity(new EntityBullet(rand, pos.copy(), this, angle + this.angle)); } } + + @Override + public void addHealth(double amount) { + health += amount; + } + + @Override + public void removeHealth(double amount) { + health -= amount; + } + + @Override + public double getHealth() { + return health; + } + + @Override + public void resetHealth() { + health = health_max; + } + + @Override + public void clearHealth() { + health = 0; + } + + @Override + public double maxHealth() { + return health_max; + } + + @Override + public void setHealth(double health) { + this.health = health; + } } diff --git a/src/shootergame/world/chunk/Chunk.java b/src/shootergame/world/chunk/Chunk.java index 3a1b386..04fc1fa 100644 --- a/src/shootergame/world/chunk/Chunk.java +++ b/src/shootergame/world/chunk/Chunk.java @@ -5,6 +5,7 @@ import java.util.Random; import shootergame.display.Camera; import shootergame.entity.Entity; +import shootergame.entity.EntityAlive; import shootergame.init.Tiles; import shootergame.tiles.Tile; import shootergame.util.math.MathHelpers; @@ -78,7 +79,7 @@ public class Chunk } } - public void moveEntities() + public void checkEntities() { // Loop over every entity for(int i=0;i e : chunks) { - e.o.moveEntities(); + e.o.checkEntities(); } } diff --git a/src/shootergame/world/layer/layergen/LayerGenEarth.java b/src/shootergame/world/layer/layergen/LayerGenEarth.java index 561dfcd..39f2ceb 100644 --- a/src/shootergame/world/layer/layergen/LayerGenEarth.java +++ b/src/shootergame/world/layer/layergen/LayerGenEarth.java @@ -36,11 +36,6 @@ public class LayerGenEarth extends LayerGen int cx = x + c_pos.x * Chunk.CHUNK_SIZE.mx; int cy = y + c_pos.y * Chunk.CHUNK_SIZE.my; - Entity e = new EntityBullet(); - e.pos.x = cx; - e.pos.y = cy; - layer.spawnEntity(e); - // Get the noise value and the position vector double noise_n = (noisegen_n.eval(cx/10.0, cy/10.0) + 1) * 50; Vec2i pos = new Vec2i(x, y);