From 316c17c945b9133aa1094edf6de5c5f38e456d3c Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Sat, 27 Apr 2019 14:32:46 +0200 Subject: Added basic obstacles --- nGJ2019/Assets/Scripts/DragonMovement.cs | 2 +- nGJ2019/Assets/Scripts/ObstacleSpawner.cs | 91 ++++++++++++++++++------------- nGJ2019/Assets/Scripts/ObstacleType.cs | 2 +- 3 files changed, 55 insertions(+), 40 deletions(-) (limited to 'nGJ2019/Assets/Scripts') diff --git a/nGJ2019/Assets/Scripts/DragonMovement.cs b/nGJ2019/Assets/Scripts/DragonMovement.cs index 4ba179d..9ae8fbb 100644 --- a/nGJ2019/Assets/Scripts/DragonMovement.cs +++ b/nGJ2019/Assets/Scripts/DragonMovement.cs @@ -205,7 +205,7 @@ public class DragonMovement : MonoBehaviour EnemyCollider enemy = other.gameObject.GetComponent(); if(enemy != null) { - Debug.Log(enemy.type == ObstacleType.alfa ? "alfa hit" : "beta hit"); + Debug.Log(enemy.type == ObstacleType.narrowPassage ? "alfa hit" : "beta hit"); healthBar.health--; } } diff --git a/nGJ2019/Assets/Scripts/ObstacleSpawner.cs b/nGJ2019/Assets/Scripts/ObstacleSpawner.cs index 102df97..a9d1078 100644 --- a/nGJ2019/Assets/Scripts/ObstacleSpawner.cs +++ b/nGJ2019/Assets/Scripts/ObstacleSpawner.cs @@ -4,47 +4,62 @@ using UnityEngine; public class ObstacleSpawner : MonoBehaviour { - private EventTimeline timeline = new EventTimeline(); - - public GameObject alfaPrefab; - public GameObject betaPrefab; - public LevelScrolling scrolling; - - public float spawnLine; - - private void spawnOnEvent(EventTimeline.SpawnEvent e) - { - GameObject prefab = null; - - if(e.type == ObstacleType.alfa) - prefab = alfaPrefab; - - if(e.type == ObstacleType.beta) - prefab = betaPrefab; - - var transformT = ((GameObject) Instantiate(prefab, new Vector3(spawnLine, e.height, 0), Quaternion.identity)).transform; - scrolling.Obstacles.Add(transformT); - } - - void Start() + private EventTimeline timeline = new EventTimeline(); + + public GameObject caveWallsPrefab, rockTopPrefab, rockBottomPrefab, narrowPassagePrefab, rockJawsPrefab; + public LevelScrolling scrolling; + + public float spawnLine; + + private void spawnOnEvent(EventTimeline.SpawnEvent e) + { + GameObject prefab = null; + + switch (e.type) { - for(int i = 0; i < 120; i += 5) - { - timeline.Add(i, 0, ObstacleType.alfa); - } - - timeline.OnSpawnEvent += spawnOnEvent; + 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; } - // Update is called once per frame - void Update() + var transformT = ((GameObject)Instantiate(prefab, new Vector3(spawnLine, e.height, 0), Quaternion.identity)).transform; + scrolling.Obstacles.Add(transformT); + } + + void Start() + { + for (int i = 0; i < 120; i += 5) { - timeline.timeTick(Time.deltaTime); + timeline.Add(i, 0, ObstacleType.caveWalls); } - - void OnDrawGizmosSelected() - { - Gizmos.color = Color.green; - Gizmos.DrawLine(new Vector3(spawnLine,-10,0), new Vector3(spawnLine,10,0)); - } + timeline.Add(2, 2.75f, ObstacleType.rockTop); + timeline.Add(8, -2, ObstacleType.rockBottom); + timeline.Add(20, 0, ObstacleType.narrowPassage); + + timeline.OnSpawnEvent += spawnOnEvent; + } + + // 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)); + } } diff --git a/nGJ2019/Assets/Scripts/ObstacleType.cs b/nGJ2019/Assets/Scripts/ObstacleType.cs index c62f629..79a4980 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 {alfa, beta} +public enum ObstacleType { caveWalls, rockTop, rockBottom, narrowPassage, rockJaws } -- cgit v1.2.3 From 9222754ebc29c533d70c283896895dfb852c3cdc Mon Sep 17 00:00:00 2001 From: Mikkel Bybjerg Date: Sat, 27 Apr 2019 14:41:12 +0200 Subject: merge --- nGJ2019/Assets/Scripts/DragonMovement.cs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'nGJ2019/Assets/Scripts') diff --git a/nGJ2019/Assets/Scripts/DragonMovement.cs b/nGJ2019/Assets/Scripts/DragonMovement.cs index 4ba179d..24b6666 100644 --- a/nGJ2019/Assets/Scripts/DragonMovement.cs +++ b/nGJ2019/Assets/Scripts/DragonMovement.cs @@ -169,6 +169,7 @@ public class DragonMovement : MonoBehaviour void Update() { + // keyboard scheme if(Input.GetKey("w")) moveUp(); if(Input.GetKey("a")) @@ -192,6 +193,32 @@ public class DragonMovement : MonoBehaviour turnSpread(); if(Input.GetKeyUp("k")) turnAntiSpread(); + + + // xbox scheme + if(Input.GetAxis("JoystickY") > 0.5f) + moveUp(); + if(Input.GetAxis("JoystickX") < -0.5f) + moveLeft(); + if(Input.GetAxis("JoystickY") < -0.5f) + moveDown(); + if(Input.GetAxis("JoystickX") > 0.5f) + moveRight(); + + if(Input.GetButtonDown("X")) + turnSwirl(); + if(Input.GetButtonUp("X")) + turnAntiSwirl(); + + if(Input.GetButtonDown("A")) + turnSlim(); + if(Input.GetButtonUp("A")) + turnAntiSlim(); + + if(Input.GetButtonDown("Y")) + turnSpread(); + if(Input.GetButtonUp("Y")) + turnAntiSpread(); } void OnDrawGizmosSelected() @@ -205,7 +232,7 @@ public class DragonMovement : MonoBehaviour EnemyCollider enemy = other.gameObject.GetComponent(); if(enemy != null) { - Debug.Log(enemy.type == ObstacleType.alfa ? "alfa hit" : "beta hit"); + //Debug.Log(enemy.type == ObstacleType.alfa ? "alfa hit" : "beta hit"); healthBar.health--; } } -- cgit v1.2.3 From 0cfee1d1f1a2a06c86080f62ce26a3eabe6b5ffd Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Sat, 27 Apr 2019 14:59:32 +0200 Subject: Refactoring --- nGJ2019/Assets/Scripts/LevelScrolling.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'nGJ2019/Assets/Scripts') diff --git a/nGJ2019/Assets/Scripts/LevelScrolling.cs b/nGJ2019/Assets/Scripts/LevelScrolling.cs index 025bf40..0122a69 100644 --- a/nGJ2019/Assets/Scripts/LevelScrolling.cs +++ b/nGJ2019/Assets/Scripts/LevelScrolling.cs @@ -4,7 +4,7 @@ using UnityEngine; public class LevelScrolling : MonoBehaviour { - public int UpdateRate = 1; + public int UpdateRate = -5; public List Obstacles; public Transform Background; @@ -56,14 +56,14 @@ public class LevelScrolling : MonoBehaviour { foreach (var o in Obstacles) { - o.Translate(new Vector2(0.01f * UpdateRate, 0)); + o.Translate(0.01f * UpdateRate, 0, 0); } } private void MoveBackground() { if (Background.position.x > -initialBgPos.x) - Background.Translate(new Vector2(0.01f * UpdateRate, 0)); + Background.Translate(0.01f * UpdateRate, 0, 0); else Background.position = initialBgPos; } } -- cgit v1.2.3 From 7539e35ce26437c5aa0325936dea68132408c8b0 Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Sat, 27 Apr 2019 15:23:18 +0200 Subject: Added rock jaws obstacle --- nGJ2019/Assets/Scripts/ObstacleSpawner.cs | 1 + nGJ2019/Assets/Scripts/RockJaws.cs | 37 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 nGJ2019/Assets/Scripts/RockJaws.cs (limited to 'nGJ2019/Assets/Scripts') diff --git a/nGJ2019/Assets/Scripts/ObstacleSpawner.cs b/nGJ2019/Assets/Scripts/ObstacleSpawner.cs index a9d1078..c285352 100644 --- a/nGJ2019/Assets/Scripts/ObstacleSpawner.cs +++ b/nGJ2019/Assets/Scripts/ObstacleSpawner.cs @@ -47,6 +47,7 @@ public class ObstacleSpawner : MonoBehaviour 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; } diff --git a/nGJ2019/Assets/Scripts/RockJaws.cs b/nGJ2019/Assets/Scripts/RockJaws.cs new file mode 100644 index 0000000..a161dfe --- /dev/null +++ b/nGJ2019/Assets/Scripts/RockJaws.cs @@ -0,0 +1,37 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class RockJaws : MonoBehaviour +{ + public Transform TopJaw; + public Transform BottomJaw; + public int Speed = 10; + private bool reverse = false; + private float initialTopJawY; + // Start is called before the first frame update + void Start() + { + initialTopJawY = TopJaw.localPosition.y; + } + + // Update is called once per frame + void Update() + { + + } + + void FixedUpdate() + { + if (TopJaw.localPosition.y < BottomJaw.localPosition.y) reverse = true; + else if(TopJaw.localPosition.y > initialTopJawY) reverse = false; + + if (!reverse) { + TopJaw.Translate(0, -0.01f * Speed, 0); + BottomJaw.Translate(0, 0.01f * Speed, 0); + } else { + TopJaw.Translate(0, 0.01f * Speed, 0); + BottomJaw.Translate(0, -0.01f * Speed, 0); + } + } +} -- cgit v1.2.3 From 29ea8fd1b67042ced673a3e53c12823d8aee2783 Mon Sep 17 00:00:00 2001 From: Mikkel Bybjerg Date: Sat, 27 Apr 2019 16:31:32 +0200 Subject: xbox control scheme --- nGJ2019/Assets/Scripts/DragonMovement.cs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'nGJ2019/Assets/Scripts') diff --git a/nGJ2019/Assets/Scripts/DragonMovement.cs b/nGJ2019/Assets/Scripts/DragonMovement.cs index f2c1cb5..f3ae1d5 100644 --- a/nGJ2019/Assets/Scripts/DragonMovement.cs +++ b/nGJ2019/Assets/Scripts/DragonMovement.cs @@ -14,6 +14,8 @@ public class DragonMovement : MonoBehaviour public HealthBar healthBar; + private float hurtCooldown = 0; + private SwarmSystem swarm; private enum State {normal, swirl, slim, spread}; @@ -169,6 +171,9 @@ public class DragonMovement : MonoBehaviour void Update() { + if(hurtCooldown < 0) + hurtCooldown -= Time.deltaTime; + // keyboard scheme if(Input.GetKey("w")) moveUp(); @@ -196,11 +201,11 @@ public class DragonMovement : MonoBehaviour // xbox scheme - if(Input.GetAxis("JoystickY") > 0.5f) + if(Input.GetAxis("JoystickY") < -0.5f) moveUp(); if(Input.GetAxis("JoystickX") < -0.5f) moveLeft(); - if(Input.GetAxis("JoystickY") < -0.5f) + if(Input.GetAxis("JoystickY") > 0.5f) moveDown(); if(Input.GetAxis("JoystickX") > 0.5f) moveRight(); @@ -227,12 +232,21 @@ public class DragonMovement : MonoBehaviour Gizmos.DrawWireCube(Vector3.zero, new Vector3(2*horizontalBound, 2*verticalBound, 0)); } + private void getHurt() + { + if(hurtCooldown <= 0) + { + healthBar.health--; + hurtCooldown = 3; + } + } + void OnTriggerEnter(Collider other) { EnemyCollider enemy = other.gameObject.GetComponent(); if(enemy != null) { - healthBar.health--; + getHurt(); } } -- cgit v1.2.3 From 19d32b28f4888407a5c06ed84a751a2c35691d2b Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Sat, 27 Apr 2019 18:00:48 +0200 Subject: Added messaging --- nGJ2019/Assets/Scripts/EventTimeline.cs | 28 +++++++++++++++++++++++++- nGJ2019/Assets/Scripts/Messenger.cs | 33 +++++++++++++++++++++++++++++++ nGJ2019/Assets/Scripts/ObstacleSpawner.cs | 6 ++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 nGJ2019/Assets/Scripts/Messenger.cs (limited to 'nGJ2019/Assets/Scripts') diff --git a/nGJ2019/Assets/Scripts/EventTimeline.cs b/nGJ2019/Assets/Scripts/EventTimeline.cs index 21b0bdb..b864ae7 100644 --- a/nGJ2019/Assets/Scripts/EventTimeline.cs +++ b/nGJ2019/Assets/Scripts/EventTimeline.cs @@ -17,15 +17,30 @@ public class EventTimeline this.type = type; } } + + public class MessageEvent + { + public float time; + public String message; + + public MessageEvent(float time, String message) + { + this.time = time; + this.message = message; + } + } public event Action OnSpawnEvent; + public event Action OnMessageEvent; private List futureEvents; + private List futureMessages; private float currentTime; public EventTimeline() { futureEvents = new List(); + futureMessages = new List(); currentTime = 0; } @@ -34,17 +49,28 @@ public class EventTimeline futureEvents.Add(new SpawnEvent(time, height, type)); futureEvents.Sort((x,y) => x.time.CompareTo(y.time)); } + + public void Add(float time, String message) + { + futureMessages.Add(new MessageEvent(time, message)); + futureMessages.Sort((x,y) => x.time.CompareTo(y.time)); + } public void timeTick(float deltaTime) { currentTime += deltaTime; - while(futureEvents.Count > 0 && currentTime > futureEvents[0].time) + while(futureEvents.Count > 0 && currentTime > futureEvents[0].time && futureMessages.Count > 0 && currentTime > futureMessages[0].time) { SpawnEvent e = futureEvents[0]; futureEvents.RemoveAt(0); if(OnSpawnEvent != null) OnSpawnEvent(e); + + MessageEvent m = futureMessages[0]; + futureMessages.RemoveAt(0); + if(OnMessageEvent != null) + OnMessageEvent(m); } } } diff --git a/nGJ2019/Assets/Scripts/Messenger.cs b/nGJ2019/Assets/Scripts/Messenger.cs new file mode 100644 index 0000000..ca2ffe1 --- /dev/null +++ b/nGJ2019/Assets/Scripts/Messenger.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +public class Messenger : MonoBehaviour +{ + public Text MainText; + public ObstacleSpawner Spawner; + private EventTimeline timeline; + + // Start is called before the first frame update + void Start() + { + timeline = Spawner.GetEventTimeline(); + + timeline.Add(1, "Test"); + + timeline.OnMessageEvent += MessageOnEvent; + } + + // Update is called once per frame + void Update() + { + + } + + void MessageOnEvent(EventTimeline.MessageEvent e) + { + MainText.text = e.message; + } +} diff --git a/nGJ2019/Assets/Scripts/ObstacleSpawner.cs b/nGJ2019/Assets/Scripts/ObstacleSpawner.cs index c285352..f438e85 100644 --- a/nGJ2019/Assets/Scripts/ObstacleSpawner.cs +++ b/nGJ2019/Assets/Scripts/ObstacleSpawner.cs @@ -8,6 +8,7 @@ public class ObstacleSpawner : MonoBehaviour public GameObject caveWallsPrefab, rockTopPrefab, rockBottomPrefab, narrowPassagePrefab, rockJawsPrefab; public LevelScrolling scrolling; + public Messenger messenger; public float spawnLine; @@ -63,4 +64,9 @@ public class ObstacleSpawner : MonoBehaviour Gizmos.color = Color.green; Gizmos.DrawLine(new Vector3(spawnLine, -10, 0), new Vector3(spawnLine, 10, 0)); } + + public EventTimeline GetEventTimeline() + { + return timeline; + } } -- cgit v1.2.3