A question:
There is a game, a space shooter; when a ship is destroyed, a player gets points, when points pass a certain threshold, then an event will increase the difficulty of the game. It is necessary to do so that every n points (for example, every thousand) increase the difficulty. There is no problem with the increase in complexity. You just need to trigger an event if the points are multiples of n. But then the question is how to be if, for example, a player has 980 points, every thousand needs to increase the difficulty, but when a ship is destroyed the player will get 40 points, then it turns out that the player will have 1020 points and the event will not work, but it would be necessary that would work. Help solve this problem.
- Check after adding points. 1040/1000 == Level - XelaNimed 1:16 pm
|
1 answer
Use integer division.
Pseudocode:
level = points/1000 + 1;
With points = 980, the level will be 0 (= 980/1000) + 1 = 1. With the number of points 1020, the level will be 1 (= 1020/1000) + 1 = 2, etc.
But in fact, you need to check not the multiplicity, but the fact that the number of points exceeded the specified level.
|