Starsector API
Loading...
Searching...
No Matches
FlickerUtil.java
Go to the documentation of this file.
1package com.fs.starfarer.api.util;
2
3public class FlickerUtil {
4 private float angle;
5 private float brightness;
6 private float currTime;
7 private float currMaxBurstTime;
8 private float currMaxBrightness;
9 private float maxBurstTime;
10 private float peakTime;
11 private float peakDur;
12 private boolean stop = false;
13
14 public FlickerUtil() {
15 //maxBurstTime = 0.25f;
16 //maxBurstTime = 1f;
17 maxBurstTime = 0.5f;
18 newBurst();
19 }
20
21 public void setStop(boolean stop) {
22 this.stop = stop;
23 }
24
25 private void newBurst() {
26 if (stop) {
27 brightness = 0f;
28 return;
29 }
30 currMaxBurstTime = maxBurstTime * 0.25f + (float) Math.random() * maxBurstTime * 0.75f;
31 //currMaxBrightness = (float) Math.random() * 0.75f + 0.5f;
32 currMaxBrightness = (float) Math.random() * 0.5f + 0.75f;
33 //currMaxBrightness = 1f;
34 if (currMaxBrightness > 1) currMaxBrightness = 1;
35 //peakTime = currMaxBurstTime / 3f;
36 //peakDur = peakTime/2f;
37 peakTime = 0f;
38 //peakDur = currMaxBurstTime / 5f;
39 peakDur = currMaxBurstTime / 20f;
40 currTime = 0f;
41
42 angle = (float) Math.random() * 360f;
43 brightness = 1f;
44 }
45
46 public float getBrightness() {
47 return brightness * currMaxBrightness;
48 }
49
50 public float getAngle() {
51 return angle;
52 }
53
59 public boolean advance(float amount) {
60 currTime += amount;
61
62 if (currTime > currMaxBurstTime) {
63 newBurst();
64 return true;
65 } else {
66 if (currTime > peakTime + peakDur){
67 //brightness -= amount / (currMaxBurstTime - peakTime - peakDur);
68 brightness -= amount / Math.max(0.1f, 0.25f - peakTime - peakDur);
69 if (brightness < 0) brightness = 0;
70 } else {
71 brightness = 1f;
72 }
73 }
74 return false;
75 }
76
77 public float getCurrTime() {
78 return currTime;
79 }
80
81
82
83}