diff --git a/Assets/Source/Scripts/Pong/Ball/PongBall.cs b/Assets/Source/Scripts/Pong/Ball/PongBall.cs index 42b4d53..f7a876d 100644 --- a/Assets/Source/Scripts/Pong/Ball/PongBall.cs +++ b/Assets/Source/Scripts/Pong/Ball/PongBall.cs @@ -28,6 +28,11 @@ public partial class PongBall { private readonly Action OnScore; private readonly Action OnRebound; + /// + /// constructor for the ball object and give the ball object the logic if how the ball will react when a player + /// scores a goal or how the ball should change its velocity vector when it rebounds the paddle or boundary of the viewport + /// + /// public PongBall(GameObject sprite) { OnScore = () => { //* Attacker Scored Goal @@ -68,6 +73,10 @@ public static PongBall FromPrefab(GameObject prefab) { return pongBall; } + /// + /// initialize the ball and let a player serve the ball so it heads toward opponnet + /// + /// public void Initialize(Player server) { // First, reset the ball (just in case) Reset(); @@ -134,11 +143,18 @@ public void Update() { //TODO: feed to players? } + + /// + /// destroys the ball when a player scores so it doesn't go off the screen + /// public void DestroyBall() { ballSprite.gameObj.SetActive(false); ballSprite.controller.HaltTrajectory(); // stop the ball from going off the screen } + /// + /// reset the position of the ball + /// public void Reset() { // set position to start position ballSprite.transform.localPosition = GetStartLocalPosition(); @@ -147,6 +163,10 @@ public void Reset() { ballSprite.gameObj.SetActive(true); } + /// + /// set the attacker for who hit the ball last so goals are scored properly? + /// + /// private void SetAttacker(Player atkr) { attacker = atkr; @@ -154,11 +174,18 @@ private void SetAttacker(Player atkr) { ballSprite.controller.Rebounder = attacker.Opponent.AsRebounder(); } + /// + /// update the ball to swap the attacker + /// private void SwapAttacker() { SetAttacker(attacker.Opponent); attackerDesire = !attackerDesire; } + /// + /// set the dimmensions of the ball? + /// + /// public void SetLocalScaleFromVPY(float viewportY) { Vector3 bgScale = BG_TRANSFORM.localScale; @@ -171,6 +198,12 @@ public void SetLocalScaleFromVPY(float viewportY) { //Debug.Log("LocalScale: " + sprite.transform.localScale); } + /// + /// sets the starting position for the ball, center of screen + /// + /// + /// returns the starting position of the ball + /// public static Vector3 GetStartLocalPosition() { return ToLocal(GameConstants.BALL_START_POSITION); } diff --git a/Assets/Source/Scripts/Pong/Ball/_Pong-Ball.cs b/Assets/Source/Scripts/Pong/Ball/_Pong-Ball.cs index 44ec914..ae5e5f1 100644 --- a/Assets/Source/Scripts/Pong/Ball/_Pong-Ball.cs +++ b/Assets/Source/Scripts/Pong/Ball/_Pong-Ball.cs @@ -11,13 +11,22 @@ namespace Pong.Ball { * Player lastTouchedBy * Destroys the ball and increments points */ + + /// + /// partial class to be later fully defined. Controls how the ball will behave when a player scores a goal + /// or the ball rebounds off a paddle. May also include how to update the balls postion + /// public partial class PongBall {} /* * Handle collisions -> adjust trajectory speedX = GameCache.BALL_SPEED_VP - velocityY = ForceAdjustment => Equation (due to possible derivatives) + velocityY = ForceAdjustment => Equation (due to possible derivatives) */ + + /// + /// define the parital class to be later defined for how the ball will behave + /// public partial class PongBallController : MonoBehaviour {} /*public static class BallStatus { @@ -36,7 +45,9 @@ public static bool IsGoal(int ballStatus) { return Mathf.Abs(ballStatus) == GOAL; } }*/ - + /// + /// store who socred the last goal + /// public static class BallGoal { public const bool LEFT = true; public const bool RIGHT = false; diff --git a/Assets/Source/Scripts/Pong/GameManager.cs b/Assets/Source/Scripts/Pong/GameManager.cs index 56fea0c..4b1969b 100644 --- a/Assets/Source/Scripts/Pong/GameManager.cs +++ b/Assets/Source/Scripts/Pong/GameManager.cs @@ -19,8 +19,8 @@ public partial class GameManager : MonoBehaviour // CONTEXT: public => reference in the Unity Editor public string player1Name = PlayerData.NO_NAME, player2Name = PlayerData.NO_NAME; - public float playerSpeedVP = 1.00f; // per second; travel 100% vertical screen size in one second - public float ballSpeedVP = 0.45f; // per second; travel 45% horizontal screen size in one second + public float playerSpeedVP = 1.0f; // per second; travel 100% vertical screen size in one second + public float ballSpeedVP = .45f; // per second; travel 45% horizontal screen size in one second public float ballServeMaxAngle = (3f / 7f) * Mathf.PI; public float ballBounceMaxAngle = (3f / 7f) * Mathf.PI; public uint scoreToWin = GameConstants.DEFAULT_WIN_SCORE; @@ -29,6 +29,9 @@ public partial class GameManager : MonoBehaviour public GameObject backgroundSprite; // reference a GameObject in the Scene public TMP_Text player1scoreText, player2scoreText; // reference in Scene + /// + /// for debugging purposes? + /// void Awake() { // Hello World message @@ -38,6 +41,10 @@ void Awake() //Debug.Log(GameConstants.LEFT_PADDLE_START_POSITION); } + /// + /// starts the game and stores important data in GameCache.{attribute}. Initialize the player and give the player data. + /// Initialize the ball object and serve it so gameplay can begin + /// void Start() { // Cache Desired Global Variables @@ -65,6 +72,11 @@ void Start() } // Update is called once per frame + /// + /// update the player information and the all information every frame. + /// update players first so you don't have instances where the ball seemed like it was in one place but then the ball was + /// updated before the player so the player missed it. This can help solve this issue + /// void Update() { // Player Updates @@ -75,6 +87,12 @@ void Update() ball.Update(); // didn't call this before the player updates for a better user experience } + /// + /// display the score board + /// + /// + /// return as string that contains both players score so it can be displayed + /// public string GetCurrentScore() { return player1.GetScoreboard().GetScore() + "-" + player2.GetScoreboard().GetScore(); } diff --git a/Assets/Source/Scripts/Pong/GamePlayer/Player.cs b/Assets/Source/Scripts/Pong/GamePlayer/Player.cs index 4d60f5d..f5fc2e7 100644 --- a/Assets/Source/Scripts/Pong/GamePlayer/Player.cs +++ b/Assets/Source/Scripts/Pong/GamePlayer/Player.cs @@ -36,6 +36,14 @@ public partial class Player { private Player opponent; // load from data + /// + /// Intialize a player with their data, how to control the player, and give the paddles a boundary box so + /// the ball can bounce off it + /// + /// + /// + /// + /// public Player(PlayerData playerData, GameObject sprite, PlayerControls controls, Scoreboard scoreboard) { this.playerData = playerData; this.scoreboard = scoreboard; @@ -85,6 +93,10 @@ public Player Opponent { set { opponent = value; } } + /// + /// update the information of the player's padldle. For example update the velocity and acceleration when the player + /// wants to switch the direction of the paddle of the player no long is moving the paddle + /// public void Update() { forceMap.PaddleVelocity = ToLocal(playerSprite.controller.GetViewportMotionTracker().velocity).y; forceMap.PaddleAcceleration = ToLocal(new Vector2(0f, playerSprite.controller.GetViewportMotionTracker().Y_Acceleration)).y; @@ -92,6 +104,9 @@ public void Update() { //TODO: playerData.feed(...); } + /// + /// update the player's score when they socre a goal + /// public void ScorePoint() { // Game: score point scoreboard.ScorePoint(); @@ -105,6 +120,11 @@ public Rebounder AsRebounder() { return new Rebounder(forceMap, playerSprite.gameObj.GetComponent()); } + /// + /// set the paddles dimensions base off percentages of the viewport + /// + /// + /// public void SetLocalPaddleDimensionsFromVP(float vpXThickness, float vpYLength) { Vector3 bgScale = GameCache.BG_TRANSFORM.localScale; diff --git a/Assets/Source/Scripts/Pong/GamePlayer/_Pong-GamePlayer.cs b/Assets/Source/Scripts/Pong/GamePlayer/_Pong-GamePlayer.cs index f92133c..7242c4c 100644 --- a/Assets/Source/Scripts/Pong/GamePlayer/_Pong-GamePlayer.cs +++ b/Assets/Source/Scripts/Pong/GamePlayer/_Pong-GamePlayer.cs @@ -5,13 +5,23 @@ using UnityEngine; namespace Pong.GamePlayer { + /// + /// future class to be defined of how player information/actoins will be stored + /// public partial class Player {} - + /// + /// playerData class derived from ScriptableObjet to be later deifined + /// public partial class PlayerData : ScriptableObject {} //public partial class AIPlayerData : PlayerData {} - + /// + /// partial class on how the player will be controlled + /// public partial class PlayerController : MonoBehaviour {} + /// + /// class stores keys players will use to control their paddle + /// public class PlayerControls { public readonly KeyCode Up, Down; public PlayerControls(KeyCode up, KeyCode down) { diff --git a/Assets/Source/Scripts/Pong/_Pong.cs b/Assets/Source/Scripts/Pong/_Pong.cs index 699b313..759b07e 100644 --- a/Assets/Source/Scripts/Pong/_Pong.cs +++ b/Assets/Source/Scripts/Pong/_Pong.cs @@ -7,6 +7,9 @@ using Pong.GamePlayer; namespace Pong { + /// + /// defines global game constants that will be used for the player, ball, and win conditions + /// public static class GameConstants { // must be >= 1 because velocity is required public const uint BALL_Y_MAX_DERIVATIVE = 3; // velocity + (acceleration, acceleration') @@ -39,7 +42,9 @@ public static class GameConstants { public static readonly char[] WINDOWS_BANNED_CHARS = {'\\', '/', ':', '*', '?', '\"', '<', '>', '|'}; } - + /// + /// stores the values of the game that other functions will call when initialzing the player and ball + /// public static class GameCache { // cached at the beginning of GameManager public static Transform BG_TRANSFORM; @@ -54,7 +59,9 @@ public static class GameCache { // A single hotkey (likely M) will mute the sounds public static bool MUTE_SOUNDS = false; // when turned on, audio won't be played } - + /// + /// vectors used to update the player's and ball's position? + /// public static class GameHelpers { public static Vector2 ToVector2(Vector3 vector) { return new Vector2(vector.x, vector.y);