diff --git a/Assets/Scenes/Game.unity b/Assets/Scenes/Game.unity index 7fd5fe7..71f4980 100644 --- a/Assets/Scenes/Game.unity +++ b/Assets/Scenes/Game.unity @@ -259,7 +259,7 @@ Transform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 5 + m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &338338487 GameObject: @@ -343,7 +343,7 @@ Transform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 4 + m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &948416250 GameObject: @@ -379,7 +379,7 @@ Transform: - {fileID: 132613873} - {fileID: 1462314554} m_Father: {fileID: 0} - m_RootOrder: 3 + m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &948416252 MonoBehaviour: @@ -506,67 +506,6 @@ EdgeCollider2D: m_AdjacentEndPoint: {x: 0, y: 0} m_UseAdjacentStartPoint: 0 m_UseAdjacentEndPoint: 0 ---- !u!1001 &1497269263 -PrefabInstance: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Modification: - m_TransformParent: {fileID: 0} - m_Modifications: - - target: {fileID: 7041796185663956338, guid: d67d5f2db5f0b3d9d8298731f423a9b6, type: 3} - propertyPath: m_RootOrder - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 7041796185663956338, guid: d67d5f2db5f0b3d9d8298731f423a9b6, type: 3} - propertyPath: m_LocalPosition.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7041796185663956338, guid: d67d5f2db5f0b3d9d8298731f423a9b6, type: 3} - propertyPath: m_LocalPosition.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7041796185663956338, guid: d67d5f2db5f0b3d9d8298731f423a9b6, type: 3} - propertyPath: m_LocalPosition.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7041796185663956338, guid: d67d5f2db5f0b3d9d8298731f423a9b6, type: 3} - propertyPath: m_LocalRotation.w - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 7041796185663956338, guid: d67d5f2db5f0b3d9d8298731f423a9b6, type: 3} - propertyPath: m_LocalRotation.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7041796185663956338, guid: d67d5f2db5f0b3d9d8298731f423a9b6, type: 3} - propertyPath: m_LocalRotation.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7041796185663956338, guid: d67d5f2db5f0b3d9d8298731f423a9b6, type: 3} - propertyPath: m_LocalRotation.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7041796185663956338, guid: d67d5f2db5f0b3d9d8298731f423a9b6, type: 3} - propertyPath: m_LocalEulerAnglesHint.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7041796185663956338, guid: d67d5f2db5f0b3d9d8298731f423a9b6, type: 3} - propertyPath: m_LocalEulerAnglesHint.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7041796185663956338, guid: d67d5f2db5f0b3d9d8298731f423a9b6, type: 3} - propertyPath: m_LocalEulerAnglesHint.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 7041796185663956339, guid: d67d5f2db5f0b3d9d8298731f423a9b6, type: 3} - propertyPath: GlobalObjectIdHash - value: 290977249 - objectReference: {fileID: 0} - - target: {fileID: 7041796185663956342, guid: d67d5f2db5f0b3d9d8298731f423a9b6, type: 3} - propertyPath: m_Name - value: Ball - objectReference: {fileID: 0} - m_RemovedComponents: [] - m_SourcePrefab: {fileID: 100100000, guid: d67d5f2db5f0b3d9d8298731f423a9b6, type: 3} --- !u!1 &1698696474 GameObject: m_ObjectHideFlags: 0 @@ -762,7 +701,7 @@ Transform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 2 + m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &2109945869 MonoBehaviour: diff --git a/Assets/Scripts/Game/AIPlayer.cs b/Assets/Scripts/Game/AIPlayer.cs index 63bbe1a..7d8d71c 100644 --- a/Assets/Scripts/Game/AIPlayer.cs +++ b/Assets/Scripts/Game/AIPlayer.cs @@ -3,21 +3,20 @@ using System.Linq; using UnityEngine; namespace Game { + public class AIPlayer : Player { /* - * Possible optimizations: - * - * - Move to center when idle - * - Ignore impossible balls - * - Try to hit ball with edge - */ - - public enum EDifficulty { - VeryEasy, Easy, Medium, Hard, VeryHard - } + * Possible optimizations: + * + * - Move to center when idle + * - Ignore impossible balls + * - Try to hit ball with edge + */ + + - public EDifficulty Difficulty { get; set; } + public Difficulty Difficulty { get; set; } // True if ball y velocity points towards player private bool BallApproaches(Ball ball) { diff --git a/Assets/Scripts/Game/GameManager.cs b/Assets/Scripts/Game/GameManager.cs index fb70e18..b7d7e37 100644 --- a/Assets/Scripts/Game/GameManager.cs +++ b/Assets/Scripts/Game/GameManager.cs @@ -49,20 +49,37 @@ namespace Game { } private void Start() { - //var ball = Instantiate(ballPrefab, Vector2.zero, Quaternion.identity).GetComponent(); - var ball = FindObjectOfType(typeof(Ball)).GetComponent(); + var ball = Instantiate(ballPrefab).GetComponent(); Balls.Add(ball); ball.Radius = 0.5f; var p1Obj = Instantiate(playerPrefab); var p2Obj = Instantiate(playerPrefab); - var p1 = p1Obj.AddComponent(); - var p2 = p2Obj.AddComponent(); - p1.Side = Player.ESide.Top; - p2.Side = Player.ESide.Bottom; - p1.Difficulty = AIPlayer.EDifficulty.VeryHard; - p2.Difficulty = AIPlayer.EDifficulty.VeryHard; - // p2.isThisClient = true; + + Player p1, p2; + switch (Settings.Type) { + case Type.AI: + p1 = p1Obj.AddComponent(); + p2 = p2Obj.AddComponent(); + ((AIPlayer) p1).Difficulty = Settings.AIDifficulty; + ((AIPlayer) p2).Difficulty = Settings.AIDifficulty; + break; + case Type.Real: + p1 = p1Obj.AddComponent(); + p2 = p2Obj.AddComponent(); + ((RealPlayer) p1).isThisClient = true; + break; + case Type.Hybrid: + p1 = p1Obj.AddComponent(); + p2 = p2Obj.AddComponent(); + ((RealPlayer) p1).isThisClient = true; + ((AIPlayer)p2).Difficulty = Settings.AIDifficulty; + break; + default: + throw new ArgumentOutOfRangeException(); + } + p1.Side = Player.ESide.Bottom; + p2.Side = Player.ESide.Top; Tests(); } diff --git a/Assets/Scripts/Game/Settings.cs b/Assets/Scripts/Game/Settings.cs new file mode 100644 index 0000000..ac3b1c8 --- /dev/null +++ b/Assets/Scripts/Game/Settings.cs @@ -0,0 +1,9 @@ +namespace Game { + public enum Type { Real, Hybrid, AI } + public enum Difficulty { VeryEasy, Easy, Medium, Hard, VeryHard } + + public struct Settings { + public static Type Type; + public static Difficulty AIDifficulty; + }; +} diff --git a/Assets/Scripts/Game/Settings.cs.meta b/Assets/Scripts/Game/Settings.cs.meta new file mode 100644 index 0000000..5637246 --- /dev/null +++ b/Assets/Scripts/Game/Settings.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ba3433b349f4485cb01c605e8abdd151 +timeCreated: 1680961305 \ No newline at end of file diff --git a/Assets/Scripts/MenuUI.cs b/Assets/Scripts/MenuUI.cs index 2d3b96d..5f77d06 100644 --- a/Assets/Scripts/MenuUI.cs +++ b/Assets/Scripts/MenuUI.cs @@ -1,3 +1,4 @@ +using Game; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UIElements; @@ -19,10 +20,13 @@ public class MenuUI : MonoBehaviour { mainMenu.Q("btn_settings").RegisterCallback(SettingsPressed); playMenu.Q("btn_find").RegisterCallback(FindPressed); + playMenu.Q("btn_host").RegisterCallback(HostPressed); + playMenu.Q("btn_join").RegisterCallback(JoinPressed); playMenu.Q("btn_bot").RegisterCallback(BotPressed); + playMenu.Q("btn_bots").RegisterCallback(BotsPressed); - PlayPressed(null); - BotPressed(null); + // PlayPressed(null); + // BotPressed(null); } private void PlayPressed(ClickEvent evt) { @@ -36,10 +40,28 @@ public class MenuUI : MonoBehaviour { } private void FindPressed(ClickEvent evt) { - Debug.Log("Start finding online opponent"); + + } + + private void HostPressed(ClickEvent evt) { + + } + + private void JoinPressed(ClickEvent evt) { + } private void BotPressed(ClickEvent evt) { + Settings.Type = Type.Hybrid; + Settings.AIDifficulty = Difficulty.VeryHard; + + SceneManager.LoadScene("Game"); + } + + private void BotsPressed(ClickEvent evt) { + Settings.Type = Type.AI; + Settings.AIDifficulty = Difficulty.VeryHard; + SceneManager.LoadScene("Game"); } } diff --git a/Assets/UI Toolkit/Menu.uxml b/Assets/UI Toolkit/Menu.uxml index 4e3ec6d..2d0a7cd 100644 --- a/Assets/UI Toolkit/Menu.uxml +++ b/Assets/UI Toolkit/Menu.uxml @@ -7,9 +7,10 @@