aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Assets/Scripts/Controllers
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts/Controllers')
-rw-r--r--Assets/Scripts/Controllers/CameraController.cs6
-rw-r--r--Assets/Scripts/Controllers/GameController.cs27
-rw-r--r--Assets/Scripts/Controllers/Player/PlayerSegment.cs7
3 files changed, 35 insertions, 5 deletions
diff --git a/Assets/Scripts/Controllers/CameraController.cs b/Assets/Scripts/Controllers/CameraController.cs
index 7d42be5..8730c1c 100644
--- a/Assets/Scripts/Controllers/CameraController.cs
+++ b/Assets/Scripts/Controllers/CameraController.cs
@@ -6,10 +6,14 @@ namespace Controllers
{
[SerializeField] private Transform target;
[SerializeField] private float speed;
+ [SerializeField] private GameController game;
private void FixedUpdate()
{
- transform.position = Vector3.MoveTowards(transform.position, new Vector3(target.transform.position.x, target.transform.position.y, -10f), Time.deltaTime * speed);
+ if (game.player.IsShooting || game.enemy.IsShooting) // Track the ball when they shoot
+ transform.position = Vector3.MoveTowards(transform.position, new Vector3(game.ball.transform.position.x, game.ball.transform.position.y, -10f), Time.deltaTime * speed);
+ else // Track the player otherwise
+ transform.position = Vector3.MoveTowards(transform.position, new Vector3(target.transform.position.x, target.transform.position.y, -10f), Time.deltaTime * speed);
}
}
}
diff --git a/Assets/Scripts/Controllers/GameController.cs b/Assets/Scripts/Controllers/GameController.cs
index c9cb0ce..35e6b62 100644
--- a/Assets/Scripts/Controllers/GameController.cs
+++ b/Assets/Scripts/Controllers/GameController.cs
@@ -46,6 +46,11 @@ namespace Controllers
[SerializeField] public AudioSource dribbleSound;
[SerializeField] public AudioSource airhornSound;
+ [Header("VFX")]
+ [SerializeField] private GameObject twoPointVFX;
+ [SerializeField] private GameObject threePointVFX;
+ [SerializeField] private GameObject spotlightVFX;
+
[Header("UI")]
[SerializeField] private Text playerScoreText;
[SerializeField] private Text enemyScoreText;
@@ -148,14 +153,20 @@ namespace Controllers
if (Vector2.Distance(lastShotPosition, Rim) >= 10)
{
score += 3;
+ controller.ParticleEffect(true, hoop);
}
else
{
score += 2;
+ controller.ParticleEffect(false, hoop);
}
+
+ // Make two spotlights.
+ Instantiate(controller.spotlightVFX);
+ Instantiate(controller.spotlightVFX);
// They made a shot! Now respawn the players and give possession to the opposite player.
- controller.Respawn(isEnemy ? Possession.Player : Possession.Enemy, $"{controller.player.score}-{controller.enemy.score}");
+ controller.StartCoroutine(controller.Respawn(isEnemy ? Possession.Player : Possession.Enemy, $"{controller.player.score}-{controller.enemy.score}"));
}
private State dribble => isEnemy ? State.EnemyDribble : State.PlayerDribble;
@@ -165,6 +176,8 @@ namespace Controllers
public bool HasBall => controller.state == dribble;
+ public bool IsShooting => controller.state == shoot;
+
/// <summary>
/// When dribbling, move the ball with the player.
/// </summary>
@@ -219,7 +232,7 @@ namespace Controllers
public void Foul(string reason)
{
// Give the other player the ball on a foul.
- controller.Respawn(isEnemy ? Possession.Player : Possession.Enemy, reason);
+ controller.StartCoroutine(controller.Respawn(isEnemy ? Possession.Player : Possession.Enemy, reason, false));
}
}
@@ -231,9 +244,17 @@ namespace Controllers
state = State.Idle;
}
- private void Respawn(Possession possession, string message)
+ private void ParticleEffect(bool threePts, Hoop hoop)
+ {
+ var vfx = Instantiate(threePts ? threePointVFX : twoPointVFX);
+ vfx.transform.position = hoop.transform.position;
+ }
+
+ private IEnumerator Respawn(Possession possession, string message, bool wait = true)
{
BallDropped();
+
+ yield return new WaitForSeconds(wait ? 0.5f : 0f); // Wait a slight bit before respawning so they can see the VFXs.
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;
diff --git a/Assets/Scripts/Controllers/Player/PlayerSegment.cs b/Assets/Scripts/Controllers/Player/PlayerSegment.cs
index 67b3ecf..aac0164 100644
--- a/Assets/Scripts/Controllers/Player/PlayerSegment.cs
+++ b/Assets/Scripts/Controllers/Player/PlayerSegment.cs
@@ -48,7 +48,12 @@ namespace Controllers.Player
private void OnCollisionEnter2D(Collision2D other)
{
- if (callFoulOnContact && game.player.HasBall && other.gameObject.CompareTag("Ground"))
+ if (!callFoulOnContact) return;
+ Debug.Log("ENTERED");
+ Debug.Log(other.gameObject.CompareTag("Ground"));
+ Debug.Log(game.player.HasBall);
+ Debug.Log("---");
+ if (game.player.HasBall && other.gameObject.CompareTag("Ground"))
game.player.Foul("LOOSE BALL FOUL");
}
}