aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Assets/Scripts
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
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')
-rw-r--r--Assets/Scripts/AIController.cs16
-rw-r--r--Assets/Scripts/Controllers.meta3
-rw-r--r--Assets/Scripts/Controllers/AIController.cs19
-rw-r--r--Assets/Scripts/Controllers/AIController.cs.meta (renamed from Assets/Scripts/AIController.cs.meta)0
-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.meta (renamed from Assets/Scripts/PlayerController.cs.meta)0
-rw-r--r--Assets/Scripts/Controllers/Player/PlayerSegment.cs28
-rw-r--r--Assets/Scripts/Controllers/Player/PlayerSegment.cs.meta3
-rw-r--r--Assets/Scripts/PlayerController.cs51
12 files changed, 156 insertions, 67 deletions
diff --git a/Assets/Scripts/AIController.cs b/Assets/Scripts/AIController.cs
deleted file mode 100644
index 9cb20fb..0000000
--- a/Assets/Scripts/AIController.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using UnityEngine;
-
-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;
- }
- }
-} \ No newline at end of file
diff --git a/Assets/Scripts/Controllers.meta b/Assets/Scripts/Controllers.meta
new file mode 100644
index 0000000..8f91366
--- /dev/null
+++ b/Assets/Scripts/Controllers.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 62c7deb7956f4aa1a8b47e1601df4173
+timeCreated: 1623470772 \ No newline at end of file
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/AIController.cs.meta b/Assets/Scripts/Controllers/AIController.cs.meta
index a64fd78..a64fd78 100644
--- a/Assets/Scripts/AIController.cs.meta
+++ b/Assets/Scripts/Controllers/AIController.cs.meta
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/PlayerController.cs.meta b/Assets/Scripts/Controllers/Player/PlayerController.cs.meta
index 8a5b37d..8a5b37d 100644
--- a/Assets/Scripts/PlayerController.cs.meta
+++ b/Assets/Scripts/Controllers/Player/PlayerController.cs.meta
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
diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs
deleted file mode 100644
index 22ce225..0000000
--- a/Assets/Scripts/PlayerController.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Linq;
-using UnityEngine;
-
-public class PlayerController : MonoBehaviour
-{
- [SerializeField] private List<Rigidbody2D> segments;
- [SerializeField] private float sensitivity;
-
- [SerializeField] private Rigidbody2D ballPrefab;
- [SerializeField] private float ballSpeed;
-
- private void Update()
- {
- 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);
- ball.transform.position = segments.Last().position;
- ball.AddForce((Vector2.right + Vector2.up) * ballSpeed);
- }
- }
-}