Skip to content

← All articles

Notes on the Making of Ping Pong Color

, Game Design

Ping Pong Color is my first published game, built in Unity over 5–6 weeks, from design to release. Players navigate an endless level, breaking obstacles that match the ball's color as the colors change with the music.

This breakdown covers the systems I developed: procedural level assembly, PC and mobile controls, custom shaders, color palettes, and reactive audio with FMOD, along with mobile performance decisions.


Gameplay

In Ping Pong Color, the goal is to advance through an endless level and destroy obstacles to increase your score. Colors change in sync with the music.

When the ball and an obstacle have the same color, the collision destroys the obstacle. If their colors differ, the run ends.


Input systems

PC

On PC, you move a circular paddle with the mouse to hit the ball.


Mobile

The same input system would be awkward on mobile:

  • Moving the paddle around a small screen would be imprecise.
  • A finger would obscure part of the play area.
  • Friction on the screen could make continuous dragging uncomfortable.

I designed a separate input system for mobile devices.

You can swipe anywhere on the screen in the direction you want to hit the ball. Swipe speed also affects the force applied to it.


Level generation

The level generator assembles an endless sequence from prebuilt blocks:

  • Each block contains multiple gameplay elements and calculates its bounding box.
  • The generator spawns a batch of blocks.
    • It selects a random block from an array.
    • It places the next block at the end of the previous one, plus a defined offset.
  • As the ball approaches the end of the latest batch, the generator spawns another.

Blocks

I created 100 blocks by hand, combining individual objects such as moving spikes, black holes, and pickups.

Examples of some blocks used in the level generation


Bounding box generation

Bounding boxes generated by the script below.

BoundingBox.cs
// added to every block
public Bounds bounds;
 
[HideInInspector] public Vector2 offsetToMin;
float boxSizeX;
 
List<Collider2D> allColliders = new List<Collider2D>();
List<Transform> allTransforms = new List<Transform>();
 
void Awake() => GetBoundingBox();
 
public void GetBoundingBox() {
	GetAllColliders(transform);
	GetAllTransforms(transform);
	CalculateBoundingBox();
 
	// An offset from the origin of the
	// block to the min point of the bounds
	// Used in the level generator to avoid
	// overlapping when placing a new block
	offsetToMin = transform.position - bounds.min;
}
 
// We add all the colliders of the block
// recursively to allColliders
void GetAllColliders(Transform trans) {
	foreach (Transform t in trans) {
		Collider2D collider = t.GetComponent<Collider2D>();
		if (collider != null)
			allColliders.Add(collider);
 
		GetAllColliders(t);
	}
}
 
// We add all the transforms of the block
// recursively to allTransforms
void GetAllTransforms(Transform trans) {
	foreach(Transform t in trans) {
		allTransforms.Add(t);
		GetAllTransforms(t);
	}
}
 
void CalculateBoundingBox() {
	// we make use of the provided Bounds() class by Unity
	bounds = new Bounds(transform.position, Vector3.zero);
 
	// We add all the transforms to the bounds
	foreach (Transform t in allTransforms)
		bounds.Encapsulate(t.position);
 
	// We add the min and max positions
	// of the colliders to the bounds
	foreach (Collider2D col in allColliders) {
		bounds.Encapsulate(col.bounds.extents + col.bounds.center);
		bounds.Encapsulate(-col.bounds.extents + col.bounds.center);
	}
 
	// we only care about the x-size of the
	// bounding box (as the level is horizontal)
	boxSizeX = bounds.size.x;
}

Empty GameObjects can add a manual margin to individual blocks.


Palette system

Players can choose different color palettes for personal preference or to make the colors easier to distinguish.

Palettes are stored as ScriptableObject assets. Here's how one looks in the Inspector:


Color-blindness palette

While researching palette accessibility, I found this GDC talk and Coblis, a tool for simulating how an image may appear with different types of color blindness.

I focused the alternative palette on making its colors distinguishable for players with deuteranomaly.


The black hole

The black hole obstacle attracts the ball and nearby particles.

Its shader is a post-processing effect, so it distorts the UI as well as the game world.

BlackHole.shader
sampler2D _MainTex;
uniform float2 _Position; // in screen space
uniform float _Radius;
 
fixed4 frag (v2f i) : SV_Target{
	float ratio = _ScreenParams.x / _ScreenParams.y;
	fixed2 pos = _Position / _ScreenParams;
	float2 offset = pos - i.uv;
 
	float rad = length (offset);
	float intensity = sin (_Time.y * 1.5);
	float deformation = 1 / pow (rad, abs(intensity)) * _Radius * intensity;
 
	offset.x *= ratio;
	offset = i.uv + normalize (offset) * 0.001;
	offset = offset * (1 - deformation);
 
	return tex2D (_MainTex, offset);
}

Sound

I learned REAPER and FMOD during the project to create sounds and music that react to gameplay.

The music is divided into sections corresponding to different game states. This is how the arrangement looks in REAPER:

In Unity, an enum tracks the current game state and drives the GameState parameter in FMOD. When the state changes, FMOD transitions to the corresponding section of the track.


Mobile optimization

The combination of shaders, particles, and physics required some additional optimization for mobile.

Fixed DPI

For the mobile build, I used the fixed-DPI option under Project Settings → Resolution and Presentation, with a target of 280 DPI. Reducing the rendering resolution this way produced the largest performance improvement in this project.

Performance mode

I also added a performance-mode toggle to the settings menu. The script below disables every post-processing effect except Lens Distortion:

public void SetPerformance(bool performance) {
	PostProcessProfile profile = postFxVolume.sharedProfile;
	foreach (PostProcessEffectSettings setting in profile.settings)
		if (!setting.GetType().Equals(typeof(LensDistortion)))
			setting.active = !performance;
}