85 lines
2.3 KiB
Java
85 lines
2.3 KiB
Java
package projectzombie.entity.particle;
|
|
|
|
import projectzombie.Main;
|
|
import projectzombie.display.Camera;
|
|
import projectzombie.entity.EntityVertical;
|
|
import projectzombie.util.gl.GlHelpers;
|
|
import projectzombie.util.gl.texture.IHasTexture;
|
|
import projectzombie.util.gl.texture.TextureReference;
|
|
import projectzombie.util.math.MathHelpers;
|
|
import projectzombie.util.math.TileState;
|
|
import projectzombie.util.math.random.RandomHelpers;
|
|
import projectzombie.util.math.vec.Vec2d;
|
|
import projectzombie.util.math.vec.Vec2i;
|
|
import projectzombie.util.math.vec.Vec3d;
|
|
import projectzombie.world.chunk.Chunk;
|
|
import projectzombie.world.layer.Layer;
|
|
|
|
public class ParticleBreak extends EntityVertical
|
|
{
|
|
private double height = 0;
|
|
private Vec3d velocity;
|
|
private int time = 1000;
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
public ParticleBreak(Vec2d pos, TileState ts) {
|
|
super(pos, getTexture(ts), new Vec2d(1/4.0, 1/4.0));
|
|
this.opaqueTile = ts.tile.opaqueTile;
|
|
this.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);
|
|
}
|
|
|
|
@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;
|
|
|
|
height += velocity.z;
|
|
velocity.z -= MathHelpers.FallSpeed;
|
|
|
|
if(height < -1) {
|
|
kill();
|
|
}
|
|
|
|
else {
|
|
pos.x += velocity.x;
|
|
pos.y += velocity.y;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void render(Vec2d pos, Camera camera, TextureReference tex, Vec2d size) {
|
|
Vec3d light = chunk.getRGBLightLevel(new Vec2i(
|
|
MathHelpers.floor(pos.x), MathHelpers.floor(pos.y)));
|
|
GlHelpers.color3(light.x, light.y, light.z);
|
|
GlHelpers.pushMatrix();
|
|
GlHelpers.translate3(0, 0, height);
|
|
super.render(pos, camera, tex, size);
|
|
GlHelpers.popMatrix();
|
|
}
|
|
}
|