Variables!
Day 2 — Aspiring Game Creator
2D Game Dev: Galaxy Shooter
Variables! The building blocks of programming.
Like a storyteller uses nouns to describe a scene when building their story, a game dev creates and defines variables in order to help construct their world.
In the previous article, movement was introduced to start to make our game feel like a game.
What does the game object need to move?
Acceleration, momentum, velocity … speed.
So give the spaceship some speed and it moves … unfortunately Unity/C# doesn’t have a clue what speed is so it’s up to the game dev to create it.
A couple variables for collecting user input, creating a vector variable for direction, a speed variable of 8 and finally using the translation method with the three required variables: direction, speed and Time.deltaTime … voila movement/speed!
Today’s lesson is building the boundaries for the spaceship: top & bottom and left & right, and an additional option for wrapping the ship from left-to-right or right-to-left which will be assigned to the ‘Q’ key.
Can’t simply drop those variables in the script and magically becomes the boundaries needed — I’ll discuss this process more tomorrow and how pseudo code is used to put down the logic and then create the C# code.
Below is the final implementation for the spaceship boundaries.
Initially the Ship Wrapping variable is disabled, then enabled.