示例#1
0
void DarkGDK ( void )
{
	dbSyncOn   ( );
	dbSyncRate ( 60 );
	dbDisableEscapeKey();
	SetCurrentDirectory("GameContents");
	dbSetWindowTitle("Gaming Level");

	int xCord = 0;
	int yCord = 0;
	int direction = 2; //up = 1, down = 2, left = 3, right = 4;
	int finished = 0; //Used to state whether the game has ended
	
	house.setWorld("stage1",xCord,yCord);	
	dbColorBackdrop(dbRGB(0,0,0));
	house.finishedPntr = &finished;

	while ( LoopGDK ( ) && !finished)
	{
		movePersonOrWorld(xCord, yCord, direction);
		//dbCenterText(510,80,dbStr(dbMouseX()));
		//dbCenterText(550,80,dbStr(dbMouseY()));
		// update the screen
		dbSync ( );
	}

	return;
}
示例#2
0
void DarkGDK ( void )
{
	dbSetWindowPosition ( dbScreenWidth()/3 , dbScreenHeight()/6); 
	dbSyncOn   ( );
	dbSyncRate ( 60 );
	dbSetWindowSize (800, 600);	
	dbSetWindowTitle ( "Labyrinth V 1.0");

	dbDisableEscapeKey ( );
	dbRandomize ( dbTimer ( ) );
	dbCLS();
	//Play();
	Menu();
	//Mazemain(2);
	return;
}
示例#3
0
文件: Main.cpp 项目: joe90p/TetrisCpp
void Initialise()
{
	dbSetDisplayMode(SCREEN_WIDTH,SCREEN_HEIGHT,32);
	dbSetImageColorKey(255,0,255);
	
	// Turn on fullscreen mode
	dbSetWindowLayout(0, 0, 1);
	dbMaximizeWindow();
	// turn on sync rate and set maximum rate to 60 fps
	dbSyncOn   ( );
	dbSyncRate ( 60 );
	
	dbDrawSpritesFirst();
	
	//seed randomness
	srand ( time(NULL) );
}
示例#4
0
void world::dimArea(char interval[], void *classPointer) {
	int timeInterval = atoi(interval);
	int *currentXCord = static_cast<world*>(classPointer)->currentX; //Get our x coordinate from our class
	int *currentYCord = static_cast<world*>(classPointer)->currentY; //Get our y coordinate from our class
	int numberOfSpritesPlus1 = (static_cast<world*>(classPointer)->numOfSprites)+1;
	int numberOfImagesPlus1 = (static_cast<world*>(classPointer)->numOfImages)+1;

	dbSyncOn   ( );
	dbSyncRate ( 60 );
	dbLoadImage("background.png",numberOfImagesPlus1);
	dbSprite(numberOfSpritesPlus1,0,0,numberOfImagesPlus1);
	dbPlaySound(3);

	for(int i = 0; i < 255 && LoopGDK(); i+=5) { //Make our screen slightly darker each time. The speed is controlled by the timeInterval variable.
		static_cast<world*>(classPointer)->updateWorld(*currentXCord,*currentYCord);
		dbSetSpriteAlpha(numberOfSpritesPlus1,i);
		dbPasteSprite(numberOfSpritesPlus1,0,0);
		dbWait(timeInterval);
		dbSync();
	}

	for(int i = 0; i <= 100 && LoopGDK(); i+=5) { //Keep out screen dark for a little bit
		static_cast<world*>(classPointer)->updateWorld(*currentXCord,*currentYCord);
		dbWait(timeInterval);
		dbSync();
	}

	for(int i = 255; i >= 0 && LoopGDK(); i-=5) { //Now make our screen lighter so we can see again.
		static_cast<world*>(classPointer)->updateWorld(*currentXCord,*currentYCord);
		dbSetSpriteAlpha(numberOfSpritesPlus1,i);
		dbPasteSprite(numberOfSpritesPlus1,0,0);
		dbWait(timeInterval);
		dbSync();
	}

}
示例#5
0
void world::passGuess(char triggerName[], void *classPointer) { 

	int *currentXCord = static_cast<world*>(classPointer)->currentX;
	int *currentYCord = static_cast<world*>(classPointer)->currentY;
	int numbers = 0;
	char messageTotal[150] = "Well you seem to have the\nurge to leave. Why not stay\nfor a bit though? If you\ntruly want to go, then\nsimply guess the password:"******"";
	int spaceBar = 0;
	int correctPassword = 0;

	dbSyncOn   ( );
	dbSyncRate ( 60 );

	dbLoadImage("textBackground.png",numberOfImages+1);
	dbLoadImage("passwordBackground.png",numberOfImages+2);

	while(LoopGDK() && numbers <= 6){ //Now we have to sustain our environment again.
		dbWait(10); //How quick the message is typed
		//dbCenterText(30,90,dbStr(dbMouseX()));
		//dbCenterText(30,120,dbStr(dbMouseY()));

		static_cast<world*>(classPointer)->updateWorld(*currentXCord,*currentYCord); //Let's send our xCord and yCord that we got to our class.
		dbPasteImage((numberOfImages+1),385,0);
		dbPasteImage((numberOfImages+2),405,200);


		if(messageCharLength < totalLength) { //Just like in our printText function
			messageTemp[messageCharLength] = messageTotal[messageCharLength];
			messageTemp[messageCharLength+1] = '\0';
			messageCharLength++;
		}

		if(dbMouseClick() == 1) {
			if((dbMouseX() >= 449) && (dbMouseX() <= 472) && (dbMouseY() >= 273) && (dbMouseY() <= 297)) { //If our mouse is over the 1 button
				strncat(passwordInput,"1",1);
				numbers++;
				dbPlaySound(12);
			}

			else if((dbMouseX() >= 500) && (dbMouseX() <= 523) && (dbMouseY() >= 273) && (dbMouseY() <= 297)) { //If our mouse is over the 2 button
				strncat(passwordInput,"2",1);
				numbers++;
				dbPlaySound(12);
			}

			else if((dbMouseX() >= 552) && (dbMouseX() <= 575) && (dbMouseY() >= 273) && (dbMouseY() <= 297)) { //If our mouse is over the 3 button
				strncat(passwordInput,"3",1);
				numbers++;
				dbPlaySound(12);
			}

			else if((dbMouseX() >= 449) && (dbMouseX() <= 472) && (dbMouseY() >= 306) && (dbMouseY() <= 330)) { //If our mouse is over the 4 button
				strncat(passwordInput,"4",1);
				numbers++;
				dbPlaySound(12);
			}

			else if((dbMouseX() >= 500) && (dbMouseX() <= 523) && (dbMouseY() >= 306) && (dbMouseY() <= 330)) { //If our mouse is over the 5 button
				strncat(passwordInput,"5",1);
				numbers++;
				dbPlaySound(12);
			}

			else if((dbMouseX() >= 552) && (dbMouseX() <= 575) && (dbMouseY() >= 306) && (dbMouseY() <= 330)) { //If our mouse is over the 6 button
				strncat(passwordInput,"6",1);
				numbers++;
				dbPlaySound(12);
			}

			else if((dbMouseX() >= 449) && (dbMouseX() <= 472) && (dbMouseY() >= 339) && (dbMouseY() <= 363)) { //If our mouse is over the 7 button
				strncat(passwordInput,"7",1);
				numbers++;
				dbPlaySound(12);
			}

			else if((dbMouseX() >= 500) && (dbMouseX() <= 523) && (dbMouseY() >= 339) && (dbMouseY() <= 363)) { //If our mouse is over the 8 button
				strncat(passwordInput,"8",1);
				numbers++;
				dbPlaySound(12);
			}

			else if((dbMouseX() >= 552) && (dbMouseX() <= 575) && (dbMouseY() >= 339) && (dbMouseY() <= 363)) { //If our mouse is over the 9 button
				strncat(passwordInput,"9",1);
				numbers++;
				dbPlaySound(12);
			}

			else if((dbMouseX() >= 500) && (dbMouseX() <= 523) && (dbMouseY() >= 372) && (dbMouseY() <= 396)) { //If our mouse is over the 0 button
				strncat(passwordInput,"0",1);
				numbers++;
				dbPlaySound(12);
			}
			dbWait(300);
		}

		if(numbers == 7) { //Now let's create a local instance of our world for the new mesage
			strcpy(messageTemp,"");
			if(strcmp(passwordInput,"1433434") == 0) {//Now let's check to see if they got the password correct
				strcpy(messageTotal,"Congratulations! That's\nthe right password!");
				correctPassword++;
				dbInk(dbRGB(0,255,0),dbRGB(0,0,0));
				dbPlaySound(14);
			}
			else {
				strcpy(messageTotal,"Sorry, but that's not the\npassword. Please try again.");
				dbInk(dbRGB(255,0,0),dbRGB(0,0,0));
				dbPlaySound(13);
			}
			totalLength = strlen(messageTotal);
			messageCharLength = 0;
			while(LoopGDK() && spaceBar == 0) {
				dbWait(10);
				static_cast<world*>(classPointer)->updateWorld(*currentXCord,*currentYCord); //Let's send our xCord and yCord that we got to our class.
				dbPasteImage((numberOfImages+1),385,0);
				dbPasteImage((numberOfImages+2),405,200);
				
				if(messageCharLength < totalLength) { //Lets loop through our message again.
					messageTemp[messageCharLength] = messageTotal[messageCharLength];
					messageTemp[messageCharLength+1] = '\0'; 
					messageCharLength++;
				}
				if(dbKeyState(57) == 1) {
					spaceBar++;
				}

				dbSetTextSize(36);
				if(correctPassword == 1) {
					dbCenterText(512,12,"Correct");
					dbCenterText(512,42,"Password!:");

				}
				else {
					dbCenterText(512,12,"Incorrect");
					dbCenterText(512,42,"Password:"******"Guess The");
			dbCenterText(512,42,"Password:");
			dbSetTextSize(12);
			dbText(395,85,messageTemp);
			dbSetTextSize(36);
			dbText(455,220,passwordInput);
			dbSync();
		}
	}
	if(correctPassword == 1){
		for(int i = 0; i <= 100; i++) {
			dbDeleteSprite(i);
			dbSync();
		}
		endingScreen(classPointer); //Go to the ending screen, since you won!

	}
	dbWait(300);	
}
示例#6
0
void world::printText(char text[], void *classPointer) {
	char title[30]; //Our title for the object.
	char titleRow1[15] = "";
	char titleRow2[15] = "";
	char messageTotal[700]; //Our entire message
	char messageTemp[700]; //Our temp message that is printed to the screen.
	int *currentXCord = static_cast<world*>(classPointer)->currentX; //Our way to get the current xCord of our main class, using a static function. (Uses a class pointer)
	int *currentYCord = static_cast<world*>(classPointer)->currentY;
	int page = 0; //What page are we on? (Index numbered)
	int messageCharLength = 0; //What's the length of our temporary message?
	int totalLength; //The length of our entire message
	int iteration = 0; //Used later to see if we were able to find a space at the end of our text line.
	int numberCharsToEnd = 0; //How many characters are between our \n and the original end of the line?
	char *time = dbGetTime(); //dbGetTime returns the char pointer of a copy of the original time
	*(time+2) = '\0'; //Just an example. Same as "time[2] = '\0'" (educational purposes, and equivalent)
	int hour = atoi(time);
	int numberOfImagesPlus1 = (static_cast<world*>(classPointer)->numOfImages)+1;

	dbSyncOn   ( );
	dbSyncRate ( 60 );


	dbLoadImage("textBackground.png",numberOfImagesPlus1);
	
	if(strcmp(text,"bed") == 0) { //If our event text matches the given text
		strcpy(title,"Bed:");
		strcpy(messageTotal,"I\'m pretty tired. It\'s been a very long ");
		if(hour <= 12) {
			strncat(messageTotal,"morning. ", 9);
		}
		else if(hour >= 13 && hour <= 18) {
			strncat(messageTotal,"day. ",5);
		}
		else {
			strncat(messageTotal,"night. ", 7);
		}
		strncat(messageTotal,"I think I'm going to just take a rest...",40);
		
	}

	else if(strcmp(text,"characterTV") == 0) {
		strcpy(title,"Character\'s TV:");
		strcpy(messageTotal,"Oh. Awesome. My favorite show is on!");
		dbPlaySound(4);
	}

	else if(strcmp(text,"characterComputer") == 0) {
		strcpy(title,"Character\'s Computer:");
		strcpy(messageTotal,"Hm. It\'s been forever since I have done anything productive on here. Where is my flash drive?");
		dbPlaySound(7);
	}

	else if(strcmp(text,"familyTV") == 0) {
		strcpy(title,"Family TV:");
		strcpy(messageTotal,"Yes! Just in time to watch my favorite movie!");
		dbPlaySound(5);
	}

	else if(strcmp(text,"familyComp") == 0) {
		strcpy(title,"Family Computer:");
		strcpy(messageTotal,"What? There's a message from the creator of this game on my facebook: \"Hello. I hope you\'re enjoying the game. I put much time this game... Not sweat though. Programming doesn't usually make you sweat, thank goodness... As I was saying though, hope you're having fun!\"");
		dbPlaySound(6);
	}

	else if(strcmp(text,"tableFront") == 0) {
		strcpy(title,"Living Room Table:");
		strcpy(messageTotal,"The tiles are very smooth, and cold to the touch. Each one has its own wavy pattern to it, as the tiles rise and lower at seemingly random spots. Each appears as if it's slightly warped.");

	}

	else if(strcmp(text,"tableBack") == 0) {
		strcpy(title,"Living Room Table:");
		strcpy(messageTotal,"Where's the TV remote... Oh. Here it is. Now what do I watch though?");
	}

	else if(strcmp(text,"smallTable") == 0) {
		strcpy(title,"Small Table:");
		strcpy(messageTotal,"I'm not actually sure what goes here... poor little table.");
	}

	else if(strcmp(text,"couch") == 0) {
		strcpy(title,"Living Room Couch:");
		strcpy(messageTotal,"This is such a comfy couch. It\'s all cushiony and stuff. The pillows are awesome too. What a nice couch.");
	}

	else if(strcmp(text,"chair") == 0) {
		strcpy(title,"Living Room Chair:");
		strcpy(messageTotal,"The chair seems to radiate fall. It has various patterns, each created by an array of leaves changing their colors. The couch as a whole has a slight orange tint to it, from all of the various leaves... So very poetic!");
	}
	
	else if(strcmp(text,"mainCloset") == 0) {
		strcpy(title,"Living Room Closet:");
		strcpy(messageTotal,"There are several vaious objects behind the door, for no one to see. Not even I know what\'s behind there!");
	}

	else if(strcmp(text,"kitchnTable") == 0) {
		strcpy(title,"Kitchen Table:");
		strcpy(messageTotal,"The kitchen table has several various types of food on it. There are also four plates set out, each at its seemingly designated spot. It must be time for ");
		if(hour <= 11) {
			strncat(messageTotal,"breakfast. ", 11);
		}
		else if(hour >= 12 && hour <= 16) {
			strncat(messageTotal,"lunch. ",7);
		}
		else {
			strncat(messageTotal,"dinner. ", 8);
		}
	}

	else if(strcmp(text,"counter") == 0) {
		strcpy(title,"Kitchen Counter:");
		strcpy(messageTotal,"The counter has a few food items on it, each varying greatly from the other. They almost all seem to be focused around ");
		if(hour <= 11) {
			strncat(messageTotal,"breakfast ", 10);
		}
		else if(hour >= 12 && hour <= 16) {
			strncat(messageTotal,"lunch ",6);
		}
		else {
			strncat(messageTotal,"dinner ", 7);
		}
		strncat(messageTotal,"though. It makes sense, considering the time of day.",52);
	}

	else if(strcmp(text,"kitchnSink") == 0) {
		strcpy(title,"Kitchen Sink:");
		strcpy(messageTotal,"It's so shiny, I can almost see my reflection!...Wow. What a nice looking person!");
		dbPlaySound(8);
	}

	else if(strcmp(text,"fridge") == 0) {
		strcpy(title,"Fridge:");
		strcpy(messageTotal,"There are several different types of food in here...What? There's a note inside: \"Hello player. I hope you're enjoying this level. If this was the first thing that you went to though, I don\'t know what to tell you. Otherwise, congrats on exploring! By the way, remember the number 1433434...\"");
		dbPlaySound(9);
	}

	else if(strcmp(text,"stove") == 0) {
		strcpy(title,"Stove:");
		strcpy(messageTotal,"The stove is off. Good. Those pesky things can get hot sometimes!");
	}

	else if(strcmp(text,"upCloset") == 0) {
		strcpy(title,"Hallway Closet:");
		strcpy(messageTotal,"*Try to turn the door knob* Darn it. It's locked!");
		dbPlaySound(10);
	}

	else if(strcmp(text,"upperRoom") == 0) {
		strcpy(title,"Relative's Room:");
		strcpy(messageTotal,"*Get ready to turn door knob* Well... maybe I should wait to go in here. There's so much more to look at!");
	}

	else if(strcmp(text,"bathroom") == 0) {
		strcpy(title,"Bathroom:");
		strcpy(messageTotal,"Um...I'm not quite sure if I should narrate this... Let's say no for right now...");
	}

	else if(strcmp(text,"lowCloset") == 0) {
		strcpy(title,"Hallway Closet:");
		strcpy(messageTotal,"*Turn the door knob, but can't open the door* What? Seems like something is holding the door back... weird...");
		dbPlaySound(11);
	}



	////////////////////
	//
	//
	//Below is the main part of this function.
	//
	//
	////////////////////








	totalLength = strlen(messageTotal);

	//We're going to perform an initial check through our main message. This will allow us to already have all of the '\n's where they need to be, so we can easily
	//print our the message later. (Without any checking)

	for(int i = 0; i <= totalLength; i++) { //Loop through our main message
		if(((i+1)+numberCharsToEnd) % 29 == 0) { //So if the next character in the string is going to hit the edge (if it's divisible by 29 with no remainders, plus our difference which we'll talk about later.)
			if(messageTotal[i+1] == ' ') { //first check if our next character is a space. If so, then just change it out for a \n
				messageTotal[i+1] = '\n';
			}

			else { //I guess it wasn't. Now let's check to see if there's a space before this, at most 29 characters away. Let's also make sure that we stop if we reach 0. (That means we reached the beginning of the line, and there are no spaces in front of us)
				for(int j = i; j >= 0 && iteration < 29; j--) {
					if(messageTotal[j] == ' ') { //We found a character that's both a space and within our limits! Now we make it \n, tell the program that we found one by setting iteration to 0,
												 //And add the difference between our previous end of line, to our numberCharsToEnd variable.
						messageTotal[j] = '\n';
						iteration = 0;
						numberCharsToEnd = ((i+1)+numberCharsToEnd)-(j+1); //The j-1 makes it so our lines align properly.
						break;
					}
					
					iteration++; //we didn't find any spaces at this character, so let's keep looking. Since I'm looking further, I increment my variable to say how far back I'm looking. (remember 29 max!)
				}
			}

			if(iteration != 0) { //It looks like we didn't find any spaces. I guess we'll have to chop the word in half so it doesn't run off of the page (our only option)

				for(int j = totalLength; j >= i; j--) { //Move everything over to the right by 1.
					messageTotal[j+1] = messageTotal[j];					
				}
				totalLength++; //Remember: by moving everything over by 1, we made the string size 1 larger.
				messageTotal[i] = '\n'; //now insert our \n where we have our emprty space from moving everything over. (Technically our first duplicated space)
				iteration = 0; //Now, make sure to reset our iteration variable.
			}
		}
	}//End for i
	messageTotal[totalLength] = '\0'; //After all of that, we need to remember to have a \0 at the end of our string.

	if(strlen(title) > 15) { //If our title's going to run off of the page, we need to break it in half.
		char *spaceLocation = strchr(title,' ');
		while(strchr(spaceLocation + 1 ,' ') != NULL && (strchr(spaceLocation + 1 ,' ')-title) <= 15) { //Try and make our space cut-off as far on the first line as possible (get as much on the first line as we can)
			spaceLocation = strchr(spaceLocation + 1, ' ');
		}
		strncpy(titleRow1,title,spaceLocation-title); //Copy our first title row
		titleRow1[spaceLocation-title] = '\0';
		strncpy(titleRow2,title+(spaceLocation-title)+1,(strlen(title)-(spaceLocation-title))); //Now our second title row

	}

	dbWait(400);
	while(LoopGDK() && page < 1){ //Now we have to sustain our environment by pasting our images and sprites. Otherwise, they wouldn't stay on the screen as we type our characters.
		dbWait(10); //How quick the message is typed. (the delay)


		static_cast<world*>(classPointer)->updateWorld(*currentXCord,*currentYCord); //Let's send our xCord and yCord that we got to our class.
		dbPasteImage(numberOfImagesPlus1,385,0);

		if(dbKeyState(57) == 1) { //Did we press the space bar?
			dbWait(400);
			page++;
		}

		if(messageCharLength < totalLength) { //Now since we did all of our computation at the beginning, we can now just add characters to the string every time instead of looping through it.
			messageTemp[messageCharLength] = messageTotal[messageCharLength];
			messageTemp[messageCharLength+1] = '\0'; /*
													 NOTE: Since we check to make sure that our object is less than the total length, once it's equal to it, we have already added the \0 ahead of it! (the [messageCharLength+1] part)
													 */
			messageCharLength++;
		}

		if(titleRow1[0] != 0) { //If we had to split our title up
			dbSetTextSize(36);
			dbCenterText(512,12,titleRow1);
			dbCenterText(512,42,titleRow2);
			dbSetTextSize(12);
			dbText(395,85,messageTemp);

		}
		else {
			dbSetTextSize(36);
			dbCenterText(512,12,title);
			dbSetTextSize(12);
			dbText(395,55,messageTemp);
		}
		dbSync();
	}
	dbWait(400);
}
示例#7
0
文件: Main.cpp 项目: njt1982/BiPlane
// the main entry point for the application is this function
void DarkGDK ( void ){
	// Seed the random number generator
	srand(time(NULL));

	// Configure the engine to run as fast as possible (no frame rate cap)
	dbSyncOn();
	dbSyncRate(0);

	// If fullscreen, configure to a, currently, hard coded setting
	if (FULLSCREEN) {
		dbSetWindowOff();
		dbMaximizeWindow();
		dbSetDisplayModeAntialias(1680, 1050, 32, 1, 0, 0);
		dbSetCameraAspect(0, 1680.0 / 1050.0);
	}
	// Otherwise, configure a windowed display
	else {
		dbSetDisplayModeAntialias(1280, 800, 32, 1, 0, 0);
		dbSetCameraAspect(0, 1280.0 / 800.0);

		int winPosX = (dbDesktopWidth() - dbScreenWidth()) / 2;
		int winPosY = (dbDesktopHeight() - dbScreenHeight()) / 2;

		dbSetWindowPosition(winPosX, winPosY);
	}
	
	// Hide the mouse pointer; CEGUI handles this
	dbHideMouse();

	// This forces the timer to initialise
	MyTimer *timer = &MyTimer::get();
	float t;


	// Create a new Game State - this is a general game controlling class
	BiPlaneGameState *gsGame = new BiPlaneGameState();

	// We'll need a start-up menu	
	StartMenuGameState *gsMenu = new StartMenuGameState();
	
	// a Loop State holder
	bool loopState = TRUE;

	// This is for the Start Menu loop
	//while (LoopGDK()) {
	do {
		// Tick the timer & frame rate for this loop
		timer->tick();
		t = timer->getT();
		dbText(0, 0, dbStr((float)(1.0 / t)));

		loopState &= gsGame->update(t);
		loopState &= gsMenu->update(t);

		dbSync();
	} while (loopState && LoopGDK());
	


	switch (gsMenu->getState()) {
		// Start Server
		case 1 :
			break;

		// Start Client
		case 2 :
			break;

		// SOMETHING WENT WRONG!!
		default : exit(-5);
	}


	loopState = TRUE;
	// our main loop
	//while (LoopGDK()) {
	do {
		// Tick the timer & frame rate for this loop
		timer->tick();
		t = timer->getT();
		dbText(0, 0, dbStr((float)(1.0 / t)));

		// Issue an Update to the GameState system, passing the frameTime into it
		loopState &= gsGame->update(t);

		// Update the display
		dbSync();
	} while (loopState && LoopGDK());

	// Do a little house keeping
	delete gsGame;
	delete gsMenu;
	return;
}
示例#8
0
// Main entry point for the application
void DarkGDK ( void )
{
	dbSyncOn   ( );
	dbSyncRate ( FRAMES_PER_SECOND );
	dbSetWindowOff();
	dbSetDisplayMode( SCREEN_WIDTH, SCREEN_HEIGHT, 16 );
	dbDisableEscapeKey ( );
	dbHideMouse();
	dbSetImageColorKey ( 255, 0, 255 );	// Set transparency key for images
	dbDrawSpritesFirst();	// So that we can draw and write over sprites
							// Probably not necessary now since we don't actually use DGDK sprite objects

	dbLoadSound("bullet.wav",1);
	dbLoadSound("explosion.wav",2);
	
	// Load a new map
	Map *map = new Map();
	bool gotmap = map->loadFromFile( "testmap.txt" );
	assert( gotmap && "Loading map failed" );

	// Set up a camera looking at our map
	Camera camera;
	camera.setMap( map );
	camera.setScreenPosition( 10, 10 );
	camera.setSize( 380, 480 );

	// Camera2
	Camera camera2;
	camera2.setMap( map );
	camera2.setScreenPosition( 410, 10 );
	camera2.setSize( 380, 480 );
	camera2.getStateMachine()->changeState( CameraFollowWASDKeysState::getInstance() );

	

	// Set up some enemies
	for( int i=0; i<NUM_TEST_ENEMIES; i++ ) {
		Enemy *enemy = new Enemy();
		enemy->setPosition( Vector2D(rand()%SCREEN_WIDTH,rand()%SCREEN_HEIGHT) );

		// Set up a test path
		Path *path = new Path();
		path->addWaypoint( Vector2D(200.0,200.0) );
		path->addWaypoint( Vector2D(400.0,300.0) );
		path->addWaypoint( Vector2D(700.0,-30.0) );
		path->setLooped(true);
		enemy->setPath( path );

		// Create a new enemy using that path
		enemy->getStateMachine()->changeState( EnemyFollowPathThenDieState::getInstance() );
		//enemy->getStateMachine()->changeState( EnemyCollideWithPlayerState::getInstance() );
		//entityManager.registerEntity( enemy );

		MessageManager::getInstance()->dispatchMessage(0,0,messageCreateEntity,(i+1)*3,enemy);
	}

	dbPerformChecklistControlDevices();
	if( dbChecklistString(1) )
		dbSetControlDevice( dbChecklistString(1) );


	char debugText[100];

	// Set up variables to keep track of elapsed time
	double previousTime = (double)dbTimer();
	double currentTime;
	double elapsedTime;

	// Set up the target
	Vector2D target;
	target.x = 400;
	target.y = 300;

	
	double timeSinceLastSpawn = 10.0;
	double timeBetweenSpawns = 2.0;
	bool spacePressedLastFrame = false;

	Vector2D testPosition(1.0,3.0);
	Vector2D testHeading(1.0,0.0);
	Vector2D testSide = testHeading.Perp();
	Vector2D testPoint(-1.0,4.0);
	Vector2D testVector = TransformFromWorldToLocalSpace(testPoint,testHeading,testSide,testPosition);


	// main loop
	while ( LoopGDK ( ) )
	{
		// Calculate elapsed time
		currentTime = (double)dbTimer();
		elapsedTime = (currentTime - previousTime)/1000;
		previousTime = currentTime;

		MessageManager::getInstance()->update(elapsedTime);

		// Clear the screen white
		dbCLS( RGB( 0, 0, 0 ) );

		camera.update( 0.0 );
		//camera.draw();
		camera2.update( 0.0 );
		//camera2.draw();

		
		// Spawn a new enemy for testing
		
		timeSinceLastSpawn += elapsedTime;
		if( timeSinceLastSpawn > timeBetweenSpawns ) {
			timeSinceLastSpawn = 0.0;
			entityManager.spawnRandomWave();
			/*
			Enemy *enemy = new Enemy(Vector2D(100.0,-10.0));

			// Set up a test path
			Path *path = new Path();
			path->addWaypoint( Vector2D(200.0,200.0) );
			path->addWaypoint( Vector2D(400.0,300.0) );
			path->addWaypoint( Vector2D(700.0,-10.0) );
			path->setLooped(false);
			enemy->setPath( path );
			enemy->getStateMachine()->changeState( EnemyFollowPathThenDieState::getInstance() );
			entityManager.registerEntity( enemy );
			*/
		}
		
		


		// Update and draw the enemies
		entityManager.updateAllEntities( elapsedTime );
		entityManager.drawAllEntities();

		// Reset the first entities position
		if( dbMouseClick() == 2  ) {
			Vector2D position( dbMouseX(), dbMouseY() );
			Vector2D velocity( 0.0, -20.0 );
			//Vector2D velocity = target - position;
			//velocity.Normalize();
			//velocity *= 20.0;
			Bullet *bullet = new Bullet(position,velocity);
			entityManager.registerEntity( bullet );
		}

		// Reset the enemies randomly if space pressed
		if( dbSpaceKey() && spacePressedLastFrame == false ) {
			spacePressedLastFrame = true;
			Enemy *enemy = new Enemy();
			enemy->setPosition(Vector2D(100.0,-30.0));

			// Set up a test path
			Path *path = new Path();
			path->addWaypoint( Vector2D(200.0,200.0) );
			path->addWaypoint( Vector2D(400.0,300.0) );
			path->addWaypoint( Vector2D(700.0,-30.0) );
			path->setLooped(false);
			enemy->setPath( path );
			enemy->getStateMachine()->changeState( EnemyFollowPathThenDieState::getInstance() );

			entityManager.registerEntity( enemy );
		}
		
		if( !dbSpaceKey() )
			spacePressedLastFrame = false;

		// Update the target
		if( dbMouseClick() == 1 ) {
			target.x = dbMouseX();
			target.y = dbMouseY();
		}

		// Draw the target
		//DrawTarget( target );

		// Put any debugging messages here
		//sprintf( debugText, "Key code: %d", dbScanCode() );	// For finding keyboard scan codes
		//sprintf( debugText, "Elapsed time: %f", elapsedTime );
		//sprintf( debugText, "Entities: %d  FPS: %d", entityManager.getSize(), dbScreenFPS() );
		//sprintf( debugText, "%s", dbChecklistString (1) );
		//sprintf( debugText, "JoystickY: %d", joystickY );
		//sprintf( debugText, "FPS: %d", dbScreenFPS() );
		sprintf( debugText, "Score: %d", entityManager.getPlayer()->getScore() );
		//sprintf( debugText, "Player Position: %f,%f", entityManager.getPlayer()->getPosition().x, entityManager.getPlayer()->getPosition().y );
		//sprintf( debugText, "VectorX: %f VectorY: %f", testVector.x, testVector.y );
		//sprintf( debugText, "screenWidth: %d screenHeight: %d", dbScreenWidth(), dbScreenHeight() );

		// Print out the debug text
		dbInk( RGB(0,0,255), RGB(255,255,255) );
		dbText( 0, SCREEN_HEIGHT-20, debugText );

		// Draw scanlines
		//drawScanlines(3);

		// break out if escape has been pressed
		if ( dbEscapeKey ( ) )
			break;

		// update the contents of the screen
		dbSync ( );
	}

	// and now everything is ready to return back to Windows
	return;
}
示例#9
0
void DarkSDK ( void )
{
	// entry point for the application

	//dbSetDir ( "media\\" );

	// initial application set up
	dbSyncOn         ( );				// turn sync on
	dbSyncRate       ( 0 );			// set sync rate to 60
	dbBackdropOn    ( );				// switch backdrop off - no need to clear screen
	dbSetCameraRange ( 0.5f, 30000 );	// set the camera range

	PhysStart ( );

	
		// floor
	dbMakeObjectBox			 ( 1, 100, 1, 100 );
	dbPositionObject		 ( 1, 0, 0, 0 );
	dbColorObject			 ( 1, dbRgb ( 100, 0, 0 ) );
	PhysCreateStaticRigidBodyMesh ( 1 );
	

	/*
	dbLoadObject ( "bin1.x", 2 );
	//dbPositionObject ( 2, 0, 1 + dbObjectCollisionCenterY ( 2 ), 0 );
	dbPositionObject ( 2, 0, 0, 0 );
	//dbOffsetLimb ( 2, 0, dbObjectCollisionCenterX ( 2 ) * -1, dbObjectCollisionCenterY ( 2 ) * -1, dbObjectCollisionCenterZ ( 2 ) * -1 );
	PhysCreateRigidBodyBox ( 2 );

	dbMakeObjectCube ( 3, 5 );
	dbPositionObject ( 3, 20, 10, 0 );
	PhysCreateRigidBodyBox ( 3 );
	*/



	const NxReal height = 0.3;
	const NxReal width = 2;
	const NxReal length = 4;

	

	//dbMakeObjectBox ( 5, length*0.65, height*0.85, width*0.65 );
	dbMakeObjectBox ( 5, 3.5,3,4);
	dbPositionObject ( 5, 3.5,4,0 );

	dbMakeObjectSphere ( 10, 0.8 );
	dbMakeObjectSphere ( 11, 0.8 );
	dbMakeObjectSphere ( 12, 0.8 );
	dbMakeObjectSphere ( 13, 0.8 );

	CreateTruck ( );

	//dbLoadObject ( "corsa.x", 5 );
	//dbPositionObject ( 5, 0, 1, 0 );

	/*
	InitCar ( );
	car = CreateCar(NxVec3(0,5,0));
	*/

	

	dbPositionCamera ( 0, 20, -30 );


	
//	PhysCreateRigidBodyBox ( 10 );
	
	// loop round until escape key is pressed
	while ( LoopSDK ( ) )
	{
		if ( dbEscapeKey ( ) )
			return;

		if ( dbSpaceKey ( ) )
			PhysSetVelocity ( 10, 0, 20, 0 );

		UpdateTruck ( );

		//if ( dbSpaceKey ( ) )
		//	PhysSetVelocity ( 3, -20, 0, 0 );

		/*
		{
			bool bKey = false;

			if ( dbKeyState ( 17 ) == 1 )
			{
				gMotorForce = gMaxMotorPower;
				bKey = true;
			}

			if ( dbKeyState ( 31 ) == 1 )
			{
				gMotorForce = -gMaxMotorPower;
				bKey = true;
			}

			if ( dbKeyState ( 32 ) )
			{
				if (gSteeringValue > (-1.0f + gSteeringDelta))
					gSteeringValue -= gSteeringDelta;

				bKey = true;
			}

			if ( dbKeyState ( 30 ) )
			{
				if (gSteeringValue < (1.0f - gSteeringDelta))
					gSteeringValue += gSteeringDelta;

				bKey = true;
			}

			if ( !bKey )
			{
				gMotorForce = 0.0f;
				gSteeringValue = 0.0f;
			}

		}

		TickCar ( );
		*/
		

		// show the frame rate and handle user input
		showFPS   ( );
		userInput ( );

		PhysRun ( );
		PhysUpdate ( );

		// render everything
		dbSync ( );
	}
}