Pong Devlog
By Josh C
I began by searching for sprites suitable for the ball, paddles, and background. I discovered a pack on itch.io made by Esoe B. Studios (1). I integrated these as new game objects into the project, giving them rigid bodies and colliders. To initiate the ball's movement, I added the StartMovingInRandomDirection script and adjusted the Random.Range values so the ball would start moving randomly between 45 and 135 degrees or 225 and 315 degrees, preventing it from moving strictly in an upward or downward direction.
Next, I focused on implementing user controls. While considering modifying the PlayerMovement script, I decided to create a new, simpler script instead. This script enables keyboard input to control vertical movement (2) and implements constraints to prevent horizontal or rotational movement (3). It features a public movement speed variable acting as a multiplier to the vector2 movement. With ChatGPT's assistance (4), I modified this script to accommodate mouse input as well, assigning keyboard control to one paddle and mouse control to the other.
Since there was no sprite for the wall in the downloaded pack, I created a simple one in Paint. I added two as objects, equipped them with rigid bodies and colliders, and designated them as kinematic objects.
Initially, I attempted to write a script to induce ball bouncing before discovering that this could be achieved easily by applying physics material to the object.
I devised a script responsible for respawning an object if it goes out of bounds, borrowing code from the DestroyIfOffScreen script. I also incorporated code to invoke the random movement script, ensuring the ball starts moving in a random direction after respawning.
I created another sprite in Paint—a white dotted line—to be positioned in the middle of the game as a dividing line.
I developed a script for tracking scores. This script increments a score counter if the ball hits an invisible wall behind each player, featuring two distinct score counters, one for each player.
I introduced a configurable wait time before the ball's movement commences, which I later removed due to functionality issues.
Subsequently, I crafted a new script responsible for reflecting the ball off a paddle based on where it strikes. For instance, if the ball hits the top of the paddle, it bounces off at a somewhat upward angle. This proved to be the most challenging part of the task, requiring considerable time and iteration to perfect. Fortunately, with Ian's and ChatGPT's guidance (5), I achieved success.
At this juncture, I realized I had numerous scripts, some of which performed similar functions. I consolidated most of the scripts that were components on the ball object, resulting in one for the ball's movement, one for initiating movement and respawning the ball, and one for tracking scores.
With the core functionality of the game operational—random ball movement, correct angle reflection upon collision, independent paddle movement, ball reset upon point loss, and graphics implementation—only two tasks remained: UI and sounds.
I initiated the UI development by creating two TextMeshPro objects to display each player's scores. I modified the player score script to ensure the text objects display the current scores accurately. Then, I designed a new scene featuring a title and three buttons: play, audio, and quit. Realizing that audio and quit buttons weren't part of the CRA, I chose not to implement their functionality. However, the play button enabled game initiation. I also began crafting an endgame screen displaying "game over" and the winning player (adjusting the player score code for accurate output) along with a restart game button.
Finally, it was time for the last step: implementing sounds. I sourced three free sound files online (6) for game events, such as winning, ball collision, and point gain. These were integrated using a single audio source component on the ball object, with code added to enable dynamic sound playback.
After thorough testing and tidying up, the game was built and ready for upload to itch.io.
(1) https://myebstudios.itch.io/simple-ping-pong-assets
(2) https://chat.openai.com/share/d267f6f8-2009-40fa-acd6-c0158073327e
(3) https://chat.openai.com/share/04def5d5-bf83-49c9-8aef-49b04779c7b0
(4) https://chat.openai.com/share/5a0c40a7-0469-4709-bc3e-ad37124e2fb7
(5) https://chat.openai.com/share/c112fe36-ad47-442a-9a9d-d7310be5a801
a. Success-fanfare-trumpets-6185.mp3
b. Archi_sonar_03-1008206.mpg
c. 8-bit-powerup-6768
(7) https://chat.openai.com/share/eb61864a-7d11-49cd-b885-28ecd0da50b0
Files
Project Pong
A copy of the classic game Pong
Status | Released |
Author | buggy blister |
Genre | Simulation |