aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Assets/Scripts
diff options
context:
space:
mode:
authorCarson Katri <carson.katri@gmail.com>2021-06-13 00:19:02 -0400
committerCarson Katri <carson.katri@gmail.com>2021-06-13 00:19:02 -0400
commitaf13ca7f36f617c95e3932bb3282e7a5ffa8d2fe (patch)
tree676d0d07fd3d5acea3fc71d55be83c47a7b830d5 /Assets/Scripts
parentb2cb1b8162e404391b2a30b77b2b4c0565adc9c4 (diff)
downloadgmtk-gamejam-af13ca7f36f617c95e3932bb3282e7a5ffa8d2fe.tar.gz
gmtk-gamejam-af13ca7f36f617c95e3932bb3282e7a5ffa8d2fe.tar.zst
gmtk-gamejam-af13ca7f36f617c95e3932bb3282e7a5ffa8d2fe.zip
Add loose ball foul
Diffstat (limited to 'Assets/Scripts')
-rw-r--r--Assets/Scripts/Controllers/GameController.cs23
-rw-r--r--Assets/Scripts/Controllers/Player/PlayerSegment.cs14
2 files changed, 28 insertions, 9 deletions
diff --git a/Assets/Scripts/Controllers/GameController.cs b/Assets/Scripts/Controllers/GameController.cs
index 303b5a0..4bdae38 100644
--- a/Assets/Scripts/Controllers/GameController.cs
+++ b/Assets/Scripts/Controllers/GameController.cs
@@ -77,9 +77,10 @@ namespace Controllers
if (remainingRaw <= 0)
{
- resultOverlay.SetActive(true);
var outcome = player.score == enemy.score ? "TIE GAME" : player.score < enemy.score ? "AWAY TEAM WINS" : "HOME TEAM WINS";
- resultText.text = $"{outcome}\n{player.score}-{enemy.score}";
+ ShowModal($"{outcome}\n{player.score}-{enemy.score}");
+
+ freezeMotion = true;
}
}
@@ -110,7 +111,7 @@ namespace Controllers
}
// They made a shot! Now respawn the players and give possession to the opposite player.
- controller.Respawn(isEnemy ? Possession.Player : Possession.Enemy);
+ controller.Respawn(isEnemy ? Possession.Player : Possession.Enemy, $"{controller.player.score}-{controller.enemy.score}");
}
private State dribble => isEnemy ? State.EnemyDribble : State.PlayerDribble;
@@ -170,6 +171,12 @@ namespace Controllers
lastShotPosition = playerTransform.position;
return true;
}
+
+ public void Foul(string reason)
+ {
+ // Give the other player the ball on a foul.
+ controller.Respawn(isEnemy ? Possession.Player : Possession.Enemy, reason);
+ }
}
internal void BallDropped()
@@ -180,8 +187,10 @@ namespace Controllers
state = State.Idle;
}
- private void Respawn(Possession possession)
+ private void Respawn(Possession possession, string message)
{
+ BallDropped();
+
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;
@@ -202,14 +211,14 @@ namespace Controllers
};
// Set a cooldown so they can stop trying to wrangle the player while it respawns.
- StartCoroutine(RespawnCooldown(possession));
+ StartCoroutine(RespawnCooldown(possession, message));
}
- private IEnumerator RespawnCooldown(Possession possession)
+ private IEnumerator RespawnCooldown(Possession possession, string message)
{
// Show the new score.
var possessionText = possession == Possession.Player ? "HOME" : "AWAY";
- ShowModal($"{player.score}-{enemy.score}\n{possessionText}'S POSSESSION");
+ ShowModal($"{message}\n{possessionText}'S POSSESSION");
freezeMotion = true;
diff --git a/Assets/Scripts/Controllers/Player/PlayerSegment.cs b/Assets/Scripts/Controllers/Player/PlayerSegment.cs
index 0e8a969..67b3ecf 100644
--- a/Assets/Scripts/Controllers/Player/PlayerSegment.cs
+++ b/Assets/Scripts/Controllers/Player/PlayerSegment.cs
@@ -11,16 +11,20 @@ namespace Controllers.Player
internal bool moveleft;
internal bool moveright;
-
+
+ [Header("Controls")]
[SerializeField] public Control left;
[SerializeField] public Control right;
+ [Header("Settings")]
[SerializeField] public Vector3 forceOrigin;
-
[SerializeField] public float height;
[SerializeField] public bool isRoot;
[SerializeField] public bool isTop;
+ [Header("References")]
+ [SerializeField] private GameController game;
+ [SerializeField] private bool callFoulOnContact;
[SerializeField] public Transform flipper;
public Rigidbody2D Rigidbody => _rigidbody != null ? _rigidbody : _rigidbody = GetComponent<Rigidbody2D>();
@@ -41,6 +45,12 @@ namespace Controllers.Player
transform.position + (height * forceOrigin));
}
}
+
+ private void OnCollisionEnter2D(Collision2D other)
+ {
+ if (callFoulOnContact && game.player.HasBall && other.gameObject.CompareTag("Ground"))
+ game.player.Foul("LOOSE BALL FOUL");
+ }
}
[Serializable]