The map class you created in lab has faster find operations than a list because of binary search. However, it has slower add operations due to maintaining a sorted order. This deficit can be mitigated if many of the add operations to the map occur in batch at program start-up by pre-optimizing the order the data is loaded. The platform game that you created for assignment 4 loads all of its sprites into a list when it first starts and never adds more later. This is an excellent example of a program that would benefit from using a map. Furthermore it is possible to quantify the difference between the map and list by comparing the number of frames-per-second at which the game runs.
For this assignment you will modify the platform game from assignment four to utilize either a list, as it already does, or a map for storing sprites. The file Platformer.tar.gz contains a modified version of the platform game from assignment four. The program no longer uses the Timer class to update every 30 milliseconds. Instead, it uses a while loop to update as frequently as it can. This loop also calculates the amount of time that elapses between frames to calculate the number of frames-per-second at which it is running. The other modification is that the PlatformList class is a sub-class of an abstract class Platforms. There is also a new class PlatformMap that also extends Platforms and implements storing the platform sprites in a two-dimensional map. Because both of these storage classes extend the Platforms class, it is very easy to switch between the two data structures. It is simply a matter of calling the appropriate constructor.
Complete the game by adding your Map2D class. You will also need to add an iterate method to your Map2D class. This method should return an iterator that efficiently iterates over the sprites in the map that are contained inside the specified rectangle. In order to do this the constructor of the iterator should use binary search to locate the indices of the first sprite in the specified rectangle. Then, each call to next
and hasNext
should iterate over the elements in the map without needing to search again.
Finally, modify the game by changing the play mechanics and adding images. You can take the gravity and jumping out to make a top down dungeon crawling or adventure game. You can add automatic scrolling to create a side scrolling shooter or driving game.
Submission: Tar and submit your code on the course blackboard site.