Exemplo n.º 1
0
void start()

{

	//Set window title
	dbSetWindowTitle("Peg/Square Game");

	//Set randomizer
	int seed = dbTimer();
	dbRandomize(seed);

}
Exemplo n.º 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;
}
Exemplo n.º 3
0
M4::M4()
{
	obj							 =	M4_GUN;
	maxAmmo			 = 40;
	currentAmmo		 = 40;
	remainingAmmo = 80;
	reloading				  = false;
	click						  = M4_CLICK;
	gunShot				  = M4_SHOT;
	reloadTimer		   = 800;
	shootingTimer	  = dbTimer();

	dbLoadObject("weapons//m4.dbo", obj);
	dbScaleObject(obj,100, 100, 100); //works in percentages e.g. 10 makes the gun 10 times smaller(10% of full size)
	dbLoadSound("sounds//M4A1 shot.wav", click);
	dbLoadSound("sounds//m4 click.wav",	  gunShot);
	
	
}
Exemplo n.º 4
0
void world::endingScreen(void *classPointer) { //Like a large version of our printText function
	dbWait(500);
	char messageTotal[1000] = "Player...";
	char messageTemp[100] = "";
	int totalLength = strlen(messageTotal);
	int tempLength = 0;
	int iteration = 0;
	int numberCharsToEnd = 0;
	dbSetTextSize(52);
	for(tempLength; LoopGDK() && tempLength <= totalLength; tempLength++) {
		messageTemp[tempLength] = messageTotal[tempLength];
		dbWait(200);
		dbText(200,80,messageTemp);
		dbSync();
	}
	while(dbKeyState(57) != 1) { //Show the message, with the blinking period controlled by your computer time. Waiting for you to press space.
		if((dbTimer()/1000) % 2 == 1)
		{
			messageTemp[tempLength-2] = '\0';
		}
		else {
			messageTemp[tempLength-2] = '.';
		}
		dbCLS();
		dbWait(40);
		dbText(200,80,messageTemp);
		dbSync();
	}
	dbCLS();
	strcpy(messageTotal,"Thank you very much for playing. This game has been coded in C++, one of my favorite languages, and it has been a blast to program. I hope you have enjoyed it as much as I have. I also wish to congratulate you on finding out the password. Either you're amazing at guessing, or you found the secret note... What an odd place to put it too...");
	totalLength = strlen(messageTotal);
	for(int i = 0; i <= totalLength; i++) { //Loop through our main message
		if(((i+1)+numberCharsToEnd) % 26 == 0) { //So if the next character in the string is going to hit the edge (if it's divisible by 26 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 behind us, at most 26 characters away. Let's also make sure that we stop if we reach 0. (Then no spaces behind us)
				for(int j = i; j >= 0 && iteration < 26; 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 this round, so let's keep looking. Since I'm looking further, I increment my variable to say how far back I'm looking. (remember 26)
				}
			}

			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
	for(int i = 500; i > -720 && LoopGDK(); i-=2) { //Move our text up the screen.
		dbCLS();
		dbWait(40);
		dbText(0,i,messageTotal);
		dbSync();
	}
	strcpy(messageTotal,"Thank you for playing");
	for(int i = 0; i <= 255 && LoopGDK(); i+=5){ //Fade our message in
		dbInk(dbRGB(i,i,i),dbRGB(0,0,0));
		dbCLS();
		dbWait(40);
		dbCenterText(310,150,messageTotal);
		dbSync();
	}
	for(int i = 255; i >= 0 && LoopGDK(); i-=5){ //Fade our message out
		dbInk(dbRGB(i,i,i),dbRGB(0,0,0));
		dbCLS();
		dbWait(40);
		dbCenterText(310,150,messageTotal);
		dbSync();
	}
	*(static_cast<world*>(classPointer)->finishedPntr) = 1; //You WON!!! YAY! Now let's tell the main darkGDK function that you won.

}
Exemplo n.º 5
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;
}