09-19-2020, 05:11 AM
(This post was last modified: 09-20-2020, 09:59 AM by RootBeerKing.
Edit Reason: updated code
)
Because of Tilengine and my undying dream to make video games, I've been learning C/C++ for the past few years, and I've finally got to the point where things are clicking into place in my brain, and I'm comfortable enough to actually start coding something.
So the first thing I did was I wrote a function that makes scrolling a background in multiple sections, like in the platformer demo, a little more automated/reusable. It would be great if Marc could add this to Tilengine natively, as I think it's a nice little function to have included with Tilengine and could be used for many different projects.
This is my first ever time writing an original function in C. If you see anything wrong with it, or anyways it could be done better, let me know! Otherwise I've tested it with the Platformer demo included with Tilengine and it worked fine, so it should work in any other project you paste it into.
Thanks for checking it out, have a great day.
So the first thing I did was I wrote a function that makes scrolling a background in multiple sections, like in the platformer demo, a little more automated/reusable. It would be great if Marc could add this to Tilengine natively, as I think it's a nice little function to have included with Tilengine and could be used for many different projects.
This is my first ever time writing an original function in C. If you see anything wrong with it, or anyways it could be done better, let me know! Otherwise I've tested it with the Platformer demo included with Tilengine and it worked fine, so it should work in any other project you paste it into.
Thanks for checking it out, have a great day.
Code:
/* \brief Scrolls an assigned Background, in user-defined sections at varying speeds, based on the size of the
assigned Background Section & Background Scroll Speed Arrays.
\param bg[] - an array that contains one or more Background scroll sections(sections must be first setup in raster_callback()).
\param bgspeed[] - an array of user-defined Background scroll speeds.
\param factor - a float value that assigns which direction to scroll the background sections.
(+ value for right or - value for left)
*/
void TLN_SetBackgroudScrolls(float bg[], float bgspeed[], float factor)
{
int scroll_section; // Holds the current section number of the horizontal scroll area.
int num_sections = *(&bg + 1) - bg; // Total number of sections, based off the size of the assigned bg[].
for (scroll_section = 0; scroll_section < num_sections; scroll_section++)
bg[scroll_section] += (bgspeed[scroll_section] * factor);
}