Skip to content

Commit

Permalink
UI completed
Browse files Browse the repository at this point in the history
  • Loading branch information
WinCisky committed Jan 25, 2020
1 parent 9c20145 commit 0426a90
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 12 deletions.
18 changes: 18 additions & 0 deletions Assets/Scenes/DOTS Subscene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -449,6 +450,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
gameStarted: 0
gameOver: 0
startTime: 0
score: 0
--- !u!4 &1025150257
Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions Assets/Scripts/DeathSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;

[AlwaysSynchronizeSystem]
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions Assets/Scripts/Digit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/DigitNumberSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions Assets/Scripts/FollowPlayerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Player>().ForEach((ref Translation translation) =>
{
#if UNITY_DOTSPLAYER
Expand All @@ -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
Expand All @@ -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;
});
}
}
45 changes: 45 additions & 0 deletions Assets/Scripts/GameOver.cs
Original file line number Diff line number Diff line change
@@ -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;
}
});
}
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/GameOver.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Assets/Scripts/GameStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
public struct GameStatus : IComponentData
{
public bool gameStarted;
public bool gameOver;
public double startTime;
public int score;
}
1 change: 1 addition & 0 deletions Assets/Scripts/InputShow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
21 changes: 13 additions & 8 deletions Assets/Scripts/MenuSpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Digit>(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)
{
Expand All @@ -30,39 +35,39 @@ 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:
var s2 = "created by";
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:
var s3 = "simone simonella";
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:
var s4 = "touch/click/press space";
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:
var s5 = "to start";
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;
}
Expand Down
8 changes: 8 additions & 0 deletions Assets/Scripts/PlayerPosition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Unity.Entities;
using Unity.Mathematics;

[GenerateAuthoringComponent]
public struct PlayerPosition : IComponentData
{
public float3 pos;
}
11 changes: 11 additions & 0 deletions Assets/Scripts/PlayerPosition.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 0426a90

Please sign in to comment.