169 lines
3.9 KiB
Java
Executable File
169 lines
3.9 KiB
Java
Executable File
package projectzombie.entity.particle;
|
|
|
|
import projectzombie.Main;
|
|
import projectzombie.display.Camera;
|
|
import projectzombie.entity.Entity;
|
|
import projectzombie.entity.EntityParticle;
|
|
import projectzombie.init.Models;
|
|
import projectzombie.model.Model;
|
|
import projectzombie.settings.SettingQuality;
|
|
import projectzombie.util.gl.GlHelpers;
|
|
import projectzombie.util.gl.texture.IHasTexture;
|
|
import projectzombie.util.gl.texture.TextureReference;
|
|
import gl_engine.MathHelpers;
|
|
import projectzombie.util.math.TileState;
|
|
import projectzombie.util.math.random.RandomHelpers;
|
|
import gl_engine.vec.Vec2d;
|
|
import gl_engine.vec.Vec2i;
|
|
import gl_engine.vec.Vec3d;
|
|
import projectzombie.world.chunk.Chunk;
|
|
import projectzombie.world.layer.Layer;
|
|
|
|
public class ParticleBreak extends EntityParticle
|
|
{
|
|
private double height = 0;
|
|
private Vec3d velocity;
|
|
private int time = 0;
|
|
private boolean landed = false;
|
|
|
|
public static void spawnParticles(Chunk chunk, Vec2d pos, Entity e)
|
|
{
|
|
if(EntityParticle.MODE == SettingQuality.OFF) {
|
|
return;
|
|
}
|
|
|
|
int height = 1;
|
|
|
|
/*if(e instanceof EntityVertical) {
|
|
height = MathHelpers.floor(((EntityVertical)e).size.y);
|
|
}
|
|
|
|
for(int i=0;i<50 * height;i++) {
|
|
chunk.spawnEntity(new ParticleBreak(pos.copy(), e));
|
|
}*/
|
|
}
|
|
|
|
public static void spawnParticles(Chunk chunk, Vec2d pos, TileState s)
|
|
{
|
|
if(EntityParticle.MODE == SettingQuality.OFF) {
|
|
return;
|
|
}
|
|
|
|
int height = 1;
|
|
|
|
|
|
|
|
for(int i=0;i<50 * height;i++) {
|
|
chunk.spawnEntity(new ParticleBreak(pos.copy(), s));
|
|
}
|
|
}
|
|
|
|
/*private static TextureReference getTexture(TileState ts)
|
|
{
|
|
if(ts.tile instanceof IHasTexture)
|
|
{
|
|
TextureReference tex = ((IHasTexture)ts.tile).getTexture();
|
|
|
|
int px = RandomHelpers.randrange(rand, tex.start_x, tex.end_x - 2);
|
|
int py = RandomHelpers.randrange(rand, tex.start_y, tex.end_y - 2);
|
|
return tex.getTextureReference(px, px + 2, py, py + 2);
|
|
}
|
|
|
|
else {
|
|
return TextureReference.EMPTY;
|
|
}
|
|
}
|
|
|
|
private static TextureReference getTexture(Entity entity)
|
|
{
|
|
if(entity instanceof IHasTexture)
|
|
{
|
|
TextureReference tex = ((IHasTexture)entity).getTexture();
|
|
|
|
int px = RandomHelpers.randrange(rand, tex.start_x, tex.end_x - 2);
|
|
int py = RandomHelpers.randrange(rand, tex.start_y, tex.end_y - 2);
|
|
return tex.getTextureReference(px, px + 2, py, py + 2);
|
|
}
|
|
|
|
else {
|
|
return TextureReference.EMPTY;
|
|
}
|
|
}*/
|
|
|
|
public ParticleBreak(Vec2d pos, TileState ts) {
|
|
super(pos);
|
|
|
|
double angle = RandomHelpers.randrange(rand, 360);
|
|
|
|
Vec2d side_v = MathHelpers.moveTowards2(0.01, Math.toRadians(angle));
|
|
velocity = new Vec3d(
|
|
side_v.x, side_v.y,
|
|
RandomHelpers.randrange(rand, 10000) / 200000.0);
|
|
|
|
time = RandomHelpers.randrange(rand, 800, 1200);
|
|
}
|
|
|
|
public ParticleBreak(Vec2d pos, Entity entity) {
|
|
super(pos);
|
|
double angle = RandomHelpers.randrange(rand, 360);
|
|
|
|
Vec2d side_v = MathHelpers.moveTowards2(0.01, Math.toRadians(angle));
|
|
velocity = new Vec3d(
|
|
side_v.x, side_v.y,
|
|
RandomHelpers.randrange(rand, 10000) / 200000.0);
|
|
|
|
time = RandomHelpers.randrange(rand, 500, 1500);
|
|
|
|
/*if(entity instanceof EntityVertical) {
|
|
EntityVertical entity_v = (EntityVertical) entity;
|
|
|
|
height = RandomHelpers.randrange(rand, 0, MathHelpers.floor(entity_v.size.y));
|
|
}
|
|
|
|
*/
|
|
}
|
|
|
|
@Override
|
|
public void tick(Chunk chunk, Layer layer) {
|
|
super.tick(chunk, layer);
|
|
|
|
// Kill the particle if the player can't see it to reduce lag
|
|
if(Main.player.pos.squareDistance(pos) > 32 || time < 0) {
|
|
this.kill();
|
|
}
|
|
|
|
time -= 1;
|
|
|
|
if(!landed) {
|
|
height += velocity.z;
|
|
velocity.z -= MathHelpers.FallSpeed;
|
|
}
|
|
|
|
if(height < 0) {
|
|
height = 0;
|
|
velocity = velocity.multiply(0);
|
|
landed = true;
|
|
}
|
|
|
|
if(time < 0) {
|
|
kill();
|
|
}
|
|
|
|
else {
|
|
pos.x += velocity.x;
|
|
pos.y += velocity.y;
|
|
}
|
|
|
|
if(EntityParticle.MODE == SettingQuality.OFF) {
|
|
kill();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public Model getModel() {
|
|
return Models.PARTICLE_BULLET;
|
|
}
|
|
|
|
|
|
}
|