aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Assets/Scripts/Controllers
diff options
context:
space:
mode:
authorCarson Katri <carson.katri@gmail.com>2021-06-12 00:30:21 -0400
committerCarson Katri <carson.katri@gmail.com>2021-06-12 00:30:21 -0400
commitff111d95db1878f9c35d99e7d4fa0b4d9a0de37c (patch)
treea7d55973657e37405eea64178f86556f585d5f30 /Assets/Scripts/Controllers
parentae62fd809cfc5545de37c6bee0ba759402bba3fe (diff)
downloadgmtk-gamejam-ff111d95db1878f9c35d99e7d4fa0b4d9a0de37c.tar.gz
gmtk-gamejam-ff111d95db1878f9c35d99e7d4fa0b4d9a0de37c.tar.zst
gmtk-gamejam-ff111d95db1878f9c35d99e7d4fa0b4d9a0de37c.zip
Restructure scripts, improve locomotion, and add movement indicators
Diffstat (limited to 'Assets/Scripts/Controllers')
-rw-r--r--Assets/Scripts/Controllers/AIController.cs19
-rw-r--r--Assets/Scripts/Controllers/AIController.cs.meta3
-rw-r--r--Assets/Scripts/Controllers/CameraController.cs14
-rw-r--r--Assets/Scripts/Controllers/CameraController.cs.meta11
-rw-r--r--Assets/Scripts/Controllers/Player.meta3
-rw-r--r--Assets/Scripts/Controllers/Player/PlayerController.cs75
-rw-r--r--Assets/Scripts/Controllers/Player/PlayerController.cs.meta11
-rw-r--r--Assets/Scripts/Controllers/Player/PlayerSegment.cs28
-rw-r--r--Assets/Scripts/Controllers/Player/PlayerSegment.cs.meta3
9 files changed, 167 insertions, 0 deletions
diff --git a/Assets/Scripts/Controllers/AIController.cs b/Assets/Scripts/Controllers/AIController.cs
new file mode 100644
index 0000000..9f115c2
--- /dev/null
+++ b/Assets/Scripts/Controllers/AIController.cs
@@ -0,0 +1,19 @@
+using UnityEngine;
+
+namespace Controllers
+{
+ public class AIController : MonoBehaviour
+ {
+ private void Update()
+ {
+ if (Input.GetKey(KeyCode.H))
+ {
+ transform.position += Vector3.right * 0.01f;
+ }
+ else if (Input.GetKey(KeyCode.F))
+ {
+ transform.position += Vector3.left * 0.01f;
+ }
+ }
+ }
+}
diff --git a/Assets/Scripts/Controllers/AIController.cs.meta b/Assets/Scripts/Controllers/AIController.cs.meta
new file mode 100644
index 0000000..a64fd78
--- /dev/null
+++ b/Assets/Scripts/Controllers/AIController.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: bc5bf022ed0c4bfcaae099b96eecf645
+timeCreated: 1623461478 \ No newline at end of file
diff --git a/Assets/Scripts/Controllers/CameraController.cs b/Assets/Scripts/Controllers/CameraController.cs
new file mode 100644
index 0000000..a72b2f4
--- /dev/null
+++ b/Assets/Scripts/Controllers/CameraController.cs
@@ -0,0 +1,14 @@
+using UnityEngine;
+
+namespace Controllers
+{
+ public class CameraController : MonoBehaviour
+ {
+ [SerializeField] private Transform target;
+
+ private void Update()
+ {
+ transform.position = new Vector3(target.transform.position.x, target.transform.position.y, -10f);
+ }
+ }
+}
diff --git a/Assets/Scripts/Controllers/CameraController.cs.meta b/Assets/Scripts/Controllers/CameraController.cs.meta
new file mode 100644
index 0000000..993e111
--- /dev/null
+++ b/Assets/Scripts/Controllers/CameraController.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: cb9598def536949fe9305920b43a1874
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/Controllers/Player.meta b/Assets/Scripts/Controllers/Player.meta
new file mode 100644
index 0000000..969fc57
--- /dev/null
+++ b/Assets/Scripts/Controllers/Player.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 5048baca0abc4e02a20e35db55394c74
+timeCreated: 1623470798 \ No newline at end of file
diff --git a/Assets/Scripts/Controllers/Player/PlayerController.cs b/Assets/Scripts/Controllers/Player/PlayerController.cs
new file mode 100644
index 0000000..c5cfc3d
--- /dev/null
+++ b/Assets/Scripts/Controllers/Player/PlayerController.cs
@@ -0,0 +1,75 @@
+using System.Linq;
+using Controllers.Player;
+using UnityEngine;
+
+namespace Controllers.Player
+{
+ public class PlayerController : MonoBehaviour
+ {
+ [SerializeField] private PlayerSegment[] segments;
+ [SerializeField] private float sensitivity;
+ [SerializeField] private float verticalSensitivity;
+
+ [SerializeField] private Rigidbody2D ballPrefab;
+ [SerializeField] private float ballSpeed;
+
+ private void Update()
+ {
+ for (var i = 0; i < segments.Length; i++)
+ {
+ var segment = segments[i];
+ var isRoot = i == 0;
+
+ // Update icons
+ foreach (var control in new[] {segment.left, segment.right})
+ {
+ if (Input.GetKeyDown(control.keyCode))
+ control.icon.SetActive(true);
+ else if (Input.GetKeyUp(control.keyCode))
+ control.icon.SetActive(false);
+ }
+
+ // Add forces
+ if (Input.GetKey(segment.left.keyCode))
+ segment.Rigidbody.AddForceAtPosition(Vector2.left * (sensitivity * (isRoot ? 2f : 1f)) + Vector2.up * (verticalSensitivity * (isRoot ? -1f : 1f)), segment.transform.position + (segment.Sprite.bounds.size.y * segment.forceOrigin));
+ if (Input.GetKey(segment.right.keyCode))
+ segment.Rigidbody.AddForceAtPosition(Vector2.right * (sensitivity * (isRoot ? 2f : 1f)) + Vector2.up * (verticalSensitivity * (isRoot ? -1f : 1f)), segment.transform.position + (segment.Sprite.bounds.size.y * segment.forceOrigin));
+ }
+
+ // if (Input.GetKey(KeyCode.D))
+ // {
+ // segments[0].AddForceAtPosition(Vector2.right * sensitivity, (Vector2)segments[0].transform.position - Vector2.up * 0.5f);
+ // }
+ // else if (Input.GetKey(KeyCode.A))
+ // {
+ // segments[0].AddForceAtPosition(Vector2.left * sensitivity, (Vector2)segments[0].transform.position - Vector2.up * 0.5f);
+ // }
+ //
+ // if (Input.GetKey(KeyCode.L))
+ // {
+ // segments[1].AddForceAtPosition(Vector2.right * sensitivity, (Vector2)segments[1].transform.position + Vector2.up * 0.5f);
+ // }
+ // else if (Input.GetKey(KeyCode.J))
+ // {
+ // segments[1].AddForceAtPosition(Vector2.left * sensitivity, (Vector2)segments[1].transform.position + Vector2.up * 0.5f);
+ // }
+ //
+ // if (Input.GetKey(KeyCode.RightArrow))
+ // {
+ // segments[2].AddForceAtPosition(Vector2.right * sensitivity, (Vector2)segments[2].transform.position + Vector2.up * 0.5f);
+ // }
+ // else if (Input.GetKey(KeyCode.LeftArrow))
+ // {
+ // segments[2].AddForceAtPosition(Vector2.left * sensitivity, (Vector2)segments[2].transform.position + Vector2.up * 0.5f);
+ // }
+ //
+ if (Input.GetKeyDown(KeyCode.Space))
+ {
+ var ball = Instantiate(ballPrefab);
+ var lastSegment = segments.Last();
+ ball.transform.position = lastSegment.transform.position;
+ ball.AddForce((lastSegment.transform.right + lastSegment.transform.up) * ballSpeed);
+ }
+ }
+ }
+}
diff --git a/Assets/Scripts/Controllers/Player/PlayerController.cs.meta b/Assets/Scripts/Controllers/Player/PlayerController.cs.meta
new file mode 100644
index 0000000..8a5b37d
--- /dev/null
+++ b/Assets/Scripts/Controllers/Player/PlayerController.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 261cc3206075846ebbd03b8896e7c733
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/Controllers/Player/PlayerSegment.cs b/Assets/Scripts/Controllers/Player/PlayerSegment.cs
new file mode 100644
index 0000000..6306201
--- /dev/null
+++ b/Assets/Scripts/Controllers/Player/PlayerSegment.cs
@@ -0,0 +1,28 @@
+using System;
+using UnityEngine;
+
+namespace Controllers.Player
+{
+ [RequireComponent(typeof(Rigidbody2D))]
+ [RequireComponent(typeof(SpriteRenderer))]
+ public class PlayerSegment : MonoBehaviour
+ {
+ [SerializeField] public Control left;
+ [SerializeField] public Control right;
+
+ [SerializeField] public Vector3 forceOrigin;
+
+ public Rigidbody2D Rigidbody => _rigidbody != null ? _rigidbody : _rigidbody = GetComponent<Rigidbody2D>();
+ private Rigidbody2D _rigidbody;
+
+ public SpriteRenderer Sprite => _sprite != null ? _sprite : _sprite = GetComponent<SpriteRenderer>();
+ private SpriteRenderer _sprite;
+ }
+
+ [Serializable]
+ public struct Control
+ {
+ public KeyCode keyCode;
+ public GameObject icon;
+ }
+}
diff --git a/Assets/Scripts/Controllers/Player/PlayerSegment.cs.meta b/Assets/Scripts/Controllers/Player/PlayerSegment.cs.meta
new file mode 100644
index 0000000..915819f
--- /dev/null
+++ b/Assets/Scripts/Controllers/Player/PlayerSegment.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 99303295fe534f42863cd15bf22587f9
+timeCreated: 1623470806 \ No newline at end of file