Skip to content

Commit 5f7ea4f

Browse files
Merge pull request #89 from Satvik-Singh192/feat/new_mini
feat: added mini game in every classic level
2 parents 5460de1 + 1d37247 commit 5f7ea4f

File tree

13 files changed

+17651
-3200
lines changed

13 files changed

+17651
-3200
lines changed

Assets/Scenes/Level1.unity

Lines changed: 3973 additions & 651 deletions
Large diffs are not rendered by default.

Assets/Scenes/Level2.unity

Lines changed: 4346 additions & 621 deletions
Large diffs are not rendered by default.

Assets/Scenes/Level3.unity

Lines changed: 4049 additions & 545 deletions
Large diffs are not rendered by default.

Assets/Scenes/Level4.unity

Lines changed: 4970 additions & 1355 deletions
Large diffs are not rendered by default.

Assets/Scripts/PillarInteractor.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using UnityEngine;
2+
using TMPro;
3+
4+
public class PillarInteractor : MonoBehaviour
5+
{
6+
public GameObject minigameCanvas;
7+
public TextMeshProUGUI interactionPromptText;
8+
9+
private bool playerIsNear = false;
10+
11+
void Start()
12+
{
13+
if (interactionPromptText != null)
14+
{
15+
interactionPromptText.gameObject.SetActive(false);
16+
}
17+
}
18+
19+
void Update()
20+
{
21+
if (playerIsNear && !minigameCanvas.activeSelf && Input.GetKeyDown(KeyCode.E))
22+
{
23+
ActivateMinigame();
24+
}
25+
}
26+
27+
private void OnTriggerEnter(Collider other)
28+
{
29+
if (other.CompareTag("Player"))
30+
{
31+
playerIsNear = true;
32+
if (interactionPromptText != null)
33+
{
34+
interactionPromptText.text = "Press [E] to Play Tic-Tac-Toe";
35+
interactionPromptText.gameObject.SetActive(true);
36+
}
37+
}
38+
}
39+
40+
private void OnTriggerExit(Collider other)
41+
{
42+
if (other.CompareTag("Player"))
43+
{
44+
playerIsNear = false;
45+
if (interactionPromptText != null)
46+
{
47+
interactionPromptText.gameObject.SetActive(false);
48+
}
49+
}
50+
}
51+
52+
private void ActivateMinigame()
53+
{
54+
if (minigameCanvas != null)
55+
{
56+
minigameCanvas.SetActive(true);
57+
Time.timeScale = 0f;
58+
if (interactionPromptText != null)
59+
{
60+
interactionPromptText.gameObject.SetActive(false);
61+
}
62+
}
63+
}
64+
}

