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

Julian_Duran:_PongRL_Week_1 #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

JP-Duran
Copy link

Code Exploration:

REQUIRED

Pong/_Pong.cs:

Contains declarations of many constants that are used throughout the game logic, as well as initializations for some crucial constants such as maximum score, default win score etc
class GameConstants: contains many constant declarations for game logic
class GameCache: caches global variables that are needed at runtime
float ballSpeedVP: global variable for ball speed

Pong/GamePlayer/_Pong-GamePlayer.cs

Contains declarations for several player-related variables and classes, as well as defining the namespace for player objects. Contains definitions of player controls (up/down).
KeyCode Up, Down: player controls for in-game
class Player: stores information about players, as well as many functions that will run during gameplay and are crucial to game logic

Pong/Ball/_Pong-Ball.cs

Class implementation for the ball object that is crucial to the game. Contains functions for different ball behavior during the course of the game, including serves, game resets, and scores. Also contains logic for keeping track of which player is currently the ‘attacker’.
OnScore(): resets ball and updates scoreboard when player scores
OnRebound(): updates ball state when player hits ball
Reset(): resets ball to initial position
SetLocalScaleFromVPY(): decides ball scale based on current size of game window

CHOSEN

Pong/Ball/PongBallController.cs

Handles physics, movement, and collision of the PongBall object. Calculates trajectory of ball movement based on viewport size and initial trajectory, as well as scoring logic and wall collisions.
void Update(): called every frame, moves ball on screen
void MoveLocal(): calculates ball movement for Update()
void ResetBallState(): resets the ball state (wow no way dude)

Pong/GamePlayer/Player.cs

Handles player creation and player actions such as initialization of paddle size and collision ‘walls’, paddle movement and sprite initialization, and scoring
void Update(): appears to be called every frame (?) to update paddle movement
void ScorePoint(): scores a point for the player (woahh no way)
void SetLocalPaddleDimensionsFromVP(): decides the on-screen dimensions of the paddle depending on the size of the game window

Pong/Physics/RectangularBodyFrame.cs

Handles collisions of game objects by calculating their edges and then running constant collision state calculations, only using this information when a collision actually occurs
void Update(): updates where the ‘edges’ of a game object are
bool CollidesWith(): determines if a collision between two game objects actually happened
vector2 CollisionPoint(): returns the angle of a collision between two game objects (?)

TESTING

Changes in Pong/GameManager.cs

ballSpeedVP = 0.90f 

playerSpeedVP = 3.00f 

I expected these changes to double the speed of the ball and triple the speed of the player paddle, but strangely these changes did nothing, even after reloading the project completely in Unity. This was confusing to me, as I searched deeper and could not find any other place where the ball speed or player speed variables are initialized. Ether I am missing something important about how global variables are handled, there is a problem with how I’m trying to edit the files, or something I don’t understand about Unity.

Changes in Pong/_Pong.cs

RIGHT_PADDLE_START_POSITION, LEFT_PADDLE_START_POSITION values swapped 

This was an interesting exploration, as it not only affected which controls mapped to which paddle on the screen but also the scoring. It appeared to reverse the scoring, where the ‘losing’ side instead received a point and the ‘winning’ side did not. This is predictable because the scoring is calculated based on which player touched the ball last, not which edge the ball went over, so essentially the scoreboard is reversed. If the two scoreboard numbers were switched this change would basically do nothing.

Changes in Pong/Physics/RectangularBodyFrame.cs

Swapped boolean output logic in CollidesWith() 

This change caused the ball to stay still in the center of the screen, appearing unable to move at all. I’m assuming this is caused by the game constantly expecting the ball to be involved in a collision, and therefore it is waiting for a direction to be specified to move the ball in after the collision. Obviously no direction is ever specified, so the ball stays still. Interestingly, after this discover I changed

Pong/_Pong.cs 

So that one of the paddles started in the center of the screen, shifted slightly upwards so it didn’t begin in contact with the ball. When the paddle is moved downwards into the ball, the ball shifts slightly in a random direction and then stops again. I would imagine the distance that the ball moves is the amount it travels in one ‘tick’ of game time before an update function is called again. Also, the fact that the ball moves in a seemingly random direction is interesting, as it indicates an element of randomness in the collision vector calculations (could be unexpected behavior due to location of collision with paddle).

Documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant