75 lines
1.9 KiB
Java
75 lines
1.9 KiB
Java
package shootergame.entity.particle;
|
|
|
|
import shootergame.Main;
|
|
import shootergame.display.Camera;
|
|
import shootergame.entity.EntityVertical;
|
|
import shootergame.util.gl.GlHelpers;
|
|
import shootergame.util.gl.texture.IHasTexture;
|
|
import shootergame.util.gl.texture.TextureReference;
|
|
import shootergame.util.math.TileState;
|
|
import shootergame.util.math.random.RandomHelpers;
|
|
import shootergame.util.math.vec.Vec2d;
|
|
import shootergame.world.chunk.Chunk;
|
|
import shootergame.world.layer.Layer;
|
|
|
|
public class ParticleBreak extends EntityVertical
|
|
{
|
|
private double height = 0;
|
|
private double height_speed;
|
|
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(getTexture(ts), new Vec2d(1/4.0, 1/4.0));
|
|
this.opaqueTile = ts.tile.opaqueTile;
|
|
this.pos = pos;
|
|
this.angle = RandomHelpers.randrange(rand, 360);
|
|
height_speed = 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 += height_speed;
|
|
height_speed -= 0.001;
|
|
|
|
if(height <= 0) {
|
|
height_speed = 0;
|
|
}
|
|
|
|
else {
|
|
moveForward(0.01);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void render(Vec2d pos, Camera camera, TextureReference tex, Vec2d size) {
|
|
GlHelpers.pushMatrix();
|
|
GlHelpers.translate(0, 0, height);
|
|
super.render(pos, camera, tex, size);
|
|
GlHelpers.popMatrix();
|
|
}
|
|
}
|