Search
Sections
System
Sort
Date
Nothing Found :(
What is Plr[]? Blog
28th March 2024
Got an email from Michael Fernie, yesterday, asking about my plr[] array, and how I always seem to be able to keep it under control.

-=-=-

How do you keep track of what they are? Is it a standard set you use for all games? I would need a list or maybe make the index all constant names. Like plyr[XPOS] so I wouldn't forget. Hehe.


One of the earliest things that Michael suggested to me, back at the start of JSE, was that there's no CONST's.
As you can clearly see, I just plain don't use them!!!

My methodology for the plr[] array has been standardised for a LONG time. I can't find exactly which project I started using it in, but it's going to be somewhere around 2002 or so, when I made the 8-bit Tiny Collection.



Though that doesn't specifically have a plr[] array, it does at least have a lot of my other standard arrays, along with one array(2500,25) multipurpose array.
I think I probably renamed that to plr[] at some point, likely when future languages didn't like me using "array" as the name of an array!

What's in those arrays is almost entirely the same thing each game, or at least for the first bunch of elements.

plr[1] and plr[2] are the X/Y co-ordinates
plr[3] and plr[4] are the sub-x and y, if the game is grid based, or the momentum if otherwise.
plr[5] is current rotation, plr[6] is the amount of spin the rotation is getting.
plr[7] is usually health or something, or occasionally an alpha value.
After that, it's open to interpretation, and whatever goes goes, with me cramming seemingly random values into the array.

And of course, it isn't just plr[], either. There's obj[] (objects), bul[] (bullets), bad[] (baddies) and more.
There's also grid[]. That's hung since the 8-bit tiny collection, too, but in JSE I tend to use the Tilemap, which is its own huge array.
You'll be happy to know, Shoebox still has grid arrays.



By constantly reusing these same arrays, and typically the same values within them, it makes it infinitely easier to reuse methods between different games. And if something goes awry, I can usually track it down easily by searching for ",5]" to find the rotation, or whatnot.
Of course, I'm always trying to find new and unique ways to do things, but having a standardised set of numbers to refer to helps immensely.

At times, I've thought about 'doing it proper', but at the end of the day, plr[1]+plr[3] is infinitely faster to type than Player[X_Position]+Player[X_Speed], and in the world of AGameAWeek, every second counts


"Cartoon @Derek's 8-bit Tiny Collection" by #ArtFlow.ai
Views 8, Upvotes 0  
Daily Blog , Gamedev
Site credits : Jayenkai made this.
(c) Jayenkai 2023 and onwards, RSS feed

Blog - What is Plr[]? - AGameAWeek