Assets/Scripts/PillarInteractor.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/PlayerCollectibles.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,44 @@ private IEnumerator InvincibilityRoutine(float duration)
5656
{
5757
IsInvincible = true;
5858
var renderers = GetComponentsInChildren<Renderer>();
59+
5960
foreach (var r in renderers)
6061
{
6162
if (r.material != null)
6263
{
63-
Color c = r.material.color;
64-
r.material.color = new Color(c.r, c.g, c.b, 0.5f);
64+
var mat = r.material;
65+
66+
if (mat.HasProperty("_Color"))
67+
{
68+
Color c = mat.color;
69+
mat.color = new Color(c.r, c.g, c.b, 0.5f);
70+
}
71+
else if (mat.HasProperty("_TintColor"))
72+
{
73+
Color c = mat.GetColor("_TintColor");
74+
mat.SetColor("_TintColor", new Color(c.r, c.g, c.b, 0.5f));
75+
}
6576
}
6677
}
78+
6779
yield return new WaitForSeconds(duration);
6880

6981
foreach (var r in renderers)
7082
{
7183
if (r.material != null)
7284
{
73-
Color c = r.material.color;
74-
r.material.color = new Color(c.r, c.g, c.b, 1f);
85+
var mat = r.material;
86+
87+
if (mat.HasProperty("_Color"))
88+
{
89+
Color c = mat.color;
90+
mat.color = new Color(c.r, c.g, c.b, 1f);
91+
}
92+
else if (mat.HasProperty("_TintColor"))
93+
{
94+
Color c = mat.GetColor("_TintColor");
95+
mat.SetColor("_TintColor", new Color(c.r, c.g, c.b, 1f));
96+
}
7597
}
7698
}
7799

Assets/Scripts/TicTacToeManager.cs

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
using UnityEngine;
2+
using UnityEngine.UI;
3+
using TMPro;
4+
5+
public class TicTacToeManager : MonoBehaviour
6+
{
7+
8+
public Button[] buttons = new Button[9];
9+
public TextMeshProUGUI statusText;
10+
public GameObject gameOverPanel;
11+
public GameObject minigameCanvas;
12+
13+
private char[] board = new char[9];
14+
private bool isPlayerTurn = true;
15+
private bool gameOver = false;
16+
private int movesMade = 0;
17+
18+
private bool isAwaitingAIMove = false;
19+
20+
void Start()
21+
{
22+
InitializeGame();
23+
}
24+
25+
void Update()
26+
{
27+
if (isAwaitingAIMove)
28+
{
29+
isAwaitingAIMove = false;
30+
AITurn();
31+
}
32+
}
33+
private void InitializeGame()
34+
{
35+
for (int i = 0; i < 9; i++)
36+
{
37+
board[i] = ' ';
38+
}
39+
for (int i = 0; i < buttons.Length; i++)
40+
{
41+
buttons[i].GetComponentInChildren<TextMeshProUGUI>().text = "";
42+
buttons[i].interactable = true;
43+
44+
int index = i;
45+
buttons[i].onClick.RemoveAllListeners();
46+
buttons[i].onClick.AddListener(() => OnButtonClick(index));
47+
}
48+
isPlayerTurn = true;
49+
gameOver = false;
50+
movesMade = 0;
51+
isAwaitingAIMove = false;
52+
gameOverPanel.SetActive(false);
53+
UpdateStatusText("Your turn (X)");
54+
}
55+
private void UpdateStatusText(string message)
56+
{
57+
statusText.text = message;
58+
}
59+
60+
public void OnButtonClick(int index)
61+
{
62+
if (board[index] != ' ' || gameOver || !isPlayerTurn)
63+
{
64+
return;
65+
}
66+
67+
MakeMove(index, 'X');
68+
isPlayerTurn = false;
69+
if (!gameOver)
70+
{
71+
UpdateStatusText("AI's turn (O)...");
72+
isAwaitingAIMove = true;
73+
}
74+
}
75+
76+
private void MakeMove(int index, char player)
77+
{
78+
board[index] = player;
79+
buttons[index].GetComponentInChildren<TextMeshProUGUI>().text = player.ToString();
80+
buttons[index].interactable = false;
81+
movesMade++;
82+
83+
if (CheckWin(player))
84+
{
85+
GameOver(player.ToString() + " wins!");
86+
}
87+
else if (movesMade == 9)
88+
{
89+
GameOver("It's a draw!");
90+
}
91+
}
92+
93+
private void AITurn()
94+
{
95+
if (gameOver) return;
96+
97+
int bestMove = GetBestMove();
98+
99+
if (bestMove != -1)
100+
{
101+
MakeMove(bestMove, 'O');
102+
}
103+
104+
if (!gameOver)
105+
{
106+
isPlayerTurn = true;
107+
UpdateStatusText("Your turn (X)");
108+
}
109+
}
110+
111+
private int GetBestMove()
112+
{
113+
for (int i = 0; i < 9; i++)
114+
{
115+
if (board[i] == ' ')
116+
{
117+
board[i] = 'O';
118+
if (CheckWin('O'))
119+
{
120+
board[i] = ' '; return i;
121+
}
122+
board[i] = ' ';
123+
}
124+
}
125+
126+
for (int i = 0; i < 9; i++)
127+
{
128+
if (board[i] == ' ')
129+
{
130+
board[i] = 'X';
131+
if (CheckWin('X'))
132+
{
133+
board[i] = ' '; return i;
134+
}
135+
board[i] = ' ';
136+
}
137+
}
138+
139+
if (board[4] == ' ') return 4;
140+
int[] corners = { 0, 2, 6, 8 };
141+
foreach (int corner in corners)
142+
{
143+
if (board[corner] == ' ') return corner;
144+
}
145+
for (int i = 0; i < 9; i++)
146+
{
147+
if (board[i] == ' ')
148+
{
149+
return i;
150+
}
151+
}
152+
return -1;
153+
}
154+
private bool CheckWin(char player)
155+
{
156+
int[,] winningLines = new int[,]
157+
{
158+
{0, 1, 2}, {3, 4, 5}, {6, 7, 8},
159+
{0, 3, 6}, {1, 4, 7}, {2, 5, 8},
160+
{0, 4, 8}, {2, 4, 6}
161+
};
162+
163+
for (int i = 0; i < 8; i++)
164+
{
165+
if (board[winningLines[i, 0]] == player &&
166+
board[winningLines[i, 1]] == player &&
167+
board[winningLines[i, 2]] == player)
168+
{
169+
return true;
170+
}
171+
}
172+
return false;
173+
}
174+
175+
private void GameOver(string message)
176+
{
177+
gameOver = true;
178+
UpdateStatusText("Game Over: " + message);
179+
for (int i = 0; i < buttons.Length; i++)
180+
{
181+
buttons[i].interactable = false;
182+
}
183+
gameOverPanel.SetActive(true);
184+
}
185+
public void PlayAgain()
186+
{
187+
InitializeGame();
188+
}
189+
public void CloseGame()
190+
{
191+
minigameCanvas.SetActive(false);
192+
Time.timeScale = 1f;
193+
}
194+
}

Assets/Scripts/TicTacToeManager.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Settings/UniversalRenderPipelineGlobalSettings.asset

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ MonoBehaviour:
9494
references:
9595
version: 2
9696
RefIds:
97+
- rid: -2
98+
type: {class: , ns: , asm: }
9799
- rid: 2100176707506143232
98100
type: {class: RenderingDebuggerRuntimeResources, ns: UnityEngine.Rendering, asm: Unity.RenderPipelines.Core.Runtime}
99101
data:
@@ -240,6 +242,9 @@ MonoBehaviour:
240242
m_AutodeskInteractive: {fileID: 4800000, guid: 0e9d5a909a1f7e84882a534d0d11e49f, type: 3}
241243
m_AutodeskInteractiveTransparent: {fileID: 4800000, guid: 5c81372d981403744adbdda4433c9c11, type: 3}
242244
m_AutodeskInteractiveMasked: {fileID: 4800000, guid: 80aa867ac363ac043847b06ad71604cd, type: 3}
245+
m_TerrainDetailLit: {fileID: 4800000, guid: f6783ab646d374f94b199774402a5144, type: 3}
246+
m_TerrainDetailGrassBillboard: {fileID: 4800000, guid: 29868e73b638e48ca99a19ea58c48d90, type: 3}
247+
m_TerrainDetailGrass: {fileID: 4800000, guid: e507fdfead5ca47e8b9a768b51c291a1, type: 3}
243248
m_DefaultSpeedTree7Shader: {fileID: 4800000, guid: 0f4122b9a743b744abe2fb6a0a88868b, type: 3}
244249
m_DefaultSpeedTree8Shader: {fileID: -6465566751694194690, guid: 9920c1f1781549a46ba081a2a15a16ec, type: 3}
245250
m_DefaultSpeedTree9Shader: {fileID: -6465566751694194690, guid: cbd3e1cc4ae141c42a30e33b4d666a61, type: 3}
@@ -250,8 +255,6 @@ MonoBehaviour:
250255
m_CopyDepthPS: {fileID: 4800000, guid: d6dae50ee9e1bfa4db75f19f99355220, type: 3}
251256
m_CameraMotionVector: {fileID: 4800000, guid: c56b7e0d4c7cb484e959caeeedae9bbf, type: 3}
252257
m_StencilDeferredPS: {fileID: 4800000, guid: e9155b26e1bc55942a41e518703fe304, type: 3}
253-
m_ClusterDeferred: {fileID: 4800000, guid: 222cce62363a44a380c36bf03b392608, type: 3}
254-
m_StencilDitherMaskSeedPS: {fileID: 4800000, guid: 8c3ee818f2efa514c889881ccb2e95a2, type: 3}
255258
m_DBufferClear: {fileID: 4800000, guid: f056d8bd2a1c7e44e9729144b4c70395, type: 3}
256259
- rid: 6852985685364965379
257260
type: {class: UniversalRenderPipelineDebugShaders, ns: UnityEngine.Rendering.Universal, asm: Unity.RenderPipelines.Universal.Runtime}

0 commit comments

Comments
 (0)