aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Assets/Scripts
diff options
context:
space:
mode:
authorCameron Katri <me@cameronkatri.com>2021-06-13 00:11:14 -0400
committerCameron Katri <me@cameronkatri.com>2021-06-13 00:11:14 -0400
commitb2cb1b8162e404391b2a30b77b2b4c0565adc9c4 (patch)
tree89a2caac46f14e81349021f89562bacdb1d45c8f /Assets/Scripts
parent25192f07018ad142818a87c2aacac1bf0ecdf551 (diff)
parent81dfc0b51dcd0abeae7b47820f54f10050d6a678 (diff)
downloadgmtk-gamejam-b2cb1b8162e404391b2a30b77b2b4c0565adc9c4.tar.gz
gmtk-gamejam-b2cb1b8162e404391b2a30b77b2b4c0565adc9c4.tar.zst
gmtk-gamejam-b2cb1b8162e404391b2a30b77b2b4c0565adc9c4.zip
Merge branch 'master' of git.cameronkatri.com:gmtk-gamejam
Diffstat (limited to 'Assets/Scripts')
-rw-r--r--Assets/Scripts/Controllers/AIController.cs2
-rw-r--r--Assets/Scripts/Controllers/GameController.cs64
-rw-r--r--Assets/Scripts/Controllers/Player/PlayerController.cs2
3 files changed, 68 insertions, 0 deletions
diff --git a/Assets/Scripts/Controllers/AIController.cs b/Assets/Scripts/Controllers/AIController.cs
index 92dc6bc..cdfc9a8 100644
--- a/Assets/Scripts/Controllers/AIController.cs
+++ b/Assets/Scripts/Controllers/AIController.cs
@@ -62,6 +62,8 @@ namespace Controllers
private void Update()
{
+ if (game.freezeMotion) return;
+
var movement = transform.position;
if (!game.enemy.HasBall) // Move towards the ball to grab it.
diff --git a/Assets/Scripts/Controllers/GameController.cs b/Assets/Scripts/Controllers/GameController.cs
index 6ebcabe..303b5a0 100644
--- a/Assets/Scripts/Controllers/GameController.cs
+++ b/Assets/Scripts/Controllers/GameController.cs
@@ -1,4 +1,6 @@
using System;
+using System.Collections;
+using JetBrains.Annotations;
using UnityEngine;
using UnityEngine.UI;
@@ -14,6 +16,8 @@ namespace Controllers
public Player player;
public Player enemy;
+
+ public bool freezeMotion;
private float startTime;
[SerializeField] private float timeLimit;
@@ -104,6 +108,9 @@ namespace Controllers
{
score += 2;
}
+
+ // They made a shot! Now respawn the players and give possession to the opposite player.
+ controller.Respawn(isEnemy ? Possession.Player : Possession.Enemy);
}
private State dribble => isEnemy ? State.EnemyDribble : State.PlayerDribble;
@@ -173,6 +180,54 @@ namespace Controllers
state = State.Idle;
}
+ private void Respawn(Possession possession)
+ {
+ PlayerSpawnPoints.body.transform.position = new Vector3(PlayerSpawnPoints.character.position.x, PlayerSpawnPoints.character.position.y, PlayerSpawnPoints.body.transform.position.y);
+ PlayerSpawnPoints.body.GetComponent<Rigidbody2D>().velocity = Vector2.zero;
+
+ if (PlayerSpawnPoints.secondBody is { })
+ {
+ if (PlayerSpawnPoints.secondCharacter is { })
+ PlayerSpawnPoints.secondBody.transform.position = new Vector3(PlayerSpawnPoints.secondCharacter.position.x, PlayerSpawnPoints.secondCharacter.position.y, PlayerSpawnPoints.body.transform.position.y);
+ PlayerSpawnPoints.secondBody.GetComponent<Rigidbody2D>().velocity = Vector2.zero;
+ }
+
+ PlayerSpawnPoints.body.transform.localRotation = Quaternion.identity;
+ EnemySpawnPoints.body.transform.position = new Vector3(EnemySpawnPoints.character.position.x, EnemySpawnPoints.character.position.y, EnemySpawnPoints.body.transform.position.y);
+ ball.transform.position = possession switch
+ {
+ Possession.Player => new Vector3(PlayerSpawnPoints.ball.position.x, PlayerSpawnPoints.ball.position.y, ball.transform.position.y),
+ Possession.Enemy => new Vector3(EnemySpawnPoints.ball.position.x, EnemySpawnPoints.ball.position.y, ball.transform.position.y),
+ _ => ball.transform.position
+ };
+
+ // Set a cooldown so they can stop trying to wrangle the player while it respawns.
+ StartCoroutine(RespawnCooldown(possession));
+ }
+
+ private IEnumerator RespawnCooldown(Possession possession)
+ {
+ // Show the new score.
+ var possessionText = possession == Possession.Player ? "HOME" : "AWAY";
+ ShowModal($"{player.score}-{enemy.score}\n{possessionText}'S POSSESSION");
+
+ freezeMotion = true;
+
+ yield return new WaitForSeconds(1f);
+
+ HideModal();
+
+ freezeMotion = false;
+ }
+
+ private void ShowModal(string text)
+ {
+ resultOverlay.SetActive(true);
+ resultText.text = text;
+ }
+
+ private void HideModal() => resultOverlay.SetActive(false);
+
internal enum State
{
Idle,
@@ -186,8 +241,17 @@ namespace Controllers
[Serializable]
private struct SpawnPoints
{
+ [SerializeField] internal Transform body;
+ [SerializeField] [CanBeNull] internal Transform secondBody;
[SerializeField] internal Transform ball;
[SerializeField] internal Transform character;
+ [SerializeField] [CanBeNull] internal Transform secondCharacter;
+ }
+
+ private enum Possession
+ {
+ Player,
+ Enemy
}
}
diff --git a/Assets/Scripts/Controllers/Player/PlayerController.cs b/Assets/Scripts/Controllers/Player/PlayerController.cs
index d72b077..9df8c0a 100644
--- a/Assets/Scripts/Controllers/Player/PlayerController.cs
+++ b/Assets/Scripts/Controllers/Player/PlayerController.cs
@@ -33,6 +33,8 @@ namespace Controllers.Player
private void Update()
{
+ if (game.freezeMotion) return;
+
// Loop over each body segment and control it.
for (var i = 0; i < segments.Length; i++)
{