Al Heck

Speed Test using If-Else Statements

Time for a small test to make a speed system.

For this test, we want to press the A/S keys to equally speed up/slow down our game object. We can’t go into the negatives and we can go past 20 for our current speed.

First we lay out our variables:

Next we want to implement our logic. Every time we press A, we decrease by our increment. If we go below 0, set the current speed back to 0. Vice versa, every time we press S, we add to our increment and we can never go past 20. Everything in the middle means we get a debug.log reminding us to hurry up.