DAY 020: MOD
#3
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.
Reply


Messages In This Thread
DAY 020: MOD - by SMcNeill - 11-28-2022, 02:00 AM
RE: DAY 020: MOD - by mnrvovrfc - 11-28-2022, 02:28 AM
RE: DAY 020: MOD - by TerryRitchie - 11-28-2022, 02:32 AM
RE: DAY 020: MOD - by bplus - 11-28-2022, 02:46 AM
RE: DAY 020: MOD - by Pete - 11-28-2022, 03:31 AM
RE: DAY 020: MOD - by Pete - 11-28-2022, 04:11 AM
RE: DAY 020: MOD - by vince - 11-28-2022, 01:45 PM
RE: DAY 020: MOD - by OldMoses - 11-28-2022, 08:36 PM



Users browsing this thread: 1 Guest(s)