aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'nGJ2019/Assets/Scripts')
-rw-r--r--nGJ2019/Assets/Scripts/DragonMovement.cs44
-rw-r--r--nGJ2019/Assets/Scripts/EventTimeline.cs28
-rw-r--r--nGJ2019/Assets/Scripts/LevelScrolling.cs6
-rw-r--r--nGJ2019/Assets/Scripts/Messenger.cs33
-rw-r--r--nGJ2019/Assets/Scripts/ObstacleSpawner.cs98
-rw-r--r--nGJ2019/Assets/Scripts/ObstacleType.cs2
-rw-r--r--nGJ2019/Assets/Scripts/RockJaws.cs37
7 files changed, 203 insertions, 45 deletions
diff --git a/nGJ2019/Assets/Scripts/DragonMovement.cs b/nGJ2019/Assets/Scripts/DragonMovement.cs
index 4ba179d..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,10 @@ public class DragonMovement : MonoBehaviour
void Update()
{
+ if(hurtCooldown < 0)
+ hurtCooldown -= Time.deltaTime;
+
+ // keyboard scheme
if(Input.GetKey("w"))
moveUp();
if(Input.GetKey("a"))
@@ -192,6 +198,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()
@@ -200,13 +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<EnemyCollider>();
if(enemy != null)
{
- Debug.Log(enemy.type == ObstacleType.alfa ? "alfa hit" : "beta hit");
- healthBar.health--;
+ getHurt();
}
}
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<SpawnEvent> OnSpawnEvent;
+ public event Action<MessageEvent> OnMessageEvent;
private List<SpawnEvent> futureEvents;
+ private List<MessageEvent> futureMessages;
private float currentTime;
public EventTimeline()
{
futureEvents = new List<SpawnEvent>();
+ futureMessages = new List<MessageEvent>();
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/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<Transform> 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;
}
}
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 102df97..f438e85 100644
--- a/nGJ2019/Assets/Scripts/ObstacleSpawner.cs
+++ b/nGJ2019/Assets/Scripts/ObstacleSpawner.cs
@@ -4,47 +4,69 @@ 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 Messenger messenger;
+
+ 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.Add(30, 0, ObstacleType.rockJaws);
+
+ 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));
+ }
+
+ public EventTimeline GetEventTimeline()
+ {
+ return timeline;
+ }
}
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 }
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);
+ }
+ }
+}