Commit 642ebc8d authored by Parsa Rahmaty's avatar Parsa Rahmaty

Improved Level Editor

parent faa3aa11
......@@ -724,10 +724,11 @@ MonoBehaviour:
obstacle: {fileID: 1346351848409056502, guid: 3b7824bf54e24584faed3e1b18a49e3c,
type: 3}
numberOfUnits: 60
rotationOffset: 0
rotationSpeed:
- 40
- 40
rotationOffsets:
- 90
rotationTimes:
- 90
rotationSpeedCurve: []
levelEditor:
- o10e20o10e20
- o5e55
......@@ -931,10 +932,41 @@ MonoBehaviour:
obstacle: {fileID: 1346351848409056502, guid: f9e114fc26bfeb34bb2e60d1b2a8741b,
type: 3}
numberOfUnits: 48
rotationOffset: 0
rotationSpeed:
- 60
- 60
rotationOffsets: []
rotationTimes: []
rotationSpeedCurve:
- serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: -0
outSlope: 2.2586784
tangentMode: 5
weightedMode: 0
inWeight: 0
outWeight: 0.07278481
- serializedVersion: 3
time: 0.49741524
value: 3.0121965
inSlope: 0.038463842
outSlope: 0.0014007525
tangentMode: 1
weightedMode: 0
inWeight: 0.1666667
outWeight: 0.33333334
- serializedVersion: 3
time: 1
value: 0.0017318726
inSlope: -2.6255615
outSlope: -2.6255615
tangentMode: 0
weightedMode: 0
inWeight: 0.05031461
outWeight: 0
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 0
levelEditor:
- e21o9e15
- o3e45
......@@ -1787,10 +1819,9 @@ MonoBehaviour:
obstacle: {fileID: 1346351848409056502, guid: 5c46f08dc2ad2dd499ad70a5584a387d,
type: 3}
numberOfUnits: 72
rotationOffset: 0
rotationSpeed:
- 20
- 20
rotationOffsets: []
rotationTimes: []
rotationSpeedCurve: []
levelEditor:
- o15e21o15e21
- o5e67
......
......@@ -6,8 +6,10 @@ public class ObstacleCircle : MonoBehaviour
{
[SerializeField] private GameObject obstacle = null;
[SerializeField] private int numberOfUnits = 0;
[SerializeField] private float rotationOffset = 0f;
[SerializeField] private float[] rotationSpeed = null;
[SerializeField] private float[] rotationOffsets = null;
[SerializeField] private float[] rotationTimes = null;
// The values are read from 0 to 1
[SerializeField] private AnimationCurve[] rotationSpeedCurve = null;
// 'o' means obstacle, followed by the number of adjacent of them.
// 'e' means empty or no obstacle, followed by the number of empty units
// the sum of all numbers in an string should be equal to the numberOfUnits field;
......@@ -15,30 +17,103 @@ public class ObstacleCircle : MonoBehaviour
private float initialRotationY;
private ArrayList obstacles = new ArrayList();
private int levelIndex = 0;
private int nextLevelIndex = 0;
private int rotationSpeedMultiplier = 50;
private float time = 0f;
private float defaultRotationTime = 2.0f;
private float defaultRotationSpeed = 1f;
private void Awake()
{
initialRotationY = transform.localEulerAngles.y;
// If rotationOffsets is not all initialized
if (rotationOffsets.Length < levelEditor.Length)
{
if (rotationOffsets.Length == 0)
{
rotationOffsets = new float[levelEditor.Length];
for (int i = 0; i < levelEditor.Length; i++)
rotationOffsets[i] = 0f;
}
else
{
float[] tmp = rotationOffsets;
rotationOffsets = new float[levelEditor.Length];
tmp.CopyTo(rotationOffsets, 0);
for (int i = tmp.Length; i < levelEditor.Length; i++)
rotationOffsets[i] = 0f;
}
}
// If rotationTimes is not all initialized
if (rotationTimes.Length < levelEditor.Length)
{
if (rotationTimes.Length == 0)
{
rotationTimes = new float[levelEditor.Length];
for (int i = 0; i < levelEditor.Length; i++)
rotationTimes[i] = defaultRotationTime;
}
else
{
float[] tmp = rotationTimes;
rotationTimes = new float[levelEditor.Length];
tmp.CopyTo(rotationTimes, 0);
for (int i = tmp.Length; i < levelEditor.Length; i++)
rotationTimes[i] = defaultRotationTime;
}
}
// If rotationSpeedCurve is not all initialized
if (rotationSpeedCurve.Length < levelEditor.Length)
{
if (rotationSpeedCurve.Length == 0)
{
rotationSpeedCurve = new AnimationCurve[levelEditor.Length];
for (int i = 0; i < levelEditor.Length; i++)
{
rotationSpeedCurve[i] = new AnimationCurve();
rotationSpeedCurve[i].AddKey(new Keyframe(0f, defaultRotationSpeed));
rotationSpeedCurve[i].AddKey(new Keyframe(1f, defaultRotationSpeed));
}
}
else
{
AnimationCurve[] tmp = rotationSpeedCurve;
rotationSpeedCurve = new AnimationCurve[levelEditor.Length];
tmp.CopyTo(rotationSpeedCurve, 0);
for (int i = tmp.Length; i < levelEditor.Length; i++)
{
rotationSpeedCurve[i] = new AnimationCurve();
rotationSpeedCurve[i].AddKey(new Keyframe(0f, defaultRotationSpeed));
rotationSpeedCurve[i].AddKey(new Keyframe(1f, defaultRotationSpeed));
}
}
}
}
private void Start()
{
transform.localEulerAngles += new Vector3(0f, rotationOffset, 0f);
transform.localEulerAngles += new Vector3(0f, rotationOffsets[0], 0f);
if (levelEditor.Length != 0)
MakeNextLevel();
GameEvents.instance.onNextLevelEvent += NextLevel;
GameEvents.instance.onGameRestartEvent += Restart;
}
private void FixedUpdate()
private void Update()
{
transform.localEulerAngles += new Vector3(0f, (rotationSpeed.Length != 0)?(rotationSpeed[levelIndex] * Time.fixedDeltaTime):(0f), 0f);
// Rotate the obstacles based on the animation curve in rotationTime of that level
time += Time.deltaTime / rotationTimes[currentLevelIndex()];
if (time > rotationTimes[currentLevelIndex()])
time = 0f;
transform.localEulerAngles += new Vector3(0f, rotationSpeedCurve[currentLevelIndex()].Evaluate(time / rotationTimes[currentLevelIndex()]) * rotationSpeedMultiplier * Time.deltaTime, 0f);
}
private void MakeNextLevel()
{
string level = levelEditor[levelIndex];
string level = levelEditor[nextLevelIndex];
char[] legalChars = { 'o', 'e' };
string leftover = level;
int currentUnitIndex = 0;
......@@ -78,12 +153,12 @@ public class ObstacleCircle : MonoBehaviour
currentUnitIndex++;
}
}
levelIndex = (levelIndex + 1) % levelEditor.Length;
nextLevelIndex = (nextLevelIndex + 1) % levelEditor.Length;
}
private void Restart()
{
levelIndex = 0;
nextLevelIndex = 0;
NextLevel();
}
......@@ -95,8 +170,13 @@ public class ObstacleCircle : MonoBehaviour
Destroy(element);
}
obstacles = new ArrayList();
transform.localEulerAngles = new Vector3(0f, initialRotationY + rotationOffset, 0f);
transform.localEulerAngles = new Vector3(0f, initialRotationY + rotationOffsets[nextLevelIndex], 0f);
if (levelEditor.Length != 0)
MakeNextLevel();
}
private int currentLevelIndex()
{
return (nextLevelIndex - 1 < 0) ? (levelEditor.Length - 1) : (nextLevelIndex - 1);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment