Fixed button collision detection
|
|
@ -76,7 +76,7 @@ public class DisplayWindow implements IMainloopTask
|
||||||
width = w.get()*4;
|
width = w.get()*4;
|
||||||
height = h.get()*4;
|
height = h.get()*4;
|
||||||
|
|
||||||
//GLFW.glfwWindowHint(GLFW.GLFW_DOUBLEBUFFER, GLFW.GLFW_FALSE);
|
GLFW.glfwWindowHint(GLFW.GLFW_DOUBLEBUFFER, GLFW.GLFW_FALSE);
|
||||||
|
|
||||||
// Create the window
|
// Create the window
|
||||||
window = GraphicsHelpers.initWindow("Project Zombie", width, height, monitor);
|
window = GraphicsHelpers.initWindow("Project Zombie", width, height, monitor);
|
||||||
|
|
|
||||||
|
|
@ -32,10 +32,10 @@ public class TileLighting implements IMainloopTask
|
||||||
cx + MathHelpers.floor(player.pos.x / 16),
|
cx + MathHelpers.floor(player.pos.x / 16),
|
||||||
cy + MathHelpers.floor(player.pos.y / 16));
|
cy + MathHelpers.floor(player.pos.y / 16));
|
||||||
Chunk chunk = layer.chunks.get(cpos);
|
Chunk chunk = layer.chunks.get(cpos);
|
||||||
/*if(chunk.light_dirty) {
|
if(chunk.isLightDirty()) {
|
||||||
chunk.light_dirty = false;
|
chunk.resetLightDirty();
|
||||||
dirty = true;
|
dirty = true;
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,9 +34,14 @@ public abstract class Entity implements IBdfClassManager
|
||||||
protected static final Random rand = new Random();
|
protected static final Random rand = new Random();
|
||||||
public boolean emitsLight = false;
|
public boolean emitsLight = false;
|
||||||
public int stepOnTileCooldown = 0;
|
public int stepOnTileCooldown = 0;
|
||||||
|
private boolean dead = false;
|
||||||
|
|
||||||
public abstract Model getModel();
|
public abstract Model getModel();
|
||||||
|
|
||||||
|
public boolean isDead() {
|
||||||
|
return dead;
|
||||||
|
}
|
||||||
|
|
||||||
protected double getTilesLightDissipation() {
|
protected double getTilesLightDissipation() {
|
||||||
if(chunk == null) return 0;
|
if(chunk == null) return 0;
|
||||||
TileState tsf = chunk.getFrontTile(pos.toInt());
|
TileState tsf = chunk.getFrontTile(pos.toInt());
|
||||||
|
|
@ -219,6 +224,7 @@ public abstract class Entity implements IBdfClassManager
|
||||||
|
|
||||||
public void kill() {
|
public void kill() {
|
||||||
chunk.killEntity(this);
|
chunk.killEntity(this);
|
||||||
|
dead = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void activateTile()
|
public void activateTile()
|
||||||
|
|
|
||||||
|
|
@ -155,9 +155,7 @@ public class EntityBullet extends EntityParticle
|
||||||
|
|
||||||
// Spawn some blood particles
|
// Spawn some blood particles
|
||||||
if(!EntityParticle.DISABLED) {
|
if(!EntityParticle.DISABLED) {
|
||||||
for(int i=0;i<ea.bloodParticles();i++) {
|
chunk.spawnEntity(ParticleBlood.createBloodParticles(pos, ea.bloodParticles()));
|
||||||
chunk.spawnEntity(new ParticleBlood(rand, pos.copy(), angle));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Play the hit noise
|
// Play the hit noise
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,99 @@
|
||||||
|
package projectzombie.entity;
|
||||||
|
|
||||||
|
import bdf.classes.IBdfClassManager;
|
||||||
|
import bdf.types.BdfArray;
|
||||||
|
import bdf.types.BdfNamedList;
|
||||||
|
import bdf.types.BdfObject;
|
||||||
|
import gl_engine.vec.Vec2d;
|
||||||
|
import projectzombie.init.Models;
|
||||||
|
import projectzombie.model.Model;
|
||||||
|
import projectzombie.world.chunk.Chunk;
|
||||||
|
import projectzombie.world.layer.Layer;
|
||||||
|
|
||||||
|
public class EntityContainer extends Entity implements EntityHoldsEntities
|
||||||
|
{
|
||||||
|
private Entity[] entities;
|
||||||
|
|
||||||
|
public EntityContainer(BdfObject bdf) {
|
||||||
|
super(bdf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityContainer(Vec2d pos, Entity[] entities) {
|
||||||
|
super(pos);
|
||||||
|
|
||||||
|
this.entities = entities;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Model getModel() {
|
||||||
|
return Models.EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Entity[] getEntities() {
|
||||||
|
return this.entities;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick(Chunk chunk, Layer layer) {
|
||||||
|
super.tick(chunk, layer);
|
||||||
|
|
||||||
|
int dead = 0;
|
||||||
|
|
||||||
|
for(Entity entity : entities)
|
||||||
|
{
|
||||||
|
if(entity == null || entity.isDead()) {
|
||||||
|
dead += 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity.tick(chunk, layer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(dead == entities.length - 1) {
|
||||||
|
kill();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassLoad(BdfObject bdf) {
|
||||||
|
super.BdfClassLoad(bdf);
|
||||||
|
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
BdfArray array = nl.get("entities").getArray();
|
||||||
|
|
||||||
|
entities = new Entity[array.size()];
|
||||||
|
|
||||||
|
for(int i=0;i<entities.length;i++)
|
||||||
|
{
|
||||||
|
Entity entity = Entity.loadEntity(array.get(i));
|
||||||
|
if(entity != null) {
|
||||||
|
entities[i] = entity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassSave(BdfObject bdf) {
|
||||||
|
super.BdfClassSave(bdf);
|
||||||
|
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
BdfArray array = new BdfArray();
|
||||||
|
|
||||||
|
nl.set("entities", BdfObject.withArray(array));
|
||||||
|
|
||||||
|
for(int i=0;i<entities.length;i++)
|
||||||
|
{
|
||||||
|
Entity e = entities[i];
|
||||||
|
|
||||||
|
if(e.getID() == -1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
BdfObject e_bdf = new BdfObject();
|
||||||
|
e.BdfClassSave(e_bdf);
|
||||||
|
|
||||||
|
array.add(e_bdf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -80,6 +80,10 @@ public class EntityExplosion extends Entity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int multiplier = killed_entities ? 2 : 1;
|
||||||
|
Entity[] entities = new Entity[(int)(Math.PI * radius * radius) * multiplier];
|
||||||
|
int upto = 0;
|
||||||
|
|
||||||
// Loop over the tiles around the tnt
|
// Loop over the tiles around the tnt
|
||||||
for(int ex=-radius;ex<radius;ex++) {
|
for(int ex=-radius;ex<radius;ex++) {
|
||||||
for(int ey=-radius;ey<radius;ey++)
|
for(int ey=-radius;ey<radius;ey++)
|
||||||
|
|
@ -118,16 +122,24 @@ public class EntityExplosion extends Entity
|
||||||
l.spawnEntity(new ParticleBreak(new Vec2d(tpos.x+rand.nextDouble(), tpos.y+rand.nextDouble()), fts, 1));
|
l.spawnEntity(new ParticleBreak(new Vec2d(tpos.x+rand.nextDouble(), tpos.y+rand.nextDouble()), fts, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(upto + multiplier > entities.length) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Spawn some blood if entities were killed
|
// Spawn some blood if entities were killed
|
||||||
if(killed_entities)
|
if(killed_entities)
|
||||||
l.spawnEntity(new ParticleBlood(rand, new Vec2d(px, py), py));
|
entities[upto + 1] = new ParticleBlood(new Vec2d(px, py));
|
||||||
|
|
||||||
// Spawn some smoke
|
// Spawn some smoke
|
||||||
l.spawnEntity(new ParticleSmoke(new Vec2d(px, py)));
|
entities[upto] = new ParticleSmoke(new Vec2d(px, py));
|
||||||
|
|
||||||
|
upto += multiplier;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
layer.spawnEntity(new EntityContainer(pos, entities));
|
||||||
|
|
||||||
// Play the explosion sound
|
// Play the explosion sound
|
||||||
Sounds.EXPLOSION.play(new Vec3d(pos.x, pos.y, 0), 1);
|
Sounds.EXPLOSION.play(new Vec3d(pos.x, pos.y, 0), 1);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package projectzombie.entity;
|
||||||
|
|
||||||
import bdf.types.BdfObject;
|
import bdf.types.BdfObject;
|
||||||
import gl_engine.vec.Vec2d;
|
import gl_engine.vec.Vec2d;
|
||||||
|
import projectzombie.init.Models;
|
||||||
|
import projectzombie.model.Model;
|
||||||
import projectzombie.world.layer.Layer;
|
import projectzombie.world.layer.Layer;
|
||||||
|
|
||||||
public class EntityFlare extends EntityTnt
|
public class EntityFlare extends EntityTnt
|
||||||
|
|
@ -12,7 +14,6 @@ public class EntityFlare extends EntityTnt
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void explode(Layer layer) {
|
protected void explode(Layer layer) {
|
||||||
kill();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityFlare(Vec2d pos, double angle) {
|
public EntityFlare(Vec2d pos, double angle) {
|
||||||
|
|
@ -25,5 +26,10 @@ public class EntityFlare extends EntityTnt
|
||||||
public double getLightLevel() {
|
public double getLightLevel() {
|
||||||
return getLightWithHeight(1 - (this.pos.y * (1/12.0))) * ( rand.nextDouble() / 10.0 + 0.9 );
|
return getLightWithHeight(1 - (this.pos.y * (1/12.0))) * ( rand.nextDouble() / 10.0 + 0.9 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Model getModel() {
|
||||||
|
return active ? Models.ENTITY_FLARE : Models.EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
package projectzombie.entity;
|
||||||
|
|
||||||
|
public interface EntityHoldsEntities
|
||||||
|
{
|
||||||
|
public Entity[] getEntities();
|
||||||
|
}
|
||||||
|
|
@ -5,22 +5,42 @@ import bdf.types.BdfObject;
|
||||||
import gl_engine.MathHelpers;
|
import gl_engine.MathHelpers;
|
||||||
import gl_engine.vec.Vec2d;
|
import gl_engine.vec.Vec2d;
|
||||||
import gl_engine.vec.Vec3d;
|
import gl_engine.vec.Vec3d;
|
||||||
|
import projectzombie.entity.particle.ParticleSmoke;
|
||||||
import projectzombie.entity.particle.ParticleSpark;
|
import projectzombie.entity.particle.ParticleSpark;
|
||||||
import projectzombie.init.Models;
|
import projectzombie.init.Models;
|
||||||
import projectzombie.model.Model;
|
import projectzombie.model.Model;
|
||||||
import projectzombie.world.chunk.Chunk;
|
import projectzombie.world.chunk.Chunk;
|
||||||
import projectzombie.world.layer.Layer;
|
import projectzombie.world.layer.Layer;
|
||||||
|
|
||||||
public class EntityTnt extends Entity
|
public class EntityTnt extends Entity implements EntityHeight, EntityHoldsEntities
|
||||||
{
|
{
|
||||||
|
protected boolean active = true;
|
||||||
protected double height = 0.4;
|
protected double height = 0.4;
|
||||||
protected Vec3d velocity;
|
protected Vec3d velocity;
|
||||||
protected int explode_time;
|
protected int explode_time;
|
||||||
private int explode_radius;
|
private int explode_radius;
|
||||||
private double explode_damage;
|
private double explode_damage;
|
||||||
|
private ParticleSpark[] smoke_particles;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Entity[] getEntities() {
|
||||||
|
return smoke_particles;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getHeight() {
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHeight(double height) {
|
||||||
|
this.height = height;
|
||||||
|
}
|
||||||
|
|
||||||
public EntityTnt(BdfObject bdf) {
|
public EntityTnt(BdfObject bdf) {
|
||||||
super(bdf);
|
super(bdf);
|
||||||
|
|
||||||
|
this.smoke_particles = new ParticleSpark[50];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -60,6 +80,7 @@ public class EntityTnt extends Entity
|
||||||
this.crossUnWalkable = true;
|
this.crossUnWalkable = true;
|
||||||
this.goThroughSolid = false;
|
this.goThroughSolid = false;
|
||||||
this.explode_damage = explode_damage;
|
this.explode_damage = explode_damage;
|
||||||
|
this.smoke_particles = new ParticleSpark[100];
|
||||||
this.emitsLight = true;
|
this.emitsLight = true;
|
||||||
|
|
||||||
// Set to 2.5 seconds
|
// Set to 2.5 seconds
|
||||||
|
|
@ -68,18 +89,38 @@ public class EntityTnt extends Entity
|
||||||
|
|
||||||
protected void explode(Layer layer)
|
protected void explode(Layer layer)
|
||||||
{
|
{
|
||||||
// Create an explosion
|
|
||||||
layer.spawnEntity(new EntityExplosion(pos, explode_radius, explode_damage));
|
layer.spawnEntity(new EntityExplosion(pos, explode_radius, explode_damage));
|
||||||
|
|
||||||
// Delete the entity
|
|
||||||
kill();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick(Chunk chunk, Layer layer) {
|
public void tick(Chunk chunk, Layer layer) {
|
||||||
super.tick(chunk, layer);
|
super.tick(chunk, layer);
|
||||||
|
|
||||||
|
int dead_particle = 0;
|
||||||
|
int dead_particle_count = 0;
|
||||||
|
|
||||||
|
for(int i=0;i<smoke_particles.length;i++)
|
||||||
|
{
|
||||||
|
ParticleSpark particle = smoke_particles[i];
|
||||||
|
|
||||||
|
if(particle == null || particle.isDead()) {
|
||||||
|
dead_particle_count += 1;
|
||||||
|
dead_particle = i;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
particle.tick(chunk, layer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!active)
|
||||||
|
{
|
||||||
|
if(dead_particle_count == smoke_particles.length - 1) {
|
||||||
|
kill();
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Create a downward gravitational pull
|
// Create a downward gravitational pull
|
||||||
height += velocity.z;
|
height += velocity.z;
|
||||||
velocity.z -= 0.001;
|
velocity.z -= 0.001;
|
||||||
|
|
@ -107,11 +148,11 @@ public class EntityTnt extends Entity
|
||||||
// Explode if it is time for the tnt to blow up
|
// Explode if it is time for the tnt to blow up
|
||||||
explode_time -= 1;
|
explode_time -= 1;
|
||||||
if(explode_time < 0) {
|
if(explode_time < 0) {
|
||||||
|
active = false;
|
||||||
explode(layer);
|
explode(layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create sparks
|
smoke_particles[dead_particle] = new ParticleSpark(new Vec3d(pos, height + 1));
|
||||||
chunk.spawnEntity(new ParticleSpark(pos.copy()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -125,7 +166,7 @@ public class EntityTnt extends Entity
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Model getModel() {
|
public Model getModel() {
|
||||||
return Models.EMPTY;
|
return active ? Models.ENTITY_TNT : Models.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -216,7 +216,7 @@ public class EntityZombie extends Entity implements EntityAlive, EntityKillWithP
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int bloodParticles() {
|
public int bloodParticles() {
|
||||||
return 10;
|
return 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ public class EntityZombieArmored extends EntityZombie
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int bloodParticles() {
|
public int bloodParticles() {
|
||||||
return 2;
|
return 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ import java.util.Random;
|
||||||
import gl_engine.MathHelpers;
|
import gl_engine.MathHelpers;
|
||||||
import gl_engine.vec.Vec2d;
|
import gl_engine.vec.Vec2d;
|
||||||
import gl_engine.vec.Vec3d;
|
import gl_engine.vec.Vec3d;
|
||||||
|
import projectzombie.entity.Entity;
|
||||||
|
import projectzombie.entity.EntityContainer;
|
||||||
import projectzombie.entity.EntityHeight;
|
import projectzombie.entity.EntityHeight;
|
||||||
import projectzombie.entity.EntityParticle;
|
import projectzombie.entity.EntityParticle;
|
||||||
import projectzombie.init.Models;
|
import projectzombie.init.Models;
|
||||||
|
|
@ -15,7 +17,7 @@ import projectzombie.world.layer.Layer;
|
||||||
|
|
||||||
public class ParticleBlood extends EntityParticle implements EntityHeight
|
public class ParticleBlood extends EntityParticle implements EntityHeight
|
||||||
{
|
{
|
||||||
private double r_color;
|
private boolean done = false;
|
||||||
private double time = 1000;
|
private double time = 1000;
|
||||||
private double height = 0;
|
private double height = 0;
|
||||||
private Vec3d velocity;
|
private Vec3d velocity;
|
||||||
|
|
@ -30,17 +32,22 @@ public class ParticleBlood extends EntityParticle implements EntityHeight
|
||||||
this.height = height;
|
this.height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ParticleBlood(Random rand, Vec2d pos, double angle) {
|
public ParticleBlood(Vec2d pos) {
|
||||||
super(pos);
|
super(pos);
|
||||||
|
|
||||||
angle += RandomHelpers.randrange(rand, -100, 100);
|
|
||||||
double angle_height = RandomHelpers.randrange(rand, 9000, 18000) / 100;
|
|
||||||
this.height = rand.nextDouble();
|
|
||||||
r_color = RandomHelpers.randrange(rand, 200, 800) / 1000.0;
|
|
||||||
velocity = MathHelpers.moveTowards3(0.1,
|
|
||||||
new Vec2d(Math.toRadians(angle), Math.toRadians(angle_height)));
|
|
||||||
|
|
||||||
time = RandomHelpers.randrange(rand, 800, 1200);
|
time = RandomHelpers.randrange(rand, 800, 1200);
|
||||||
|
velocity = new Vec3d(MathHelpers.moveTowards2(0.01, rand.nextDouble() * 360), rand.nextDouble() * 0.12);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static EntityContainer createBloodParticles(Vec2d pos, int size)
|
||||||
|
{
|
||||||
|
Entity[] entities = new Entity[size];
|
||||||
|
|
||||||
|
for(int i=0;i<entities.length;i++) {
|
||||||
|
entities[i] = new ParticleBlood(pos.copy());
|
||||||
|
}
|
||||||
|
|
||||||
|
return new EntityContainer(pos.copy(), entities);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -49,26 +56,26 @@ public class ParticleBlood extends EntityParticle implements EntityHeight
|
||||||
// Call super
|
// Call super
|
||||||
super.tick(chunk, layer);
|
super.tick(chunk, layer);
|
||||||
|
|
||||||
// Move in the velocity and remove some of it
|
if(DISABLED || time < 0) {
|
||||||
pos.x += velocity.x;
|
kill();
|
||||||
pos.y += velocity.y;
|
return;
|
||||||
height += velocity.z;
|
|
||||||
velocity.x /= 1.05;
|
|
||||||
velocity.y /= 1.05;
|
|
||||||
velocity.z -= MathHelpers.FallSpeed;
|
|
||||||
if(height < 0) {
|
|
||||||
height = 0;
|
|
||||||
velocity.z = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove some time
|
// Remove some time
|
||||||
time -= 1;
|
time -= 1;
|
||||||
|
|
||||||
// Should this particle too old; destroy it
|
if(done) {
|
||||||
if(time < 0) chunk.killEntity(this);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(DISABLED) {
|
// Move in the velocity and remove some of it
|
||||||
kill();
|
pos.x += velocity.x;
|
||||||
|
pos.y += velocity.y;
|
||||||
|
height += velocity.z;
|
||||||
|
velocity.z -= MathHelpers.FallSpeed;
|
||||||
|
if(height < 0) {
|
||||||
|
velocity = new Vec3d(0, 0, 0);
|
||||||
|
height = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,44 @@
|
||||||
package projectzombie.entity.particle;
|
package projectzombie.entity.particle;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
import gl_engine.vec.Vec2d;
|
import gl_engine.vec.Vec2d;
|
||||||
|
import gl_engine.vec.Vec3d;
|
||||||
|
import projectzombie.entity.EntityHeight;
|
||||||
import projectzombie.entity.EntityParticle;
|
import projectzombie.entity.EntityParticle;
|
||||||
import projectzombie.init.Models;
|
import projectzombie.init.Models;
|
||||||
import projectzombie.model.Model;
|
import projectzombie.model.Model;
|
||||||
import projectzombie.world.chunk.Chunk;
|
import projectzombie.world.chunk.Chunk;
|
||||||
import projectzombie.world.layer.Layer;
|
import projectzombie.world.layer.Layer;
|
||||||
|
|
||||||
public class ParticleSpark extends EntityParticle
|
public class ParticleSpark extends EntityParticle implements EntityHeight
|
||||||
{
|
{
|
||||||
private double size = 0.1;
|
private int time;
|
||||||
|
private double height;
|
||||||
|
private Vec3d velocity;
|
||||||
|
|
||||||
|
private static final Random rand = new Random();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getHeight() {
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHeight(double height) {
|
||||||
|
this.height = height;
|
||||||
|
}
|
||||||
|
|
||||||
public ParticleSpark(Vec2d pos) {
|
public ParticleSpark(Vec3d pos) {
|
||||||
super(pos);
|
super(pos.xy());
|
||||||
|
|
||||||
|
velocity = new Vec3d(
|
||||||
|
rand.nextDouble() * 0.02 - 0.01,
|
||||||
|
rand.nextDouble() * 0.02 - 0.01,
|
||||||
|
rand.nextDouble() * 0.02);
|
||||||
|
|
||||||
|
height = pos.z;
|
||||||
|
time = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -20,16 +46,12 @@ public class ParticleSpark extends EntityParticle
|
||||||
super.tick(chunk, layer);
|
super.tick(chunk, layer);
|
||||||
|
|
||||||
// Reduce the size
|
// Reduce the size
|
||||||
size -= 0.004;
|
pos = pos.add(velocity.xy());
|
||||||
|
height += velocity.z;
|
||||||
|
time -= 1;
|
||||||
|
|
||||||
// Is the size zero
|
// Kill if at the end of life
|
||||||
if(size <= 0)
|
if(time <= 0 || DISABLED) {
|
||||||
{
|
|
||||||
// Destroy this particle
|
|
||||||
kill();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(DISABLED) {
|
|
||||||
kill();
|
kill();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ package projectzombie.entity.particle;
|
||||||
import gl_engine.MathHelpers;
|
import gl_engine.MathHelpers;
|
||||||
import gl_engine.vec.Vec2d;
|
import gl_engine.vec.Vec2d;
|
||||||
import gl_engine.vec.Vec3d;
|
import gl_engine.vec.Vec3d;
|
||||||
|
import projectzombie.entity.Entity;
|
||||||
|
import projectzombie.entity.EntityContainer;
|
||||||
import projectzombie.entity.EntityHeight;
|
import projectzombie.entity.EntityHeight;
|
||||||
import projectzombie.entity.EntityParticle;
|
import projectzombie.entity.EntityParticle;
|
||||||
import projectzombie.init.Models;
|
import projectzombie.init.Models;
|
||||||
|
|
@ -26,12 +28,22 @@ public class ParticleWater extends EntityParticle implements EntityHeight
|
||||||
this.height = height;
|
this.height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ParticleWater(Vec2d pos) {
|
ParticleWater(Vec2d pos) {
|
||||||
super(pos);
|
super(pos);
|
||||||
|
|
||||||
// Set the velocity
|
// Set the velocity
|
||||||
velocity = MathHelpers.moveTowards3(0.05, new Vec2d(Math.toRadians(
|
velocity = new Vec3d(MathHelpers.moveTowards2(0.04, rand.nextDouble() * 360), rand.nextDouble() * 0.04);
|
||||||
RandomHelpers.randrange(rand, 360)), Math.toRadians(RandomHelpers.randrange(rand, 0, 45))));
|
}
|
||||||
|
|
||||||
|
public static EntityContainer createWaterParticles(Vec2d pos, int amount)
|
||||||
|
{
|
||||||
|
Entity[] entities = new Entity[amount];
|
||||||
|
|
||||||
|
for(int i=0;i<amount;i++) {
|
||||||
|
entities[i] = new ParticleWater(pos.copy());
|
||||||
|
}
|
||||||
|
|
||||||
|
return new EntityContainer(pos.copy(), entities);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,9 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory
|
||||||
|
|
||||||
// Create the inventory
|
// Create the inventory
|
||||||
inventory = new Inventory(10);
|
inventory = new Inventory(10);
|
||||||
|
|
||||||
|
inventory.addItem(new ItemStack(Items.SPAWN_ZOMBIE, 99, (short)0));
|
||||||
|
inventory.addItem(new ItemStack(Items.AMMO, 999, (short)0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -314,7 +317,7 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int bloodParticles() {
|
public int bloodParticles() {
|
||||||
return 5;
|
return 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import bdf.types.BdfObject;
|
||||||
import projectzombie.entity.Entity;
|
import projectzombie.entity.Entity;
|
||||||
import projectzombie.entity.EntityBoss;
|
import projectzombie.entity.EntityBoss;
|
||||||
import projectzombie.entity.EntityBullet;
|
import projectzombie.entity.EntityBullet;
|
||||||
|
import projectzombie.entity.EntityContainer;
|
||||||
import projectzombie.entity.EntityDummy;
|
import projectzombie.entity.EntityDummy;
|
||||||
import projectzombie.entity.EntityExplosion;
|
import projectzombie.entity.EntityExplosion;
|
||||||
import projectzombie.entity.EntityFlare;
|
import projectzombie.entity.EntityFlare;
|
||||||
|
|
@ -45,5 +46,6 @@ public class Entities
|
||||||
register(EntityBullet.class);
|
register(EntityBullet.class);
|
||||||
register(EntityBoss.class);
|
register(EntityBoss.class);
|
||||||
register(EntityPlayer.class);
|
register(EntityPlayer.class);
|
||||||
|
register(EntityContainer.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ public class Models
|
||||||
public static final Model TILE_LAVA_FLOW = new ModelTile(Resources.ATLAS.get("/tile/lava_flow.png"), 16, 50);
|
public static final Model TILE_LAVA_FLOW = new ModelTile(Resources.ATLAS.get("/tile/lava_flow.png"), 16, 50);
|
||||||
public static final Model TILE_LANTERN = new ModelVertical(Resources.ATLAS.get("/tile/lantern.png"), 4, 5);
|
public static final Model TILE_LANTERN = new ModelVertical(Resources.ATLAS.get("/tile/lantern.png"), 4, 5);
|
||||||
|
|
||||||
public static final Model ENTITY_BOSS_IDLE = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_still.png"), new Vec2d(4, 4), 4, 50);
|
public static final Model ENTITY_BOSS_IDLE = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_still.png"), new Vec2d(4, 4));
|
||||||
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_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 = 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_BOSS_WALKING_AND_FIRING = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_walking_firing.png"), new Vec2d(4, 4), 4, 50);
|
||||||
|
|
@ -56,8 +56,8 @@ public class Models
|
||||||
public static final ModelGui UI_BUTTON = new ModelGui(Resources.ATLAS.get("/gui/button_normal.png"), new Vec2d(12, 1.5));
|
public static final ModelGui UI_BUTTON = new ModelGui(Resources.ATLAS.get("/gui/button_normal.png"), new Vec2d(12, 1.5));
|
||||||
public static final ModelGui UI_BUTTON_HOVER = new ModelGui(Resources.ATLAS.get("/gui/button_hover.png"), new Vec2d(12, 1.5));
|
public static final ModelGui UI_BUTTON_HOVER = new ModelGui(Resources.ATLAS.get("/gui/button_hover.png"), new Vec2d(12, 1.5));
|
||||||
|
|
||||||
public static final ModelGui UI_HEALTH_FG = new ModelGui(Resources.ATLAS.get("/gui/health_full.png"), new Vec2d(8, 0.5));
|
public static final ModelGui UI_HEALTH_FG = new ModelGui(Resources.ATLAS.get("/gui/health_full.png"), new Vec2d(6, 0.375));
|
||||||
public static final ModelGui UI_HEALTH_BG = new ModelGui(Resources.ATLAS.get("/gui/health_empty.png"), new Vec2d(8, 0.5));
|
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_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_ACTIVE_SLOT = new ModelGui(Resources.ATLAS.get("/gui/hotbar_selected.png"), new Vec2d(1.5, 1.5));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,24 +24,22 @@ public class Button implements GUIComponent, GUISelectable
|
||||||
|
|
||||||
private GUISelectable[] SELECTABLE = {null, null, null, null};
|
private GUISelectable[] SELECTABLE = {null, null, null, null};
|
||||||
|
|
||||||
private void updateMatrix()
|
private double getOffset()
|
||||||
{
|
{
|
||||||
double offset;
|
|
||||||
|
|
||||||
switch(alignment) {
|
switch(alignment) {
|
||||||
|
|
||||||
case CENTRE:
|
case CENTRE:
|
||||||
offset = Models.UI_BUTTON.getWidth() / 2;
|
return Models.UI_BUTTON.getWidth() / 2;
|
||||||
break;
|
|
||||||
case RIGHT:
|
case RIGHT:
|
||||||
offset = Models.UI_BUTTON.getWidth();
|
return Models.UI_BUTTON.getWidth();
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
offset = 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
matrix = Matrix4.translate(pos.x - offset, pos.y, 0);
|
|
||||||
|
private void updateMatrix()
|
||||||
|
{
|
||||||
|
matrix = Matrix4.translate(pos.x - getOffset(), pos.y, 0);
|
||||||
|
|
||||||
matrix_text = Matrix4.multiply(matrix, Matrix4.translate(
|
matrix_text = Matrix4.multiply(matrix, Matrix4.translate(
|
||||||
Models.UI_BUTTON.getWidth() / 2 - 0.25 * text.length(),
|
Models.UI_BUTTON.getWidth() / 2 - 0.25 * text.length(),
|
||||||
|
|
@ -102,20 +100,15 @@ public class Button implements GUIComponent, GUISelectable
|
||||||
this.dirty = false;
|
this.dirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
double mx = -pos.x / Main.window.getWidth() * 2 + 1;
|
double offset = getOffset();
|
||||||
double my = -pos.y / Main.window.getHeight() * 2 + 1;
|
|
||||||
|
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;
|
ModelGui model = Models.UI_BUTTON;
|
||||||
Matrix4 mat = Matrix4.multiply(matrix, DisplayRenderUI.projection);
|
|
||||||
Vec3d point_s = Matrix4.multiply(mat, this.pos.xyn());
|
return (mx > this.pos.x - offset && mx < this.pos.x + model.getWidth() - offset &&
|
||||||
Vec3d point_e = Matrix4.multiply(mat, new Vec3d(
|
my > this.pos.y && my < this.pos.y + model.getHeight());
|
||||||
model.getWidth() + this.pos.x,
|
|
||||||
model.getHeight() + this.pos.y, 0));
|
|
||||||
|
|
||||||
//System.out.println("mx="+mx+" my="+my+" bx="+point.x+" by="+point.y+" w="+Models.UI_BUTTON.getWidth()+" h="+Models.UI_BUTTON.getHeight());
|
|
||||||
|
|
||||||
return (mx > point_s.x && mx < point_e.x &&
|
|
||||||
my > point_s.y && my < point_e.y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,7 @@ public class TileWater extends Tile
|
||||||
super.onWalkedOn(chunk, layer, pos, entity, state);
|
super.onWalkedOn(chunk, layer, pos, entity, state);
|
||||||
|
|
||||||
// Spawn some water particles
|
// Spawn some water particles
|
||||||
for(int i=0;i<4;i++) {
|
layer.spawnEntity(ParticleWater.createWaterParticles(entity.pos, 4));
|
||||||
layer.spawnEntity(new ParticleWater(entity.pos.copy()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package projectzombie.world.chunk;
|
package projectzombie.world.chunk;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL33;
|
import org.lwjgl.opengl.GL33;
|
||||||
|
|
@ -21,6 +22,7 @@ import projectzombie.display.Camera;
|
||||||
import projectzombie.entity.Entity;
|
import projectzombie.entity.Entity;
|
||||||
import projectzombie.entity.EntityAlive;
|
import projectzombie.entity.EntityAlive;
|
||||||
import projectzombie.entity.EntityHeight;
|
import projectzombie.entity.EntityHeight;
|
||||||
|
import projectzombie.entity.EntityHoldsEntities;
|
||||||
import projectzombie.entity.EntityKillWithParticles;
|
import projectzombie.entity.EntityKillWithParticles;
|
||||||
import projectzombie.entity.particle.ParticleBreak;
|
import projectzombie.entity.particle.ParticleBreak;
|
||||||
import projectzombie.init.Tiles;
|
import projectzombie.init.Tiles;
|
||||||
|
|
@ -78,6 +80,14 @@ public class Chunk implements IBdfClassManager
|
||||||
this.dirty = true;
|
this.dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isLightDirty() {
|
||||||
|
return light_dirty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetLightDirty() {
|
||||||
|
this.light_dirty = false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void BdfClassLoad(BdfObject bdf)
|
public void BdfClassLoad(BdfObject bdf)
|
||||||
{
|
{
|
||||||
|
|
@ -176,6 +186,39 @@ public class Chunk implements IBdfClassManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void renderEntities(Object[] entities)
|
||||||
|
{
|
||||||
|
// Render each entity
|
||||||
|
for(Object o : entities)
|
||||||
|
{
|
||||||
|
Entity e = (Entity)o;
|
||||||
|
|
||||||
|
if(e == null || e.isDead()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Model model = e.getModel();
|
||||||
|
double h = 0;
|
||||||
|
|
||||||
|
if(e instanceof EntityHoldsEntities) {
|
||||||
|
renderEntities(((EntityHoldsEntities) e).getEntities());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't try to render anything if the model is empty
|
||||||
|
if(model.getSize() == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(e instanceof EntityHeight) {
|
||||||
|
h = ((EntityHeight)e).getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render the model
|
||||||
|
model.setModel(Matrix4.translate(e.pos.x - 0.5, h, e.pos.y - 0.5));
|
||||||
|
model.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void render(Camera camera)
|
public void render(Camera camera)
|
||||||
{
|
{
|
||||||
if(this.render_dirty)
|
if(this.render_dirty)
|
||||||
|
|
@ -266,23 +309,11 @@ public class Chunk implements IBdfClassManager
|
||||||
model = new ModelChunk(verticies, textures, verticies_size);
|
model = new ModelChunk(verticies, textures, verticies_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
// Render all the tiles in the chunk as a block
|
||||||
model.setModel(Matrix4.translate(c_pos.x * 16, 0, c_pos.y * 16));
|
model.setModel(Matrix4.translate(c_pos.x * 16, 0, c_pos.y * 16));
|
||||||
model.render();
|
model.render();
|
||||||
}
|
|
||||||
|
|
||||||
for(Entity e : entities)
|
renderEntities(entities.toArray());
|
||||||
{
|
|
||||||
Model model = e.getModel();
|
|
||||||
double h = 0;
|
|
||||||
|
|
||||||
if(e instanceof EntityHeight) {
|
|
||||||
h = ((EntityHeight)e).getHeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
model.setModel(Matrix4.translate(e.pos.x - 0.5, h, e.pos.y - 0.5));
|
|
||||||
model.render();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void spawnEntity(Entity e) {
|
public void spawnEntity(Entity e) {
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,5 @@ void main()
|
||||||
{
|
{
|
||||||
FragColor = texture(tex, pTexture) * color;
|
FragColor = texture(tex, pTexture) * color;
|
||||||
|
|
||||||
if(FragColor.a == 0 || (pPos.x > tex_cut.y && tex_cut.x > 0.5)) {
|
discard(FragColor.a == 0 || (pPos.x > tex_cut.y && tex_cut.x > 0.5));
|
||||||
discard;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 952 B |
|
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 829 B |
|
Before Width: | Height: | Size: 556 B After Width: | Height: | Size: 5.5 KiB |
|
Before Width: | Height: | Size: 1005 B After Width: | Height: | Size: 5.7 KiB |
|
Before Width: | Height: | Size: 984 B After Width: | Height: | Size: 5.6 KiB |
|
Before Width: | Height: | Size: 985 B After Width: | Height: | Size: 5.5 KiB |
|
Before Width: | Height: | Size: 1021 B After Width: | Height: | Size: 5.5 KiB |
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 5.6 KiB |
|
Before Width: | Height: | Size: 932 B After Width: | Height: | Size: 5.6 KiB |
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 7.9 KiB |