11-11-2022, 10:46 PM
I'm finishing up a Pac-Man clone. The game runs at 60 frames per second just like the original. During game play the speed of both Pac-Man and the ghosts are modified by level events and by advancing to higher levels. The speed of these objects is adjusted in 5% increments resulting in a loss of 3 frames per second per 5% loss:
100% = 60FPS (the fastest any object travels)
95% = 57FPS (60 * .95)
90% = 54FPS (60 * .9)
85% = 51FPS (60 * .85)
...
...
40% = 24FPS (60 * .4) (the slowest any object travels - ghost in the tunnel on level 1)
The usual way I adjust speeds in games is to use MOD and skip frames when the outcome is 0 (zero):
IF Frames MOD 20 THEN ... (every 20th frame will be skipped resulting in 95% or 57FPS)
IF Frames MOD 10 THEN ... (every 10th frame will be skipped resulting in 90% or 54FPS)
IF Frames MOD 5 THEN ... (every 5th frame will be skipped resulting in 80% or 48FPS)
..
.. Etc.
This can also be done in reverse for lower frame rates:
IF Frames MOD 20 = 0 THEN ... (all but three frames will be skipped resulting in 3FPS)
IF Frames MOD 10 = 0 THEN ... (all but six frames will be skipped resulting in 6FPS)
..
.. And so on
My problem is that neither of these methods will yield 85%(51FPS), 60%(36FPS), 55%(33FPS), 45% (27FPS), and 40%(24FPS) all of which I need.
There must be a simple formula I am overlooking to use within a 60FPS loop:
Object.FPS = 24
Frame = 0
DO
_LIMIT 60
Frame = Frame + 1
( If Object.FPS multiplied by some magical number= current frame then draw it ... formula here)
LOOP
I know I could set up individual frame counters for every object and skip, say, every 9th frame to achieve 85%. However, the original Pac-Man arcade machine had 16K of ROM and 2K of RAM and I can't imagine this was the procedure used with such limited space.
I also realize that I could simply use single precision numbers for x,y and add the percentage ( x! = x! + .85 : 85% for instance ) to get the desired outcome, but again, using single precision values in that era would have been a no-no given the speed over head.
How did those early programmers do this with Integers? Is there a formula I'm overlooking? Help me Obi-Wan math wizards, you are my only hope. I've stared at this for far too long now. My brain hurts.
100% = 60FPS (the fastest any object travels)
95% = 57FPS (60 * .95)
90% = 54FPS (60 * .9)
85% = 51FPS (60 * .85)
...
...
40% = 24FPS (60 * .4) (the slowest any object travels - ghost in the tunnel on level 1)
The usual way I adjust speeds in games is to use MOD and skip frames when the outcome is 0 (zero):
IF Frames MOD 20 THEN ... (every 20th frame will be skipped resulting in 95% or 57FPS)
IF Frames MOD 10 THEN ... (every 10th frame will be skipped resulting in 90% or 54FPS)
IF Frames MOD 5 THEN ... (every 5th frame will be skipped resulting in 80% or 48FPS)
..
.. Etc.
This can also be done in reverse for lower frame rates:
IF Frames MOD 20 = 0 THEN ... (all but three frames will be skipped resulting in 3FPS)
IF Frames MOD 10 = 0 THEN ... (all but six frames will be skipped resulting in 6FPS)
..
.. And so on
My problem is that neither of these methods will yield 85%(51FPS), 60%(36FPS), 55%(33FPS), 45% (27FPS), and 40%(24FPS) all of which I need.
There must be a simple formula I am overlooking to use within a 60FPS loop:
Object.FPS = 24
Frame = 0
DO
_LIMIT 60
Frame = Frame + 1
( If Object.FPS multiplied by some magical number= current frame then draw it ... formula here)
LOOP
I know I could set up individual frame counters for every object and skip, say, every 9th frame to achieve 85%. However, the original Pac-Man arcade machine had 16K of ROM and 2K of RAM and I can't imagine this was the procedure used with such limited space.
I also realize that I could simply use single precision numbers for x,y and add the percentage ( x! = x! + .85 : 85% for instance ) to get the desired outcome, but again, using single precision values in that era would have been a no-no given the speed over head.
How did those early programmers do this with Integers? Is there a formula I'm overlooking? Help me Obi-Wan math wizards, you are my only hope. I've stared at this for far too long now. My brain hurts.