diff --git a/Assets/Scenes/DOTS Subscene.unity b/Assets/Scenes/DOTS Subscene.unity index c749635..ccec0da 100644 --- a/Assets/Scenes/DOTS Subscene.unity +++ b/Assets/Scenes/DOTS Subscene.unity @@ -429,6 +429,7 @@ GameObject: m_Component: - component: {fileID: 1025150257} - component: {fileID: 1025150256} + - component: {fileID: 1025150258} m_Layer: 0 m_Name: GameStatus m_TagString: Untagged @@ -449,6 +450,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: gameStarted: 0 + gameOver: 0 startTime: 0 score: 0 --- !u!4 &1025150257 @@ -465,6 +467,22 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &1025150258 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1025150255} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 8822ec26c4127ef4e9b5bdb2345ace2e, type: 3} + m_Name: + m_EditorClassIdentifier: + pos: + x: 0 + y: 0 + z: 0 --- !u!1 &1073891444 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/DeathSystem.cs b/Assets/Scripts/DeathSystem.cs index 98daf28..3700713 100644 --- a/Assets/Scripts/DeathSystem.cs +++ b/Assets/Scripts/DeathSystem.cs @@ -1,5 +1,7 @@ using Unity.Entities; using Unity.Jobs; +using Unity.Mathematics; +using Unity.Transforms; using UnityEngine; [AlwaysSynchronizeSystem] @@ -28,8 +30,20 @@ protected override void OnUpdate() Entities.ForEach((ref GameStatus gs) => { gs.gameStarted = false; + gs.gameOver = true; }); + //reposition score recap (main menu) + var cameraPos = new float3(0, 0, 0); + Entities.ForEach((ref PlayerPosition cp) => + { + cameraPos = cp.pos; + }); + Entities.ForEach((ref Translation translation, ref Digit d) => + { + if (d.mainMenu) + translation.Value = cameraPos + d.offset; + }); //destroy Obstacles var obj = GetEntityQuery(new ComponentType[] { typeof(ObstacleTag) }); EntityManager.DestroyEntity(obj); diff --git a/Assets/Scripts/Digit.cs b/Assets/Scripts/Digit.cs index 70bd851..44357c1 100644 --- a/Assets/Scripts/Digit.cs +++ b/Assets/Scripts/Digit.cs @@ -9,6 +9,8 @@ public struct Digit : IComponentData public char shownValue; public int digit; public float3 offset; + public int row; + public int charIndex; public Entity s1_1, s2_1, s3_1, s1_2, s2_2, s3_2, diff --git a/Assets/Scripts/DigitNumberSystem.cs b/Assets/Scripts/DigitNumberSystem.cs index a1662bd..2ec7441 100644 --- a/Assets/Scripts/DigitNumberSystem.cs +++ b/Assets/Scripts/DigitNumberSystem.cs @@ -15,7 +15,7 @@ protected override void OnUpdate() #else var value = ((int)digit.shownValue - (int)'0'); - if (value >= 0 && value <= 26) + if (value >= 0 && value <= 9) { #endif switch (value) diff --git a/Assets/Scripts/FollowPlayerSystem.cs b/Assets/Scripts/FollowPlayerSystem.cs index 5ae0042..1002852 100644 --- a/Assets/Scripts/FollowPlayerSystem.cs +++ b/Assets/Scripts/FollowPlayerSystem.cs @@ -16,6 +16,7 @@ protected override void OnUpdate() var offset = new float3(0, 0, -25); var deltaTime = Time.DeltaTime; var cameraPos = new float3(0, 0, 0); + var playerPos = new float3(0, 0, 0); Entities.WithAll().ForEach((ref Translation translation) => { #if UNITY_DOTSPLAYER @@ -26,6 +27,7 @@ protected override void OnUpdate() cameraPos = UnityEngine.Camera.main.transform.position; cameraPos = math.lerp(cameraPos, translation.Value + offset, deltaTime * followSpeed); #endif + playerPos = translation.Value; }); //let the ui follow the player @@ -34,5 +36,11 @@ protected override void OnUpdate() if (!d.mainMenu) translation.Value = cameraPos + d.offset; }); + + //update camera pos + Entities.ForEach((ref PlayerPosition pp) => + { + pp.pos = playerPos; + }); } } \ No newline at end of file diff --git a/Assets/Scripts/GameOver.cs b/Assets/Scripts/GameOver.cs new file mode 100644 index 0000000..5e294f6 --- /dev/null +++ b/Assets/Scripts/GameOver.cs @@ -0,0 +1,45 @@ +using Unity.Burst; +using Unity.Collections; +using Unity.Entities; + +public class GameOver : ComponentSystem +{ + protected override void OnUpdate() + { + var gameOver = false; + var score = 0; + Entities.ForEach((ref GameStatus gs) => + { + gameOver = gs.gameOver; + score = gs.score; + }); + if (gameOver) + { + Entities.ForEach((ref Digit d) => + { + d.isActive = true; + switch (d.row) + { + case 1: + var s1 = " your score was: "; + d.shownValue = s1[d.charIndex]; + break; + case 2: + var s2 = " "; + if (score <= 9) + s2 += ' '; + if (score <= 99) + s2 += ' '; + s2 += score.ToString(); + s2 += " "; + d.shownValue = s2[d.charIndex]; + break; + case 3: + var s3 = "congratulations!"; + d.shownValue = s3[d.charIndex]; + break; + } + }); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/GameOver.cs.meta b/Assets/Scripts/GameOver.cs.meta new file mode 100644 index 0000000..67941ed --- /dev/null +++ b/Assets/Scripts/GameOver.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7834cb79a40640c4a8dfe0c3fad80f13 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/GameStatus.cs b/Assets/Scripts/GameStatus.cs index 0f34577..35c4c28 100644 --- a/Assets/Scripts/GameStatus.cs +++ b/Assets/Scripts/GameStatus.cs @@ -7,6 +7,7 @@ public struct GameStatus : IComponentData { public bool gameStarted; + public bool gameOver; public double startTime; public int score; } diff --git a/Assets/Scripts/InputShow.cs b/Assets/Scripts/InputShow.cs index 5e730a7..044715a 100644 --- a/Assets/Scripts/InputShow.cs +++ b/Assets/Scripts/InputShow.cs @@ -36,6 +36,7 @@ protected override void OnUpdate() Entities.ForEach((ref GameStatus gs) => { gs.gameStarted = true; + gs.gameOver = false; gs.startTime = Time.ElapsedTime; }); Entities.ForEach((ref ObstacleTag ot) => diff --git a/Assets/Scripts/MenuSpawner.cs b/Assets/Scripts/MenuSpawner.cs index c7647e6..f9d4ddc 100644 --- a/Assets/Scripts/MenuSpawner.cs +++ b/Assets/Scripts/MenuSpawner.cs @@ -8,20 +8,25 @@ public class MenuSpawner : ComponentSystem { - private void SetDigit(Entity instance, char c, int characters, int index, float yPos) + private void SetDigit(Entity instance, char c, int characters, int index, float yPos, int row) { + var pos = new float3((index - (characters / 2f)) * 0.8f, yPos, 0); + var digit = EntityManager.GetComponentData(instance); digit.shownValue = c; digit.isActive = true; + digit.charIndex = index; + digit.row = row; + digit.offset = new float3(pos.x, pos.y, -5); EntityManager.SetComponentData(instance, digit); - var pos = new float3((index - (characters / 2f)) * 0.8f, yPos, 0); + EntityManager.SetComponentData(instance, new Translation() { Value = pos }); } protected override void OnUpdate() { - Entities.ForEach((Entity entity, ref TextRow textRow, ref LocalToWorld l2w) => + Entities.ForEach((Entity entity, ref TextRow textRow) => { switch (textRow.rowNumber) { @@ -30,7 +35,7 @@ protected override void OnUpdate() for (int i = 0; i < 20; i++) { var instance = EntityManager.Instantiate(textRow.character); - SetDigit(instance, s1[i], 20, i, 5); + SetDigit(instance, s1[i], 20, i, 5, textRow.rowNumber); } break; case 2: @@ -38,7 +43,7 @@ protected override void OnUpdate() for (int i = 0; i < 10; i++) { var instance = EntityManager.Instantiate(textRow.character); - SetDigit(instance, s2[i], 10, i, 3); + SetDigit(instance, s2[i], 10, i, 3, textRow.rowNumber); } break; case 3: @@ -46,7 +51,7 @@ protected override void OnUpdate() for (int i = 0; i < 16; i++) { var instance = EntityManager.Instantiate(textRow.character); - SetDigit(instance, s3[i], 16, i, 1); + SetDigit(instance, s3[i], 16, i, 1, textRow.rowNumber); } break; case 4: @@ -54,7 +59,7 @@ protected override void OnUpdate() for (int i = 0; i < 23; i++) { var instance = EntityManager.Instantiate(textRow.character); - SetDigit(instance, s4[i], 23, i, -3); + SetDigit(instance, s4[i], 23, i, -3, textRow.rowNumber); } break; default: @@ -62,7 +67,7 @@ protected override void OnUpdate() for (int i = 0; i < 8; i++) { var instance = EntityManager.Instantiate(textRow.character); - SetDigit(instance, s5[i], 8, i, -5); + SetDigit(instance, s5[i], 8, i, -5, textRow.rowNumber); } break; } diff --git a/Assets/Scripts/PlayerPosition.cs b/Assets/Scripts/PlayerPosition.cs new file mode 100644 index 0000000..eb1b1a3 --- /dev/null +++ b/Assets/Scripts/PlayerPosition.cs @@ -0,0 +1,8 @@ +using Unity.Entities; +using Unity.Mathematics; + +[GenerateAuthoringComponent] +public struct PlayerPosition : IComponentData +{ + public float3 pos; +} diff --git a/Assets/Scripts/PlayerPosition.cs.meta b/Assets/Scripts/PlayerPosition.cs.meta new file mode 100644 index 0000000..3a93a14 --- /dev/null +++ b/Assets/Scripts/PlayerPosition.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8822ec26c4127ef4e9b5bdb2345ace2e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/README.md b/README.md index dc69f11..06dcf42 100644 --- a/README.md +++ b/README.md @@ -33,9 +33,7 @@ So i created some paths to make the game more interesting, I used the noise func ## TODO: - main menu - speed increase - score system (ui? -> is kinda distracting during the playmode) + speed increase -> not really necessary (already challenging enough) random color for cubes player and background > Bugfix (I'm not good at my own game so it's hardto discover bugs)