Skip to content

Commit

Permalink
actually add wincon
Browse files Browse the repository at this point in the history
  • Loading branch information
cpiemontese committed Aug 23, 2024
1 parent 4592c74 commit 5579aa5
Show file tree
Hide file tree
Showing 8 changed files with 2,812 additions and 4 deletions.
18 changes: 18 additions & 0 deletions Assets/Scripts/Boundary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ public class Boundary : MonoBehaviour
public Text scoreText;
public GameManager gameManager;

public enum BoundaryType
{
Player,
AI
}

public BoundaryType boundaryType;

int score;

void Start()
Expand All @@ -16,6 +24,16 @@ void Start()
void OnTriggerEnter2D(Collider2D other)
{
score += 1;

if (boundaryType == BoundaryType.Player)
{
gameManager.ScorePlayer();
}
else if (boundaryType == BoundaryType.AI)
{
gameManager.ScoreAI();
}

scoreText.text = score.ToString();
other.gameObject.GetComponent<Ball>().Reset();
}
Expand Down
26 changes: 26 additions & 0 deletions Assets/Scripts/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class GameManager : MonoBehaviour
public AudioSource musicSource;
public Toggle[] difficultyToggles;
public Toggle musicToggle;
public int winningScore = 10;

[SerializeField]
bool _paused = false;
Expand Down Expand Up @@ -52,6 +53,11 @@ public int music
}
}

[SerializeField]
int playerScore = 0;
[SerializeField]
int aiScore = 0;

bool _settingsOpen = false;
public bool settingsOpen
{
Expand Down Expand Up @@ -103,6 +109,26 @@ void UpdateMusicSource()
}
}

public void ScorePlayer()
{
playerScore++;

if (playerScore >= winningScore)
{
LoadScene("PlayerWin");
}
}

public void ScoreAI()
{
aiScore++;

if (aiScore >= winningScore)
{
LoadScene("AIWin");
}
}

public void LoadScene(string sceneName)
{
SceneManager.LoadScene(sceneName);
Expand Down
Loading

0 comments on commit 5579aa5

Please sign in to comment.