Well, for any game or program really, a sorted list is necessary. So if you are able to do them and make a tut about it that would be not only amazing but extremely useful to the amateur gamedev community.
To begin explaining sorted lists, there are many types. A lot of them are only used professionally and kept secret to the company. Most people make their own rather than use a template. (I don't think that's true but it sounds good XD)
Anyway, Types of Sorted Lists:
Linear Sort/Search Method:
This one is pretty self explanatory, its also the most common of search/sort methods. All arrays are sorted Linear. Meaning a straight line. When you search through them you start at 0: the beginning, and you finish at n: the number of elements in the array.
Another method, is a Odd/Even search/sort method.
Another method, is Bubble Sort:
This one brings the lowest values in the list to the top and the highest values, it pushes to the bottom. This is sometimes called priority sorting. This method is good for linked lists.
Linked lists:
This is where one value in the array is the parent of one or more values in the array. Then you can chain downward into the array. Linked lists are the most efficient way of using arrays.
Example of the usefulness of a linked list:
Say you have 30 enemies on the screen. You need to check and update the life values of them. If the game is space invaders then you might want to start your search with the enemies with the highest Y value (the ones closest to the player). Then you can sort them in a row by their x value. So when you run through your list its:
Showing how each value is linked
- Code: Select all
M M M M M M M M M M
Î Î Î Î Î Î Î Î Î Î
M M M M M M M M M M
Î Î Î Î Î Î Î Î Î Î
M->M->M->M->M->M->M->M->M->M