diff options
author | miakata <miakata@gmail.com> | 2019-04-27 22:51:19 +0200 |
---|---|---|
committer | miakata <miakata@gmail.com> | 2019-04-27 22:51:19 +0200 |
commit | 87c702bbff7e39066c1aea6ed40c46a961a022d4 (patch) | |
tree | 74324c7f9dcfdd75fec8f66b1df0557799f3e9d4 /nGJ2019/Assets/Scripts | |
parent | c34eb93d97ae8dcb51ef88dc9ddae5b40c81783e (diff) | |
parent | 932a418c3f2251d434b67d115aaa380b51685ef7 (diff) |
Merge branch 'master' of https://github.com/marcinzelent/ngj2019
Diffstat (limited to 'nGJ2019/Assets/Scripts')
-rw-r--r-- | nGJ2019/Assets/Scripts/EventTimeline.cs | 11 | ||||
-rw-r--r-- | nGJ2019/Assets/Scripts/LevelScrolling.cs | 4 | ||||
-rw-r--r-- | nGJ2019/Assets/Scripts/ObstacleSpawner.cs | 110 | ||||
-rw-r--r-- | nGJ2019/Assets/Scripts/ObstacleType.cs | 2 |
4 files changed, 66 insertions, 61 deletions
diff --git a/nGJ2019/Assets/Scripts/EventTimeline.cs b/nGJ2019/Assets/Scripts/EventTimeline.cs index 18b87cc..465815c 100644 --- a/nGJ2019/Assets/Scripts/EventTimeline.cs +++ b/nGJ2019/Assets/Scripts/EventTimeline.cs @@ -1,19 +1,20 @@ using System; using System.Collections; using System.Collections.Generic; +using UnityEngine; public class EventTimeline { public class SpawnEvent { public float time; - public float height; + public Vector3 position; public ObstacleType type; - public SpawnEvent(float time, float height, ObstacleType type) + public SpawnEvent(float time, Vector3 position, ObstacleType type) { this.time = time; - this.height = height; + this.position = position; this.type = type; } } @@ -44,9 +45,9 @@ public class EventTimeline currentTime = 0; } - public void Add(float time, float height, ObstacleType type) + public void Add(float time, Vector3 position, ObstacleType type) { - futureEvents.Add(new SpawnEvent(time, height, type)); + futureEvents.Add(new SpawnEvent(time, position, type)); futureEvents.Sort((x,y) => x.time.CompareTo(y.time)); } diff --git a/nGJ2019/Assets/Scripts/LevelScrolling.cs b/nGJ2019/Assets/Scripts/LevelScrolling.cs index fac0a13..7ca89e3 100644 --- a/nGJ2019/Assets/Scripts/LevelScrolling.cs +++ b/nGJ2019/Assets/Scripts/LevelScrolling.cs @@ -49,7 +49,7 @@ public class LevelScrolling : MonoBehaviour 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);
+ Background.position = new Vector3(viewportX * -1, 0, 10);
initialBgPos = Background.position;
}
@@ -63,7 +63,7 @@ public class LevelScrolling : MonoBehaviour void DestroyObstacles()
{
- if (Obstacles[0].transform.position.x < -30)
+ if (Obstacles.Count > 0 && Obstacles[0].transform.position.x < -30)
{
Destroy(Obstacles[0]);
Obstacles.RemoveAt(0);
diff --git a/nGJ2019/Assets/Scripts/ObstacleSpawner.cs b/nGJ2019/Assets/Scripts/ObstacleSpawner.cs index 0e6b3ac..1615714 100644 --- a/nGJ2019/Assets/Scripts/ObstacleSpawner.cs +++ b/nGJ2019/Assets/Scripts/ObstacleSpawner.cs @@ -4,68 +4,72 @@ using UnityEngine; public class ObstacleSpawner : MonoBehaviour { - private EventTimeline timeline = new EventTimeline(); + private EventTimeline timeline = new EventTimeline(); - public GameObject caveWallsPrefab, rockTopPrefab, rockBottomPrefab, narrowPassagePrefab, rockJawsPrefab; - public LevelScrolling scrolling; + public GameObject caveWallsPrefab, rockTopPrefab, rockBottomPrefab, narrowPassagePrefab, rockJawsPrefab, netPrefab; + public LevelScrolling scrolling; - public float spawnLine; + public float spawnLine; - private void spawnOnEvent(EventTimeline.SpawnEvent e) - { - GameObject prefab = null; - - switch (e.type) + private void spawnOnEvent(EventTimeline.SpawnEvent e) { - case ObstacleType.caveWalls: - prefab = caveWallsPrefab; - break; - case ObstacleType.rockTop: - prefab = rockTopPrefab; - break; - case ObstacleType.rockBottom: - prefab = rockBottomPrefab; - break; - case ObstacleType.narrowPassage: - prefab = narrowPassagePrefab; - break; - case ObstacleType.rockJaws: - prefab = rockJawsPrefab; - break; - } + GameObject prefab = null; - var o = Instantiate(prefab, new Vector3(spawnLine, e.height, 0), Quaternion.identity); - scrolling.Obstacles.Add(o); - } + switch (e.type) + { + case ObstacleType.caveWalls: + prefab = caveWallsPrefab; + break; + case ObstacleType.rockTop: + prefab = rockTopPrefab; + break; + case ObstacleType.rockBottom: + prefab = rockBottomPrefab; + break; + case ObstacleType.narrowPassage: + prefab = narrowPassagePrefab; + break; + case ObstacleType.rockJaws: + prefab = rockJawsPrefab; + break; + case ObstacleType.net: + prefab = netPrefab; + break; + } - void Start() - { - for (int i = 0; i < 120; i += 5) - { - timeline.Add(i, 0, ObstacleType.caveWalls); + var o = Instantiate(prefab, new Vector3(spawnLine, e.position.y, e.position.z), Quaternion.identity); + scrolling.Obstacles.Add(o); } - timeline.Add(2, 2.75f, ObstacleType.rockTop); - timeline.Add(8, -2, ObstacleType.rockBottom); - timeline.Add(20, 0, ObstacleType.narrowPassage); - timeline.Add(30, 0, ObstacleType.rockJaws); - timeline.OnSpawnEvent += spawnOnEvent; - } + void Start() + { + for (int i = 0; i < 120; i += 5) + { + timeline.Add(i, new Vector3(0, 0, 0), ObstacleType.caveWalls); + } + timeline.Add(0, new Vector3(0, 2.75f, 0), ObstacleType.rockTop); + timeline.Add(6, new Vector3(0, -2, 0), ObstacleType.rockBottom); + timeline.Add(12, new Vector3(0, 0, 0), ObstacleType.narrowPassage); + timeline.Add(20, new Vector3(0, 0, 2), ObstacleType.rockJaws); + timeline.Add(25, new Vector3(0, 0.5f, 3), ObstacleType.net); + + timeline.OnSpawnEvent += spawnOnEvent; + } - // Update is called once per frame - void Update() - { - timeline.timeTick(Time.deltaTime); - } + // Update is called once per frame + void Update() + { + timeline.timeTick(Time.deltaTime); + } - void OnDrawGizmosSelected() - { - Gizmos.color = Color.green; - Gizmos.DrawLine(new Vector3(spawnLine, -10, 0), new Vector3(spawnLine, 10, 0)); - } + void OnDrawGizmosSelected() + { + Gizmos.color = Color.green; + Gizmos.DrawLine(new Vector3(spawnLine, -10, 0), new Vector3(spawnLine, 10, 0)); + } - public EventTimeline GetEventTimeline() - { - return timeline; - } + public EventTimeline GetEventTimeline() + { + return timeline; + } } diff --git a/nGJ2019/Assets/Scripts/ObstacleType.cs b/nGJ2019/Assets/Scripts/ObstacleType.cs index 79a4980..c97a2ed 100644 --- a/nGJ2019/Assets/Scripts/ObstacleType.cs +++ b/nGJ2019/Assets/Scripts/ObstacleType.cs @@ -2,4 +2,4 @@ using System.Collections.Generic; using UnityEngine; -public enum ObstacleType { caveWalls, rockTop, rockBottom, narrowPassage, rockJaws } +public enum ObstacleType { caveWalls, rockTop, rockBottom, narrowPassage, rockJaws, net } |