11-28-2022, 02:32 AM
(This post was last modified: 11-28-2022, 02:36 AM by TerryRitchie.)
I find MOD to be an essential tool for game programming. Using MOD I can select individual frames from within a frame counter.
For example, in the Pacman game I'm working on, the game runs at 75 frames per second. I need to know when 25 frames have have passed so I can blink the power pellets on and off. Now I could set up an individual frame counter like so:
PelletFlash = PelletFlash + 1
IF PelletFlash = 25 THEN
PelletFlash = 0
' My code here
END IF
However, when I write games I always created a master frame counter that is keeping track of which frame the game is on. So, I can simply do this:
IF MasterFrame MOD 25 = 0 THEN
' My code here
END IF
Same result. much less code.
MOD can be used to skip frames too. Take this for example:
IF MasterFrame MOD 5 THEN
'My code here
END IF
The above code will skip every number that is evenly divisible by 5 because the IF statement will see the result of 0 (zero) as false.
I've been using MOD with QB64 for years and it works just as it should.
For example, in the Pacman game I'm working on, the game runs at 75 frames per second. I need to know when 25 frames have have passed so I can blink the power pellets on and off. Now I could set up an individual frame counter like so:
PelletFlash = PelletFlash + 1
IF PelletFlash = 25 THEN
PelletFlash = 0
' My code here
END IF
However, when I write games I always created a master frame counter that is keeping track of which frame the game is on. So, I can simply do this:
IF MasterFrame MOD 25 = 0 THEN
' My code here
END IF
Same result. much less code.
MOD can be used to skip frames too. Take this for example:
IF MasterFrame MOD 5 THEN
'My code here
END IF
The above code will skip every number that is evenly divisible by 5 because the IF statement will see the result of 0 (zero) as false.
I've been using MOD with QB64 for years and it works just as it should.