diff options
author | marcinzelent <zelent.marcin@gmail.com> | 2019-04-27 12:19:37 +0200 |
---|---|---|
committer | marcinzelent <zelent.marcin@gmail.com> | 2019-04-27 12:19:37 +0200 |
commit | b1a279b551e2127ff9f530b205f2e1590ae51e9f (patch) | |
tree | 3c4518fbec740f51cbf138edb1087eccdaf1305e /nGJ2019/Assets/Scripts | |
parent | dd7a4adbea30ab2e4435a314e8a3a570ed09a695 (diff) |
Added level obstacles spawning
Diffstat (limited to 'nGJ2019/Assets/Scripts')
-rw-r--r-- | nGJ2019/Assets/Scripts/LevelScrolling.cs | 27 | ||||
-rw-r--r-- | nGJ2019/Assets/Scripts/ObstacleSpawner.cs | 12 |
2 files changed, 22 insertions, 17 deletions
diff --git a/nGJ2019/Assets/Scripts/LevelScrolling.cs b/nGJ2019/Assets/Scripts/LevelScrolling.cs index b40f70e..025bf40 100644 --- a/nGJ2019/Assets/Scripts/LevelScrolling.cs +++ b/nGJ2019/Assets/Scripts/LevelScrolling.cs @@ -4,9 +4,9 @@ using UnityEngine; public class LevelScrolling : MonoBehaviour
{
- public int updateRate = 1;
- public Transform obstacles;
- public Transform background;
+ public int UpdateRate = 1;
+ public List<Transform> Obstacles;
+ public Transform Background;
private Vector3 initialBgPos;
private float[] backgroundSize;
@@ -31,10 +31,10 @@ public class LevelScrolling : MonoBehaviour private void ResizeBackground()
{
- var sr = background.GetComponent<SpriteRenderer>();
+ var sr = Background.GetComponent<SpriteRenderer>();
if (sr == null) return;
- background.localScale = new Vector3(1, 1, 1);
+ Background.localScale = new Vector3(1, 1, 1);
var width = sr.sprite.bounds.size.x;
var height = sr.sprite.bounds.size.y;
@@ -45,22 +45,25 @@ public class LevelScrolling : MonoBehaviour var finalHeight = (float)(worldScreenHeight / height);
var finalWidth = (float)(worldScreenWidth / width);
- background.localScale = new Vector3(finalHeight, finalHeight, 1);
+ Background.localScale = new Vector3(finalHeight, finalHeight, 1);
var viewportX = Camera.main.ViewportToWorldPoint(new Vector3(0, 1, 0)).x;
- background.position = new Vector3(viewportX * -1, 0, 0);
- initialBgPos = background.position;
+ Background.position = new Vector3(viewportX * -1, 0, 0);
+ initialBgPos = Background.position;
}
private void MoveObstacles()
{
- obstacles.Translate(new Vector2(0.1f * updateRate, 0));
+ foreach (var o in Obstacles)
+ {
+ o.Translate(new Vector2(0.01f * UpdateRate, 0));
+ }
}
private void MoveBackground()
{
- if (background.position.x > -initialBgPos.x)
- background.Translate(new Vector2(0.1f * updateRate, 0));
- else background.position = initialBgPos;
+ if (Background.position.x > -initialBgPos.x)
+ Background.Translate(new Vector2(0.01f * UpdateRate, 0));
+ else Background.position = initialBgPos;
}
}
diff --git a/nGJ2019/Assets/Scripts/ObstacleSpawner.cs b/nGJ2019/Assets/Scripts/ObstacleSpawner.cs index d007513..7be5b33 100644 --- a/nGJ2019/Assets/Scripts/ObstacleSpawner.cs +++ b/nGJ2019/Assets/Scripts/ObstacleSpawner.cs @@ -8,6 +8,7 @@ public class ObstacleSpawner : MonoBehaviour public GameObject alfaPrefab; public GameObject betaPrefab; + public LevelScrolling scrolling; public float spawnLine; @@ -21,15 +22,16 @@ public class ObstacleSpawner : MonoBehaviour if(e.type == EventTimeline.SpawnEventType.beta) prefab = betaPrefab; - Instantiate(prefab, new Vector3(spawnLine, e.height, 0), Quaternion.identity); + var transformT = ((GameObject) Instantiate(prefab, new Vector3(spawnLine, e.height, 0), Quaternion.identity)).transform; + scrolling.Obstacles.Add(transformT); } void Start() { - timeline.Add(2, 2, EventTimeline.SpawnEventType.alfa); - timeline.Add(4, 2, EventTimeline.SpawnEventType.beta); - timeline.Add(5, -2, EventTimeline.SpawnEventType.beta); - timeline.Add(7, -3, EventTimeline.SpawnEventType.alfa); + for(int i = 0; i < 120; i += 5) + { + timeline.Add(i, 0, EventTimeline.SpawnEventType.alfa); + } timeline.OnSpawnEvent += spawnOnEvent; } |