Added health, zombies can die, and more blood and gore.
This commit is contained in:
parent
d0e89a0aa2
commit
a107afd05d
|
|
@ -17,6 +17,8 @@ public class Entity implements ITransparentObject
|
||||||
public Vec2d pos;
|
public Vec2d pos;
|
||||||
public double angle;
|
public double angle;
|
||||||
public boolean opaqueTile = true;
|
public boolean opaqueTile = true;
|
||||||
|
public double hitbox = 1;
|
||||||
|
public boolean isSolid = false;
|
||||||
|
|
||||||
public Entity(Vec2d pos, double angle)
|
public Entity(Vec2d pos, double angle)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,20 +1,28 @@
|
||||||
package shootergame.entity;
|
package shootergame.entity;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
import shootergame.display.Camera;
|
import shootergame.display.Camera;
|
||||||
import shootergame.init.Textures;
|
|
||||||
import shootergame.util.gl.GlHelpers;
|
import shootergame.util.gl.GlHelpers;
|
||||||
|
import shootergame.util.math.random.RandomHelpers;
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
import shootergame.world.chunk.Chunk;
|
import shootergame.world.chunk.Chunk;
|
||||||
import shootergame.world.layer.Layer;
|
import shootergame.world.layer.Layer;
|
||||||
|
|
||||||
public class EntityBullet extends Entity
|
public class EntityBullet extends EntityParticle
|
||||||
{
|
{
|
||||||
private int time = 0;
|
private int time = 0;
|
||||||
|
private Random rand;
|
||||||
|
private Entity parent;
|
||||||
|
|
||||||
public EntityBullet()
|
public EntityBullet(Random rand, Vec2d pos, Entity parent, double angle) {
|
||||||
{
|
super(0.2, 0.4);
|
||||||
// Set some settings
|
|
||||||
this.opaqueTile = false;
|
// Store some specified values
|
||||||
|
this.rand = rand;
|
||||||
|
this.pos = pos;
|
||||||
|
this.angle = angle;
|
||||||
|
this.parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -27,11 +35,21 @@ public class EntityBullet extends Entity
|
||||||
// Loop over the nearby entities
|
// Loop over the nearby entities
|
||||||
for(Entity e : layer.getNearbyEntities(pos, 0.5))
|
for(Entity e : layer.getNearbyEntities(pos, 0.5))
|
||||||
{
|
{
|
||||||
// Is this a zombie
|
// Is this entity alive and not the parent
|
||||||
if(e instanceof EntityZombie)
|
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);
|
chunk.killEntity(this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -48,36 +66,10 @@ public class EntityBullet extends Entity
|
||||||
@Override
|
@Override
|
||||||
public void render(Vec2d pos, Camera camera)
|
public void render(Vec2d pos, Camera camera)
|
||||||
{
|
{
|
||||||
|
// Set the colour
|
||||||
|
GlHelpers.color3(0.6, 0.6, 0);
|
||||||
|
|
||||||
// Call super
|
// Call super
|
||||||
super.render(pos, camera);
|
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,24 +3,28 @@ package shootergame.entity;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import shootergame.Main;
|
import shootergame.Main;
|
||||||
import shootergame.display.Camera;
|
|
||||||
import shootergame.init.Textures;
|
import shootergame.init.Textures;
|
||||||
import shootergame.util.math.random.OpenSimplexNoise;
|
import shootergame.util.math.random.OpenSimplexNoise;
|
||||||
import shootergame.util.math.vec.Vec2d;
|
|
||||||
import shootergame.world.chunk.Chunk;
|
import shootergame.world.chunk.Chunk;
|
||||||
import shootergame.world.layer.Layer;
|
import shootergame.world.layer.Layer;
|
||||||
|
|
||||||
public class EntityZombie extends EntityVertical
|
public class EntityZombie extends EntityVertical implements EntityAlive
|
||||||
{
|
{
|
||||||
private Random rand;
|
private Random rand;
|
||||||
private OpenSimplexNoise noise;
|
private OpenSimplexNoise noise;
|
||||||
private double time;
|
private double time;
|
||||||
|
private double health_max = 100;
|
||||||
|
private double health = health_max;
|
||||||
|
|
||||||
public EntityZombie() {
|
public EntityZombie() {
|
||||||
super(Textures.ENTITY_ZOMBIE, 1);
|
super(Textures.ENTITY_ZOMBIE, 1);
|
||||||
rand = new Random();
|
rand = new Random();
|
||||||
noise = new OpenSimplexNoise(rand.nextLong());
|
noise = new OpenSimplexNoise(rand.nextLong());
|
||||||
time = 0;
|
time = 0;
|
||||||
|
|
||||||
|
// Set some settings
|
||||||
|
hitbox = 0.5;
|
||||||
|
isSolid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -36,4 +40,39 @@ public class EntityZombie extends EntityVertical
|
||||||
this.moveForward(0.05);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,11 @@
|
||||||
package shootergame.entity.player;
|
package shootergame.entity.player;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
import shootergame.Main;
|
import shootergame.Main;
|
||||||
import shootergame.display.Camera;
|
import shootergame.display.Camera;
|
||||||
import shootergame.entity.Entity;
|
import shootergame.entity.Entity;
|
||||||
|
import shootergame.entity.EntityAlive;
|
||||||
import shootergame.entity.EntityBullet;
|
import shootergame.entity.EntityBullet;
|
||||||
import shootergame.entity.EntityVertical;
|
import shootergame.entity.EntityVertical;
|
||||||
import shootergame.init.Textures;
|
import shootergame.init.Textures;
|
||||||
|
|
@ -13,7 +16,7 @@ import shootergame.util.math.vec.Vec2i;
|
||||||
import shootergame.world.chunk.Chunk;
|
import shootergame.world.chunk.Chunk;
|
||||||
import shootergame.world.layer.Layer;
|
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_FORWARD = false;
|
||||||
public boolean MOVE_BACKWARD = false;
|
public boolean MOVE_BACKWARD = false;
|
||||||
|
|
@ -22,9 +25,17 @@ public class EntityPlayer extends EntityVertical
|
||||||
public boolean moving = false;
|
public boolean moving = false;
|
||||||
|
|
||||||
private int bullet_frequency = 0;
|
private int bullet_frequency = 0;
|
||||||
|
private Random rand;
|
||||||
|
private double health_max = 100;
|
||||||
|
private double health = health_max;
|
||||||
|
|
||||||
public EntityPlayer() {
|
public EntityPlayer() {
|
||||||
this.angle = 45;
|
this.angle = 45;
|
||||||
|
rand = new Random();
|
||||||
|
|
||||||
|
// Set some settings
|
||||||
|
hitbox = 0.5;
|
||||||
|
isSolid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -75,10 +86,42 @@ public class EntityPlayer extends EntityVertical
|
||||||
if(bullet_frequency == 0)
|
if(bullet_frequency == 0)
|
||||||
{
|
{
|
||||||
// Summon bullets at this angle relative to the player
|
// Summon bullets at this angle relative to the player
|
||||||
Entity bullet = new EntityBullet();
|
Main.world.getLayer().spawnEntity(new EntityBullet(rand, pos.copy(), this, angle + this.angle));
|
||||||
bullet.angle = angle + this.angle;
|
|
||||||
bullet.pos = pos.copy();
|
|
||||||
Main.world.getLayer().spawnEntity(bullet);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import java.util.Random;
|
||||||
|
|
||||||
import shootergame.display.Camera;
|
import shootergame.display.Camera;
|
||||||
import shootergame.entity.Entity;
|
import shootergame.entity.Entity;
|
||||||
|
import shootergame.entity.EntityAlive;
|
||||||
import shootergame.init.Tiles;
|
import shootergame.init.Tiles;
|
||||||
import shootergame.tiles.Tile;
|
import shootergame.tiles.Tile;
|
||||||
import shootergame.util.math.MathHelpers;
|
import shootergame.util.math.MathHelpers;
|
||||||
|
|
@ -78,7 +79,7 @@ public class Chunk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void moveEntities()
|
public void checkEntities()
|
||||||
{
|
{
|
||||||
// Loop over every entity
|
// Loop over every entity
|
||||||
for(int i=0;i<entities.size();i++)
|
for(int i=0;i<entities.size();i++)
|
||||||
|
|
@ -86,6 +87,19 @@ public class Chunk
|
||||||
// Get the entitiy
|
// Get the entitiy
|
||||||
Entity e = entities.get(i);
|
Entity e = entities.get(i);
|
||||||
|
|
||||||
|
// is this entity alive
|
||||||
|
if(e instanceof EntityAlive)
|
||||||
|
{
|
||||||
|
// Get the alive entity
|
||||||
|
EntityAlive ea = (EntityAlive)e;
|
||||||
|
|
||||||
|
// Kill the entity if it should be dead and continue to the next loop iteration
|
||||||
|
if(ea.getHealth() < 0) {
|
||||||
|
entities.remove(i);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Has the entity left the chunk
|
// Has the entity left the chunk
|
||||||
int cx = c_pos.x * CHUNK_SIZE.mx;
|
int cx = c_pos.x * CHUNK_SIZE.mx;
|
||||||
int cy = c_pos.y * CHUNK_SIZE.my;
|
int cy = c_pos.y * CHUNK_SIZE.my;
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ public class Layer
|
||||||
|
|
||||||
// Move every entitiy in every loaded chunk
|
// Move every entitiy in every loaded chunk
|
||||||
for(Map2DElement<Chunk> e : chunks) {
|
for(Map2DElement<Chunk> e : chunks) {
|
||||||
e.o.moveEntities();
|
e.o.checkEntities();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,11 +36,6 @@ public class LayerGenEarth extends LayerGen
|
||||||
int cx = x + c_pos.x * Chunk.CHUNK_SIZE.mx;
|
int cx = x + c_pos.x * Chunk.CHUNK_SIZE.mx;
|
||||||
int cy = y + c_pos.y * Chunk.CHUNK_SIZE.my;
|
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
|
// Get the noise value and the position vector
|
||||||
double noise_n = (noisegen_n.eval(cx/10.0, cy/10.0) + 1) * 50;
|
double noise_n = (noisegen_n.eval(cx/10.0, cy/10.0) + 1) * 50;
|
||||||
Vec2i pos = new Vec2i(x, y);
|
Vec2i pos = new Vec2i(x, y);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue