A threshold is a finite limit to the values that a variable can have. Thresholds are commonly constructed using IF statements.
For example, let's say that we wanted a spaceship to have a minimum and maximum range for its speed, 0 being the minimum and 30 being the maximum. We would first check to see if the value is out of that range, and if so, set it back to the minimum or maximum.
if spaceshipSpeed < 0 then spaceshipSpeed = 0
if spaceshipSpeed > 30 then spaceshipSpeed = 30
Cage
This method of making thresholds is also useful for making cages. A cage is a 2-d, or 3-d set of thresholds designed to keep a game object in a specific area.
For example, let's say your game is designed with a screen that is 800x600 and you want to keep the spaceship in the screen area. You could set up a cage like this :
if spaceshipX < 0 then spaceshipX = 0
if spaceshipX > 800 then spaceshipX = 800
if spaceshipY < 0 then spaceshipY = 0
if spaceshipY > 600 then spaceshipY = 600
The above example does not take into account the width and height of the spaceship's sprite.
See Also
| This article is a stub. You can help improve Game Design Novice by expanding it. |