This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
notes:fall2024:projects:msi3 [2024/09/09 16:51] – created - external edit 127.0.0.1 | notes:fall2024:projects:msi3 [2024/10/03 01:38] (current) – [clearlist() function] jmerri10 | ||
---|---|---|---|
Line 3: | Line 3: | ||
=====independently moving enemies===== | =====independently moving enemies===== | ||
+ | One way to make randomly moving enemies is to have them spawn at random positions and going different directions at different speeds and bouncing around like PC screen saver! | ||
=====trigonometric functions===== | =====trigonometric functions===== | ||
+ | One way to use trigonometric functions is to model how your enemies will move. Maybe you want them to move in a circle? Or in a cosine wave? The Vircon " | ||
=====doubly-linked lists===== | =====doubly-linked lists===== | ||
+ | The primary difference between a singly and doubly-linked list is that a singly-linked list can only move forward in direction. For example, if you start at First, you can only move to the next until you hit the Last. With a doubly-linked list, you can move both to the next and previous node, offering more freedom in data access. However, keep in mind this will require more hygiene of the user to keep the pointers between nodes in order, both for making the nodes and removing them. | ||
=====mknode() function===== | =====mknode() function===== | ||
+ | To make a node you need to allocate memory for it, and initialize any values that need to be, for parameters you want to pass it anything that might change between nodes, like X and Y coordinates, | ||
+ | Don't forget that this is a non void function, meaning that it needs to **return a value**! | ||
+ | * There is no real difference between mknode() for a singly or a doubly-linked list | ||
=====rmnode() function===== | =====rmnode() function===== | ||
+ | To be to use **rmnode** you must first use **obtain()**. rmnode does what it sounds like it does, removes the given node. First you will want to check if the given node is **NULL** or not as there is no reason to remove something that doesn' | ||
+ | Don't forget that since this is not a void function it needs to **return a value**! | ||
+ | |||
=====mklist() function===== | =====mklist() function===== | ||
+ | For mklist one must name there list like they have the other struct objects in previous projects. And also just like previous projects one must allocate memory for said list! Or else there will be issues in your future! In typical faction one must set their lists attributes to **NULL**.\\ | ||
+ | Don't forget that this is a non void function, meaning that it needs to **return a value**! | ||
=====insert() function===== | =====insert() function===== | ||
+ | The insert function should operate a bit like the append function. However, this time it should allow a node to be placed wherever in the last as opposed to strictly the end. If desired, insert could be used like obtain(). | ||
=====append() function===== | =====append() function===== | ||
+ | To Append is to Add After, not Before. With doubly linked lists we can now go backwards. When adding stuff to the end of a list we need to check where we are adding the node to as that decides the rest of what we do. You need to check for if the Old_Node that New_Node is going after is: | ||
+ | 1. At the Start/ | ||
+ | 2. At the End | ||
+ | 3. or in the Middle | ||
+ | | ||
+ | One way to tell for the First option is to see if your list == NULL. If so then the lists two ends need to point to the New_Node and it's next and previous need to be NULL as there are no other nodes in the list. | ||
+ | |||
+ | One way to tell for the Second option is to see if your Old_Node == end of the list. If so then Old_Node now point to the New_Node which point' | ||
+ | |||
+ | The Third option is like the Second in terms of pointing but that New_Node needs to point at what Old_Node was pointing at next before it was pointing at New_Node. | ||
+ | |||
+ | Don't forget that since this is a function it needs a return value! | ||
=====obtain() function===== | =====obtain() function===== | ||
+ | For the most part, the obtain() function should be the same as the obtain() function in msi2. Loop through your list until you find the node you would like to obtain, then return the list. | ||
=====clearlist() function===== | =====clearlist() function===== | ||
+ | The clearlist() function should be the same as in msi2, as well. Loop through your list and remove each node in the list using your rmnode() function until the list reaches NULL (end of list). Make sure the list's start and end is NULL, then return the list. | ||
=====rmlist() function===== | =====rmlist() function===== | ||
+ | The rmlist function will call clearlist() function. After the list is successfully cleared, then the list itself will be deallocated from memory. |