48 lines
1.2 KiB
Java
48 lines
1.2 KiB
Java
package projectzombie.tiles;
|
|
|
|
import java.util.Random;
|
|
|
|
import mainloop.task.IMainloopTask;
|
|
import projectzombie.time.GameTimer;
|
|
import projectzombie.util.math.MathHelpers;
|
|
import projectzombie.util.math.random.OpenSimplexNoise;
|
|
|
|
public class LightLevelNoise implements IMainloopTask
|
|
{
|
|
private static final Random rand = new Random();
|
|
private static final OpenSimplexNoise lava_noise_g = new OpenSimplexNoise(rand.nextLong());
|
|
private static final OpenSimplexNoise lantern_noise_g = new OpenSimplexNoise(rand.nextLong());
|
|
|
|
private static double lava_noise = 0;
|
|
private static double lantern_noise = 0;
|
|
|
|
static double getLightLevel(OpenSimplexNoise noise) {
|
|
return noise.eval(GameTimer.getTime() / 50.0, 0);
|
|
}
|
|
|
|
static double getLavaLightLevel() {
|
|
return lava_noise;
|
|
}
|
|
|
|
static double getLanternLightLevel() {
|
|
return lantern_noise;
|
|
}
|
|
|
|
@Override
|
|
public boolean MainLoopDelay(long millis) {
|
|
return millis > 10;
|
|
}
|
|
|
|
@Override
|
|
public boolean MainLoopRepeat() {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public void MainLoopUpdate()
|
|
{
|
|
lava_noise = MathHelpers.map(getLightLevel(lava_noise_g), -1, 1, 0.6, 0.8);
|
|
lantern_noise = MathHelpers.map(getLightLevel(lantern_noise_g), -1, 1, 0.6, 1);
|
|
}
|
|
}
|