Pseudocode and Wrapping the Player!

Stacy Clifton
3 min readNov 16, 2021

--

Objective: To understand pseudocode and practice it through Player position!

What is pseudocode?

Pseudocode is a plain language description of what we want to accomplish using code. It helps organize our thoughts so we can more effectively write our code, giving us a chance to break down the steps before attempting complicated code.

Let’s look at an example of pseudocode on our Player script. Let’s have the Player to wrap to the other side once they go off screen on the X-axis.

How do we go about doing this? Well, first we need to figure out at what point the Player goes off screen (on both the left and right sides of the screen). We can do this by manually dragging the Player off screen in Unity and checking the X value in the Inspector.

Remember to check the Game View (bottom panel) for when the Player goes off screen!

We can see that the Player goes completely off screen at about X = 18.5 on the right, meaning it will be X = -18.5 on the left. So if the Player position goes above 18.5, we want them to “wrap around” to the other side, and the same goes for when the Player position goes lower than -18.5.

Let’s hop into Visual Studio and begin writing our pseudocode!

When writing pseudocode (or anything that you don’t want to compile or affect your final code), type // at the beginning to comment it out. It will turn green to let you know that it is just a comment that won’t affect your code. Let’s finish the pseudocode and turn it into C# code!

Pseudocode is a great way to organize what you want to achieve in code before diving in. Once you successfully implement the code, you can delete the pseudocode for a cleaner project (but feel free to keep comments in if they help clarify what’s happening in code!).

Pseudocode is also helpful when collaborating with others, allowing them to see your thought process and help you find solutions. Code can be very complicated, so it’s a great way to break it down and focus on the goal instead of getting overwhelmed by functions and syntax.

And there we go! We’ve successfully mapped out our objective in pseudocode and put it into action in Unity! Join me tomorrow as we dive into more exciting code in our space shooter game!

--

--

Stacy Clifton

Currently pursuing my passion of game development at GameDevHQ!