Learn Create Your Own Split Screen

Next Page

Remember a few lessons back our very useful, but kind of unwieldy, ImagesTouching function?

The inside of the function was a bit complicated, but even if we accepted the function as magic provided for our use, it was still pretty awkward to make use of:

if (ImagesTouching(bug_x, bug_y, BugImg, melon_x, melon_y, MelonImg)) { score= score + 1; }

Now, thanks to objects, each variable is not just a single variable, but a package of everything we need to know about that particular game sprite, and all the properties travel together.

Once we redefine ImagesTouching to use our objects, it becomes much more pleasant to use:

if (ImagesTouching(bug, melon)) { score= score + 1; }

The definition of ImagesTouching is perhaps slightly more obscure than it was before, but we don't care too much about that. It's only defined once, but we'll use this function time and time again.