76 lines
1.5 KiB
Java
76 lines
1.5 KiB
Java
package shootergame.entity;
|
|
|
|
import java.util.Random;
|
|
|
|
import shootergame.display.Camera;
|
|
import shootergame.util.gl.GlHelpers;
|
|
import shootergame.util.math.random.RandomHelpers;
|
|
import shootergame.util.math.vec.Vec2d;
|
|
import shootergame.world.chunk.Chunk;
|
|
import shootergame.world.layer.Layer;
|
|
|
|
public class EntityBullet extends EntityParticle
|
|
{
|
|
private int time = 0;
|
|
private Random rand;
|
|
private Entity parent;
|
|
|
|
public EntityBullet(Random rand, Vec2d pos, Entity parent, double angle) {
|
|
super(0.2, 0.4);
|
|
|
|
// Store some specified values
|
|
this.rand = rand;
|
|
this.pos = pos;
|
|
this.angle = angle;
|
|
this.parent = parent;
|
|
}
|
|
|
|
@Override
|
|
public void tick(Chunk chunk, Layer layer) {
|
|
super.tick(chunk, layer);
|
|
|
|
// Move forward in the bullets angle, very quickly
|
|
this.moveForward(0.2);
|
|
|
|
// Loop over the nearby entities
|
|
for(Entity e : layer.getNearbyEntities(pos, 0.5))
|
|
{
|
|
// Is this entity alive and not the parent
|
|
if(e instanceof EntityAlive && e != parent)
|
|
{
|
|
// Get the alive entity
|
|
EntityAlive ea = (EntityAlive)e;
|
|
|
|
// Spawn some blood particles
|
|
for(int i=0;i<20;i++) {
|
|
chunk.spawnEntity(new EntityBlood(rand, pos.copy(), angle));
|
|
}
|
|
|
|
// Harm the entity
|
|
ea.removeHealth(10);
|
|
|
|
// Kill the bullet
|
|
chunk.killEntity(this);
|
|
return;
|
|
}
|
|
}
|
|
|
|
// Increase time
|
|
time++;
|
|
|
|
if(time > 60) {
|
|
chunk.killEntity(this);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void render(Vec2d pos, Camera camera)
|
|
{
|
|
// Set the colour
|
|
GlHelpers.color3(0.6, 0.6, 0);
|
|
|
|
// Call super
|
|
super.render(pos, camera);
|
|
}
|
|
}
|