73 lines
1.7 KiB
Java
73 lines
1.7 KiB
Java
package shootergame.entity;
|
|
|
|
import shootergame.Main;
|
|
import shootergame.display.Camera;
|
|
import shootergame.util.gl.GlHelpers;
|
|
import shootergame.util.math.vec.Vec2d;
|
|
import shootergame.world.chunk.Chunk;
|
|
import shootergame.world.layer.Layer;
|
|
|
|
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;
|
|
}
|
|
|
|
public void setSize(double size) {
|
|
this.size = size;
|
|
}
|
|
|
|
public void setHeight(double height) {
|
|
this.height = height;
|
|
}
|
|
|
|
@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) this.kill();
|
|
}
|
|
|
|
@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.popMatrix();
|
|
}
|
|
}
|