On the Road again


Author Message
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 1479
Posted: 02:53pm 12 Oct 2022      

  stanleyella said  @Martin.H

How do lines like bc%=col%(7-3*((Sin((((120-f%)/40)^3)+dist%))>0))
work in real time ???

The Spaces of the upper strips at the Border is less than the Lower ones,
for this:
Sin((((120-f%)/40)^3)+dist%)
f% is the y position of the Line and Dist% is just a Framecounter to simulate driving.
calculates a point in a Sinewave at which frequency increases starting with the Phase dist%
I use this to deside to use Color 7 (White) or Color 4 (Red) for the Border

bc%=col%(7-3*((Sin((((120-f%)/40)^3)+dist%))>0))
the color value is 7 but subtracts 3 if the Result of the Sine-Function is Positiv.
Look at the Listing in the first Post.
It is the Function get_BorderCol%() from the Listing above in a conpressed form.
Cause every function call takes some time and it is called 120 times per Frame, so I put it in one basic Line.
The Idea for this method is from javidx9 (one Lone Coder) who used the same calculation in his video.
Code-It-Yourself! Retro Arcade Racing Game - Programming from Scratch (Quick and Simple C++)

easy, eh  
Maybee I've been working with Excel for to long, where you're used to summarizing formulas
Edited 2022-10-13 02:09 by Martin H.