main.cpp
author Mohammed Khoory
Wed Jul 07 19:11:38 2010 -0400 (22 months ago)
changeset 5 bcf3d6f89c62
parent 0 fbd3d2dbfcdf
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 /*
     2  --- main function is here ---
     3  */
     4  
     5 #include <stdio.h>
     6 #include "9Game.h"
     7 #include "sprload.h"
     8 extern "C" {
     9 	#include "keyboard.h"
    10 }
    11  
    12  int main(int argc, char ** argv)
    13  {
    14 	int rc = 0;
    15 	Game9 nineGame = Game9();
    16 	
    17 //	rc  = nineGame.run();
    18 	GraphicsDevice graphics;
    19 	SpriteLoader spriteloader;
    20 	
    21 	GraphicsDevice::enter_mode13h();
    22 	try{
    23 		spriteloader.loadFile("C:\\9game\\DJGPP\\sprites\\sprites");
    24 		
    25 		
    26 		printf("debugging info:\n");
    27 		printf("Width: %ld Height: %ld \n", spriteloader.getWidth(), spriteloader.getHeight());
    28 		printf("Size: %lu\n" , spriteloader.getSize());
    29 		
    30 //		testSprite = spriteloader.getSprite(0,0,110,110);
    31 		spriteloader.setPalette(graphics);
    32 		spriteloader.unloadFile();	
    33 
    34 	}
    35 	catch(int e)
    36 	{
    37 		printf("an exception has occurred\n");
    38 		switch(e){
    39 		case SpriteLoader::FileNotLoadedException:
    40 			printf("Tried to run a function when no file loaded\n");
    41 			break;
    42 		case SpriteLoader::BadFileNameException:
    43 			printf("File name is not valid\n");
    44 			break;
    45 		case SpriteLoader::BadFileException:
    46 			printf("This file is bad. makes no sense\n");
    47 			break;
    48 		case SpriteLoader::CannotReadException:
    49 			printf("This file is not supported\n");
    50 			break;
    51 		}
    52 		rc = 1;
    53 	}
    54 	
    55 	if(rc != 0)
    56 		return rc;
    57 	
    58 	// attach keyboard ISR
    59 	rc = attach_keyboard_handler();
    60 	if(rc !=0)
    61 	{
    62 		detach_keyboard_handler();
    63 		return rc;
    64 	}
    65 
    66 	while(nineGame.finished() == GameManager::NOT_FINISHED)
    67 	{
    68 		nineGame.processKeys();
    69 		nineGame.updateState();
    70 		nineGame.render(graphics);
    71 	}
    72 	
    73 	// detach keyboard ISR
    74 	detach_keyboard_handler();
    75 	
    76 //	nineGame.~Game9();
    77 	GraphicsDevice::leave_mode13h();
    78 	return rc;
    79  }