Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dylan_Hernandez: PongRL Week 1 #4

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions Assets/Source/Scripts/Pong/Ball/PongBall.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
//namespace Pong.Ball;
/*
This file is important because it handles aspects of the ball to make sure it functions properly. This includes when the balls scores, the ball velocity, and the serves
The method serve is important in this file. It serves the ball to the correct side at a random angle.
The method reset is important. It resets the ball's position.
The method DestroyBall is important. This makes the ball "dissappear" once it goes off the screen into the goal.
*/
using Pong.Ball;

using System;
Expand Down Expand Up @@ -114,6 +120,10 @@ public void Initialize(Player server) {
}

// serve the ball
/// <summary>
/// It serves the ball to the correct side at a random angle.
/// </summary>
/// <returns> void, doesnt return anything
public void Serve() {
(float angle, bool serverDesire) = serveAngles.Pop();
float speed = BALL_SPEED_VP; // in terms of viewport x percentage
Expand All @@ -133,12 +143,18 @@ public void Serve() {
public void Update() {
//TODO: feed to players?
}

/// <summary>
/// This makes the ball "dissappear" once it goes off the screen into the goal.
/// </summary>
/// <returns> void, doesnt return anything
public void DestroyBall() {
ballSprite.gameObj.SetActive(false);
ballSprite.controller.HaltTrajectory(); // stop the ball from going off the screen
}

/// <summary>
/// It resets the ball's position.
/// </summary>
/// <returns> void, doesnt return anything
public void Reset() {
// set position to start position
ballSprite.transform.localPosition = GetStartLocalPosition();
Expand Down
19 changes: 18 additions & 1 deletion Assets/Source/Scripts/Pong/Ball/PongBallController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
//namespace Pong.Ball;
/*
This file is very important due to the abilities it gives the pong ball. This file handles all of the physics behind the ball in order for it to work properly on the screen.
The method awake is simple but important. This allows the velocity and all the derivatives of the ball to be set to 0.
The method RetrieveBallTrajectory is important. This allows the code to capture the velocity and vector of the ball.
The method moveLocal is important. This allows the code to deal with movement, collision, and interactions as a result of that movement.
*/
using Pong.Ball;

using System;
Expand Down Expand Up @@ -40,7 +46,10 @@ public void Initialize(Action scoreProcedure, Action reboundProcedure) {

isInitialized = true;
}

/// <summary>
/// This allows the velocity and all the derivatives of the ball to be set to 0.
/// </summary>
/// <returns> void, doesnt return anything
void Awake()
{
// cancel motion: no more velocity and further derivatives! all 0
Expand Down Expand Up @@ -72,6 +81,10 @@ void Update()
}

//* Deals with Movement, and Collision + Interactions as a Result of that movement
/// <summary>
/// This allows the code to deal with movement, collision, and interactions as a result of that movement.
/// </summary>
/// <returns> void, doesnt return anything
public void MoveLocal(Vector3 localDelta_dt) {
// origin is in the center
Vector3 MAX_POS = BG_TRANSFORM.localScale / 2f;
Expand Down Expand Up @@ -172,6 +185,10 @@ public void SetFreeze(bool freeze) {

// [(x, y), (x', y'), (x'', y''), ...]
// in terms of viewport %
/// <summary>
/// This allows the code to capture the velocity and vector of the ball.
/// </summary>
/// <returns> returns a vector of the ball
public Vector2[] RetrieveBallTrajectory() {
Vector2 vpLocalPos = ToViewport(transform.localPosition);

Expand Down
15 changes: 12 additions & 3 deletions Assets/Source/Scripts/Pong/Ball/_Pong-Ball.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
// * NAMESPACE HEADER FILE

/*
Important for the pong ball logic and physics to work properly in the game.
The class PongBall in this file is extremely important; it handles how the velocity and collisions work with the ball
The class PongBallController in this file is extremely important; it holds the functionality of the actual goals when the ball scores in goal
The class BallGoal in this file is extremely important; it holds the boolean values for the left and right goal
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using Pong;

/// <summary>
/// Handles the velocity and collisions with the ball.
/// </summary>
namespace Pong.Ball {
/*
* Player lastTouchedBy
Expand Down Expand Up @@ -36,7 +43,9 @@ public static bool IsGoal(int ballStatus) {
return Mathf.Abs(ballStatus) == GOAL;
}
}*/

/// <summary>
/// When ball scores in a goal, it sets the left one to true and right one to false, allowing the code to operate smoothly with this ideology.
/// </summary>
public static class BallGoal {
public const bool LEFT = true;
public const bool RIGHT = false;
Expand Down
21 changes: 18 additions & 3 deletions Assets/Source/Scripts/Pong/GamePlayer/Player.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
//namespace Pong.GamePlayer;
/*
This file is very important for the overall program to work. This file allows the paddles to work. This file also collects data from the player, which will come into use fo rthe AI.
The method CreateNew is important in this file. This creates the paddles, as well as allows the users to set the name of the players.
The method update also seems very important. It looks like it updates the velocity and acceleration of the paddles.
The method SetLocalPaddleDimensionsFromVP is important. It sets the dimensions of the paddles and allows them to actually operate with those dimensions.
*/
using Pong.GamePlayer;

using System.Collections;
Expand Down Expand Up @@ -53,7 +59,10 @@ public Player(PlayerData playerData, GameObject sprite, PlayerControls controls,
// wrap it up
playerSprite = new ControlledGameObject<PlayerController>(sprite, controller);
}

/// <summary>
/// This creates the paddles, as well as allows the users to set the name of the players.
/// </summary>
/// <returns> returns the Player class with the values for the current player
public static Player CreateNew(string name, GameObject prefab, Vector2 viewportPos, PlayerControls controls, TMP_Text scoreText) {
// create paddle
GameObject paddle = GameObject.Instantiate(prefab, ToLocal(viewportPos), Quaternion.identity);
Expand Down Expand Up @@ -84,7 +93,10 @@ public Player Opponent {
get { return opponent; }
set { opponent = value; }
}

/// <summary>
/// It looks like it updates the velocity and acceleration of the paddles.
/// </summary>
/// <returns> void, doesn't return anything
public void Update() {
forceMap.PaddleVelocity = ToLocal(playerSprite.controller.GetViewportMotionTracker().velocity).y;
forceMap.PaddleAcceleration = ToLocal(new Vector2(0f, playerSprite.controller.GetViewportMotionTracker().Y_Acceleration)).y;
Expand All @@ -104,7 +116,10 @@ public void ScorePoint() {
public Rebounder AsRebounder() {
return new Rebounder(forceMap, playerSprite.gameObj.GetComponent<RectangularBodyFrame>());
}

/// <summary>
/// It sets the dimensions of the paddles and allows them to actually operate with those dimensions.
/// </summary>
/// <returns> void, doesn't return anything
public void SetLocalPaddleDimensionsFromVP(float vpXThickness, float vpYLength) {
Vector3 bgScale = GameCache.BG_TRANSFORM.localScale;

Expand Down
10 changes: 9 additions & 1 deletion Assets/Source/Scripts/Pong/GamePlayer/_Pong-GamePlayer.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
// * NAMESPACE HEADER FILE

/*
Important for the player controls and data to work properly.
The class PlayerControls in this file is extremely important; it holds the controls for the player to use (input for the game)
The class PlayerData in this file is extremely important; it holds the player data (which will probably be used for the AI)
The class PlayerController in this file is extremely important; it holds the behavior type for the controller
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// Holds controls for the player to use (up and down), holds the player data in this file for the AI, and also holds the behavior type for the controller.
/// </summary>
namespace Pong.GamePlayer {
public partial class Player {}

Expand Down
27 changes: 23 additions & 4 deletions Assets/Source/Scripts/Pong/_Pong.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
// * NAMESPACE HEADER FILE

/*
Important for the actual constants for the game to be stored and inputed somewhere. Also makes sure the game just functions properly.
The class GameConstants in this file is extremely important; it holds the constants of the game, such as the max score, and score to win
The class GameCache in this file is extremely important; it holds the context that is passed into GameManager (GameManager sets them)
The class GameHelpers in this file is extremely important; it creates the vectors and viewports for the code

THREE CHANGES:
Changed the win score for pong from 11 to 10. This made it so that it is the first person to 10 to win instead of 11.
Changed the max ball y derivative from 3 to 10. This allowed the ball to travel faster in the y dimension.
Changed the ball scale y from .05 to .1. This made the ball bigger
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using Pong.GamePlayer;

namespace Pong {
/// <summary>
/// Sets all of the constants for the game.
/// </summary>
public static class GameConstants {
// must be >= 1 because velocity is required
public const uint BALL_Y_MAX_DERIVATIVE = 3; // velocity + (acceleration, acceleration')
public const uint BALL_Y_MAX_DERIVATIVE = 10; // velocity + (acceleration, acceleration')

public const uint MAX_SCORE = 999; // any more than that and the UI kinda clips
public const uint DEFAULT_WIN_SCORE = 11; // 11 points is a win in the original Pong game!
public const uint DEFAULT_WIN_SCORE = 10; // 11 points is a win in the original Pong game!

// used for abnormal shots
public const float PADDLE_MASS = 1.00f;

// viewport y
public const float BALL_SCALE_Y = 0.05f;
public const float BALL_SCALE_Y = 0.1f;

// constants for if origin of a viewport is in the middle of the screen
public const float CENTER_ORIGIN_X = 0.5f;
Expand All @@ -39,6 +52,9 @@ public static class GameConstants {

public static readonly char[] WINDOWS_BANNED_CHARS = {'\\', '/', ':', '*', '?', '\"', '<', '>', '|'};
}
/// <summary>
/// Sets the context passed into GameManager and set by it.
/// </summary>

public static class GameCache {
// cached at the beginning of GameManager
Expand All @@ -55,6 +71,9 @@ public static class GameCache {
public static bool MUTE_SOUNDS = false; // when turned on, audio won't be played
}

/// <summary>
/// Sets vectors for the game to use.
/// </summary>
public static class GameHelpers {
public static Vector2 ToVector2(Vector3 vector) {
return new Vector2(vector.x, vector.y);
Expand Down