Pseudocode is an informal manner of describing what you want your code to do. The advantage of writing pseudocode is it helps you design your algorithm without being bothered whether it’s syntactically correct or not. Aside from that, you do not need to spend this time implementing the code and revising it frequently wasting time and effort. As the saying goes, failing to plan is planning to fail.
Here’s an example of pseudocode:
/*
You need to check this condition per frame
Get user input from player.
Check if player position overlaps the Y boundaries of the screen.
If it overlaps the Y boundary, clamp the position up to the max Y boundary.
If it overlaps the X boundary, make the player be shown on the opposite edge of the screen.
*/
Here’s an example of implementing the pseudocode:
void Update()
{
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
Vector3 direction = new Vector3(horizontalInput, verticalInput, 0);
transform.Translate(direction * Time.deltaTime * _speed);if (transform.position.x >= 11.3f)
{
transform.position = new Vector3(-11.3f, transform.position.y, 0);
}
else if (transform.position.x <= -11.3f)
{
transform.position = new Vector3(11.3f, transform.position.y, 0);
}
transform.position = new Vector3(transform.position.x, Mathf.Clamp(transform.position.y, -3.8f, 0), 0);
}
As you can see above, the implementation deals with if-else conditions, Input system, Vectors and math functions and can be hard to read compared to pseudocode. Implementation will actually get more complicated and harder to comprehend when adding more conditions and features. Good thing there’s pseudocode, which you can use document what your code is actually doing.