This is an old revision of the document!
Table of Contents
Robots Part 4
- This isn't really a 'robots' class, but we will use the robots game as a base.
- Our goal is to import and use a sprite sheet.
- We will need to make a SpriteSheet class.
- We will need to make a Sprite class.
- ALL objects will be drawn by blitting the sprite. The sprite class will pull the correct image for animation.
General Overview
Class SpriteSheet
This class will be created with the name of an image file and the dimensions of the sprites inside. It will then go through and categorize sprites by number. Rows are flattened into one row by attaching subsequent rows to the first row. The SpriteSheet will then contain an array of images, the index to which is the sprite number. That is all the SpriteSheet has to do; to be able to return a cut (cropped-in) image based on a number.
Class Sprite
A Sprite will have an array of images. It's purpose is merely to hold and manage the images for animation. The sprite class will return the correct image because it is given an index number for the array of images. Therefore 'Sprite' will be used in a parent class which contains sprite-specific information. I.E. a 'mario' character class would be responsible for requesting the correct image based on the state of the character. This is going to have to be hardcoded, but the good thing is that once you define the state of the character you know there will be a certain number of images found on the sheet in order, so it will not be something overly onerous to hardcode.
Thing Classes
As mentioned above, we now need a 'thing' class to track sprite animation. We will need to make Class Stone, Class Wall, Class Robot, and Class Player. The locations of every object are now to be stored in arrays. This will allow faster map drawing and faster collision detection because we only need to worry about the arrays of objects and not every little square on the map.
In fact it may be possible to 'not use' a map at all, if everything is kept in arrays. The only trouble with that is that without a game map, proximity checks (such as while moving) become difficult.
The solution to this is to create a 'tile' class which holds everying in that tile. Thus, gameMap becomes a 2d array (list!!) of tiles, and there is no wasted space here.