diff options
author | miakata <miakata@gmail.com> | 2019-04-27 20:57:13 +0200 |
---|---|---|
committer | miakata <miakata@gmail.com> | 2019-04-27 20:57:13 +0200 |
commit | 5b8e22009ffa9f1297dc3bb1bf1807fade67d79f (patch) | |
tree | 6e32e373468130033a666b7dd088aa33dc61352a /nGJ2019/Assets/Scripts | |
parent | 738f22bae44b4d57ae77419f48dbd4a7d57312d7 (diff) | |
parent | 2b8e13affdf1047b196e5e80288b80a6d5eda5cb (diff) |
Merge branch 'master' of https://github.com/marcinzelent/ngj2019
Diffstat (limited to 'nGJ2019/Assets/Scripts')
-rw-r--r-- | nGJ2019/Assets/Scripts/EventTimeline.cs | 7 | ||||
-rw-r--r-- | nGJ2019/Assets/Scripts/LevelScrolling.cs | 104 | ||||
-rw-r--r-- | nGJ2019/Assets/Scripts/Messenger.cs | 1 | ||||
-rw-r--r-- | nGJ2019/Assets/Scripts/ObstacleSpawner.cs | 5 |
4 files changed, 65 insertions, 52 deletions
diff --git a/nGJ2019/Assets/Scripts/EventTimeline.cs b/nGJ2019/Assets/Scripts/EventTimeline.cs index b864ae7..18b87cc 100644 --- a/nGJ2019/Assets/Scripts/EventTimeline.cs +++ b/nGJ2019/Assets/Scripts/EventTimeline.cs @@ -60,17 +60,20 @@ public class EventTimeline { currentTime += deltaTime; - while(futureEvents.Count > 0 && currentTime > futureEvents[0].time && futureMessages.Count > 0 && currentTime > futureMessages[0].time) + while(futureEvents.Count > 0 && currentTime > futureEvents[0].time) { SpawnEvent e = futureEvents[0]; futureEvents.RemoveAt(0); if(OnSpawnEvent != null) OnSpawnEvent(e); + } + while(futureMessages.Count > 0 && currentTime > futureMessages[0].time) + { MessageEvent m = futureMessages[0]; futureMessages.RemoveAt(0); if(OnMessageEvent != null) OnMessageEvent(m); - } + } } } diff --git a/nGJ2019/Assets/Scripts/LevelScrolling.cs b/nGJ2019/Assets/Scripts/LevelScrolling.cs index 0122a69..fac0a13 100644 --- a/nGJ2019/Assets/Scripts/LevelScrolling.cs +++ b/nGJ2019/Assets/Scripts/LevelScrolling.cs @@ -4,66 +4,76 @@ using UnityEngine; public class LevelScrolling : MonoBehaviour
{
- public int UpdateRate = -5;
- public List<Transform> Obstacles;
- public Transform Background;
+ public int UpdateRate = -5;
+ public List<GameObject> Obstacles;
+ public Transform Background;
- private Vector3 initialBgPos;
- private float[] backgroundSize;
+ private Vector3 initialBgPos;
+ private float[] backgroundSize;
- // Start is called before the first frame update
- void Start()
- {
- ResizeBackground();
- }
+ // Start is called before the first frame update
+ void Start()
+ {
+ ResizeBackground();
+ }
+
+ // Update is called once per frame
+ void Update()
+ {
- // Update is called once per frame
- void Update()
- {
+ }
+
+ void FixedUpdate()
+ {
+ MoveBackground();
+ MoveObstacles();
+ DestroyObstacles();
+ }
- }
+ void ResizeBackground()
+ {
+ var sr = Background.GetComponent<SpriteRenderer>();
+ if (sr == null) return;
- void FixedUpdate()
- {
- MoveBackground();
- MoveObstacles();
- }
+ Background.localScale = new Vector3(1, 1, 1);
- private void ResizeBackground()
- {
- var sr = Background.GetComponent<SpriteRenderer>();
- if (sr == null) return;
+ var width = sr.sprite.bounds.size.x;
+ var height = sr.sprite.bounds.size.y;
- Background.localScale = new Vector3(1, 1, 1);
+ var worldScreenHeight = Camera.main.orthographicSize * 2.0;
+ var worldScreenWidth = worldScreenHeight / Screen.height * Screen.width;
- var width = sr.sprite.bounds.size.x;
- var height = sr.sprite.bounds.size.y;
+ var finalHeight = (float)(worldScreenHeight / height);
+ var finalWidth = (float)(worldScreenWidth / width);
- var worldScreenHeight = Camera.main.orthographicSize * 2.0;
- var worldScreenWidth = worldScreenHeight / Screen.height * Screen.width;
+ Background.localScale = new Vector3(finalHeight, finalHeight, 1);
- var finalHeight = (float)(worldScreenHeight / height);
- var finalWidth = (float)(worldScreenWidth / width);
+ var viewportX = Camera.main.ViewportToWorldPoint(new Vector3(0, 1, 0)).x;
+ Background.position = new Vector3(viewportX * -1, 0, 0);
+ initialBgPos = Background.position;
+ }
- Background.localScale = new Vector3(finalHeight, finalHeight, 1);
+ void MoveObstacles()
+ {
+ for (int i = 0; i < Obstacles.Count; i++)
+ {
+ Obstacles[i].transform.Translate(0.01f * UpdateRate, 0, 0);
+ }
+ }
- var viewportX = Camera.main.ViewportToWorldPoint(new Vector3(0, 1, 0)).x;
- Background.position = new Vector3(viewportX * -1, 0, 0);
- initialBgPos = Background.position;
- }
+ void DestroyObstacles()
+ {
+ if (Obstacles[0].transform.position.x < -30)
+ {
+ Destroy(Obstacles[0]);
+ Obstacles.RemoveAt(0);
+ }
+ }
- private void MoveObstacles()
- {
- foreach (var o in Obstacles)
+ void MoveBackground()
{
- o.Translate(0.01f * UpdateRate, 0, 0);
+ if (Background.position.x > -initialBgPos.x)
+ Background.Translate(0.01f * UpdateRate, 0, 0);
+ else Background.position = initialBgPos;
}
- }
-
- private void MoveBackground()
- {
- if (Background.position.x > -initialBgPos.x)
- Background.Translate(0.01f * UpdateRate, 0, 0);
- else Background.position = initialBgPos;
- }
}
diff --git a/nGJ2019/Assets/Scripts/Messenger.cs b/nGJ2019/Assets/Scripts/Messenger.cs index ca2ffe1..21d2f8d 100644 --- a/nGJ2019/Assets/Scripts/Messenger.cs +++ b/nGJ2019/Assets/Scripts/Messenger.cs @@ -16,6 +16,7 @@ public class Messenger : MonoBehaviour timeline = Spawner.GetEventTimeline();
timeline.Add(1, "Test");
+ timeline.Add(3, "");
timeline.OnMessageEvent += MessageOnEvent;
}
diff --git a/nGJ2019/Assets/Scripts/ObstacleSpawner.cs b/nGJ2019/Assets/Scripts/ObstacleSpawner.cs index f438e85..0e6b3ac 100644 --- a/nGJ2019/Assets/Scripts/ObstacleSpawner.cs +++ b/nGJ2019/Assets/Scripts/ObstacleSpawner.cs @@ -8,7 +8,6 @@ public class ObstacleSpawner : MonoBehaviour public GameObject caveWallsPrefab, rockTopPrefab, rockBottomPrefab, narrowPassagePrefab, rockJawsPrefab; public LevelScrolling scrolling; - public Messenger messenger; public float spawnLine; @@ -35,8 +34,8 @@ public class ObstacleSpawner : MonoBehaviour break; } - var transformT = ((GameObject)Instantiate(prefab, new Vector3(spawnLine, e.height, 0), Quaternion.identity)).transform; - scrolling.Obstacles.Add(transformT); + var o = Instantiate(prefab, new Vector3(spawnLine, e.height, 0), Quaternion.identity); + scrolling.Obstacles.Add(o); } void Start() |