package shootergame.entity; import shootergame.Main; import shootergame.init.Textures; import shootergame.util.math.random.OpenSimplexNoise; import shootergame.util.math.vec.Vec2d; import shootergame.world.chunk.Chunk; import shootergame.world.layer.Layer; public class EntityZombieBomber extends EntityVertical implements EntityAlive { private int time = 0; private OpenSimplexNoise noise_movement; private double health = 100; private double max_health = 100; public EntityZombieBomber(Vec2d pos) { super(Textures.ENTITY_ZOMBIE_BOMBER, new Vec2d(1, 1)); this.noise_movement = new OpenSimplexNoise(rand.nextLong()); this.pos = pos; this.goThroughSolid = false; this.crossUnWalkable = false; this.isSolid = true; } private void explode(Layer layer) { kill(); layer.spawnEntity(new EntityExplosion(pos, 6, 5000)); } @Override public void moveBackward() { super.moveBackward(0.06); } @Override public void moveForward() { super.moveForward(0.06); } @Override public void tick(Chunk chunk, Layer layer) { super.tick(chunk, layer); // Explode if the zombie is dead if(health <= 0) { this.explode(layer); return; } // Get the angle between the player and the zombie double angle = Math.atan2(pos.x - Main.player.pos.x, pos.y - Main.player.pos.y); // Move forward towards the player this.angle = Math.toDegrees(angle) + 180; this.angle += noise_movement.eval(time, 0)*80; this.moveForward(); // Explode if the zombie is in radius of the player if(Main.player.pos.squareDistance(pos) < 3) { this.explode(layer); return; } // Increase time time += 0.001; } @Override public void addHealth(double amount) { this.health += amount; } @Override public void removeHealth(double amount) { this.health -= amount; } @Override public double getHealth() { return health; } @Override public void resetHealth() { this.health = max_health; } @Override public void clearHealth() { this.health = 0; } @Override public double maxHealth() { return max_health; } @Override public void setHealth(double health) { this.health = health; } }