Why you need to be writing pseudo code
Day 3— Aspiring Game Creator
2D Game Dev: Galaxy Shooter
Pseudo code is a means of outlining the logic, major and minor — anything! — for the method, function, program currently being worked. There’s no wrong way to do it. It’s simply a rough draft possibly refined into a more structured blueprint to make the coding process more effective and efficient.
Everyone uses pseudo code, talking out aloud, ‘thinking’ about the process, it’s really whether or not it’s formally written.
Some of the key benefits are detecting logic errors which might have been bugs! Coding becomes more efficient with a solid plan already in place. The Pseudo code is a great starting point for documentation or code documenting.
Pseudo Code for Player Boundaries:
- If the player’s vertical is greater than 0, THEN lock the player at 0.
- If the player’s vertical is less than -5, THEN lock the player at -5.
- If the player’s horizontal is greater than 10.5 THEN lock the player at 10.5 UNLESS the ShipWrap option is enabled, THEN set the player’s horizontal to -10.5.
- If the player’s horizontal left is less than -10.5 THEN lock the player at -10.5 UNLESS the ShipWrap option is enabled, THEN set the player’s horizontal to 10.5.
- Testing purposes the Q key will enable/disable the ShipWrap option.
Pseudo Code for Lasers:
- Create LASER game object.
- Add material, color. Make any alterations, scaling.
- Move the laser game object into the PREFAB folder.
- Create Laser C#, launch laser UP and destroy when Y > yThreshold.
- Add a Trail renderer.
- Create an empty game object on spaceship for FirePoint.
- Capture user input SPACE to fire laser.
- Instantiate laser prefab at the FirePoint position.
Pseudo Code for Laser Cooldown System:
- Allow the spaceship to fire its laser every 0.5 seconds, call it Fire Rate
- Determine how much game time has passed, Time.time.
- Need a variable to check when the next time the player can fire: NextFire.
- NextFire initially will be ZERO, so the player can fire immediately.
- Once the player fires NextFire is set to Time.time + FireRate, so it’s in the future.
- In the Update loop test for user input && if Time.time is GREAT THAN NextFire.
- If the game time passed is GREAT THAN the Fire Rate, THEN allow the shot, otherwise, keep waiting.