sprload.h
author Mohammed Khoory
Wed Jul 07 19:11:38 2010 -0400 (22 months ago)
changeset 5 bcf3d6f89c62
parent 4 6366beccd211
permissions -rw-r--r--
Keyboard support, code movement, and TestManager

Major Changes
=============
- Added "testman.h" and "testman.cpp" to be used exclusively to test stuff (from a
GameManager perspective)
- Moved all the testing stuff to testman.cpp. 9game is just an empty class now to
manage other GameManagers
- Moved all the initializing stuff from 9Game to main. 9Game is like any other
GameManager now (just that it manages other GameManagers)
- Added keyboard.h and keyboard.c to handle keyboard interrupts (by replacing the
keyboard ISR)
- Keyboard is working :D can read more than one key at a time. (tested in
TestManager with WASD)

Minor Changes
=============
- Removed the exception throwing in SpriteLoader::unloadFile() (because it just
makes things unnecessarily complicated)
- added finished() to GameManager to indicate whether a GameManager is finished or
not
- Animation test + key control test. Sprite moves around depending on wasd key
input. (program ends when off screen to right)
- Set 0x00 as transparency color with drawSprite (TODO: change to make this
customizeable on runtime)
- Edited Makefile to reflect new changes

Notes
=====
- Animation seems to work nice and smooth in dosbox, slow in dosemu, so maybe I
should start testing in both dosemu and dosbox
- TODO: fix bug with drawSprite. When a sprite is drawn on the right of the screen
it "wraps around" to the other side by one pixel in width
     1 /* Raw bitmap sprite loader written by Mohammed Khoory
     2 	- reads three files: header file, palette file, and raw bitmap files
     3 	- can convert data from those files to sprites and set the DOS palette , etc.
     4 	
     5 	based a LOT on bmpload's structure lol
     6 */
     7 
     8 #ifndef SPR_LOAD
     9 #define SPR_LOAD
    10 
    11 #include <iostream>
    12 #include <fstream>
    13 #include <new>
    14 #include <string>
    15 #include <exception>
    16 #include "graphics.h"
    17 
    18 
    19 using namespace std;
    20 
    21 class SpriteLoader
    22 {
    23 protected:
    24 	// filestreams
    25 	ifstream rawBitmapFile;
    26 	ifstream paletteFile;
    27 	
    28 	// header
    29 	unsigned long int width;
    30 	unsigned long int height;
    31 	unsigned long int size;
    32 	
    33 	void resetHeader();
    34 
    35 public:
    36 	SpriteLoader();
    37 	~SpriteLoader();
    38 	
    39 	// opens all bitmap and palette and reads the header (filenames are passed in without extension)
    40 	void loadFile(const string& filename) throw(int, ios_base::failure);
    41 	void unloadFile();
    42 	
    43 	// get methods (allocates memory!)
    44 	// returns the entire bitmap as a char array
    45 	unsigned char * getBitmap() throw(int, bad_alloc, ios_base::failure);
    46 	// creates a sprite from the file and returns it
    47 	struct sprite * getSprite(int x1 = -1, int y1 = -1, int x2 = -1, int y2 = -1)
    48 		throw (int, bad_alloc, ios_base::failure);
    49 	
    50 	// palette setter
    51 	void setPalette(GraphicsDevice& graphics) throw (int, bad_alloc, ios_base::failure);
    52 	
    53 	unsigned long int getWidth() throw(int);
    54 	unsigned long int getHeight() throw(int);
    55 	unsigned long int getSize() throw(int);
    56 	bool isLoaded();
    57 	
    58 	// exceptions
    59 	static const int FileNotLoadedException = 1; // when trying to run a function but the file isn't loaded
    60 	static const int BadFileNameException = 2; // when the filename isn't valid
    61 	static const int BadFileException = 3; // when the file makes no sense (EOF)
    62 	static const int CannotReadException = 4; // When it encounters an unsupported file (no palette, etc.)
    63 	
    64 };
    65 	
    66 
    67 
    68 #endif