rev, v0.3
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using TMPro;
|
||||
using Unity.VisualScripting;
|
||||
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
@@ -24,10 +25,10 @@ public class GameManager : MonoBehaviour
|
||||
public EventTrigger gameInputPanel;
|
||||
public Rigidbody2D ball;
|
||||
public float puckForce = 20f;
|
||||
[Range(0f,1f)]
|
||||
public float puckForceMaxPoint = 0.75f;
|
||||
public AnimationCurve puckForceCurve = AnimationCurve.Linear(0,3,1,1);
|
||||
public float ballMoveTime = 3f;
|
||||
public float puckDragClamp = 5f;
|
||||
public float puckDragClampMax = 5f;
|
||||
public float puckDragMinClamp = 1f;
|
||||
|
||||
public int redScore,blueScore=0;
|
||||
|
||||
@@ -39,6 +40,8 @@ public class GameManager : MonoBehaviour
|
||||
|
||||
[Header("Misc")]
|
||||
public List<Puck> pucks = new List<Puck>();
|
||||
public float curPuckPullForce;
|
||||
public int hitCounter = 0;
|
||||
|
||||
public static GameManager instance;
|
||||
void Awake()
|
||||
@@ -118,14 +121,22 @@ public class GameManager : MonoBehaviour
|
||||
Vector2 endPosition = pointerEventData.position;
|
||||
// Vector2 direction = endPosition - startPosition;
|
||||
Vector2 direction = selectedPuck.lineEnd;
|
||||
|
||||
if(direction.magnitude < puckDragMinClamp){
|
||||
selectedPuck = null;
|
||||
OnSelectedPuckChanged?.Invoke(null);
|
||||
startPosition = Vector2.zero;
|
||||
return;
|
||||
}
|
||||
if(coroutinePostLaunch != null){
|
||||
StopCoroutine(coroutinePostLaunch);
|
||||
}
|
||||
coroutinePostLaunch = StartCoroutine(CoroutinePostLaunch());
|
||||
|
||||
float force = puckForce * Time.deltaTime;
|
||||
Debug.Log($"launching puck at {direction}");
|
||||
curPuckPullForce = direction.magnitude;
|
||||
float force = puckForce * Time.deltaTime * puckForceCurve.Evaluate(curPuckPullForce);
|
||||
Debug.Log($"launching puck at {direction} with {force * -direction} force");
|
||||
selectedPuck.GetComponent<Rigidbody2D>().AddForce(-direction * force, ForceMode2D.Impulse);
|
||||
hitCounter++;
|
||||
|
||||
startPosition = Vector2.zero;
|
||||
selectedPuck = null;
|
||||
@@ -138,6 +149,10 @@ public class GameManager : MonoBehaviour
|
||||
{
|
||||
PointerEventData pointerEventData = eventData as PointerEventData;
|
||||
curPosition = pointerEventData.position;
|
||||
|
||||
if(selectedPuck!=null){
|
||||
curPuckPullForce = selectedPuck.lineEnd.magnitude;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -174,14 +189,25 @@ public class GameManager : MonoBehaviour
|
||||
public void OnGoal(Team team){
|
||||
freezeInput=true;
|
||||
|
||||
if(hitCounter == 1){
|
||||
//kickoff goal
|
||||
Debug.Log("Kickoff goal");
|
||||
StartCoroutine(CoroutineOnGoal(team,true));//true = Kickoff goal, reset only the ball
|
||||
return;
|
||||
}
|
||||
if(team == Team.Blue){
|
||||
blueScore++;
|
||||
blueScoreText.text = blueScore.ToString();
|
||||
SelectedTeam = Team.Red;
|
||||
}else{
|
||||
redScore++;
|
||||
redScoreText.text = redScore.ToString();
|
||||
SelectedTeam = Team.Blue;
|
||||
}
|
||||
|
||||
OnTeamChanged?.Invoke(SelectedTeam);
|
||||
|
||||
|
||||
if(blueScore >= 3){
|
||||
gameOverPanel.SetActive(true);
|
||||
|
||||
@@ -194,11 +220,13 @@ public class GameManager : MonoBehaviour
|
||||
}else{
|
||||
StartCoroutine(CoroutineOnGoal(team));
|
||||
}
|
||||
|
||||
hitCounter = 0;
|
||||
}
|
||||
|
||||
bool freezeInput = false;
|
||||
|
||||
IEnumerator CoroutineOnGoal(Team team){
|
||||
IEnumerator CoroutineOnGoal(Team team, bool kickoff = false){
|
||||
if(coroutinePostLaunch!=null){
|
||||
StopCoroutine(coroutinePostLaunch);
|
||||
}
|
||||
@@ -216,15 +244,17 @@ public class GameManager : MonoBehaviour
|
||||
}
|
||||
|
||||
|
||||
public void Reset()
|
||||
public void Reset(bool kickoff = false)
|
||||
{
|
||||
StartCoroutine(CoroutineReset());
|
||||
StartCoroutine(CoroutineReset(kickoff));
|
||||
}
|
||||
|
||||
IEnumerator CoroutineReset(){
|
||||
IEnumerator CoroutineReset(bool kickoff = false){
|
||||
float resetDuration = 0.5f;
|
||||
foreach(Puck puck in pucks){
|
||||
puck.Reset(resetDuration);
|
||||
if(!kickoff){
|
||||
foreach(Puck puck in pucks){
|
||||
puck.Reset(resetDuration);
|
||||
}
|
||||
}
|
||||
|
||||
ball.GetComponent<Ball>().Reset(resetDuration);
|
||||
|
||||
Reference in New Issue
Block a user