コード例 #1
0
ファイル: Main.cpp プロジェクト: thankmelater23/Asteroid-3d
void DarkGDK ( void )
{
	loadSettings();
	loadResources();

	//ASTEROID LOADED OBJECTS
	Large_Roid loadLarge(1);
	Big_Roid loadBig(1);
	Medium_Roid loadMedium(1);
	Small_Roid loadSmall(1);
	Tiny_Roid loadTiny(1);

	Ship *player = new Jet;

	Asteroid * roids[NUM_ASTEROIDS];
	setAsteroids(roids, NUM_ASTEROIDS);

	dbMakeObjectSphere(MACH_GUN_FIRE, 2);
	dbTextureObject(MACH_GUN_FIRE, MACH_GUN_FIRE);


	while ( LoopGDK ( ) )
	{
		astroReset(roids, NUM_ASTEROIDS);
		astroidPhysics(roids, NUM_ASTEROIDS);
		collision(roids, NUM_ASTEROIDS, player);
		player->moveShip();

		

		pause();
		if(dbSpaceKey())
		{
			dbWait(1000);
		}
		dbSync ( );
	}
	


	memoryLeak();
	return;
}
コード例 #2
0
ファイル: Main.cpp プロジェクト: thomas-mitchell/2DShooter
// 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;
}
コード例 #3
0
ファイル: PhysX.cpp プロジェクト: Fliper12/darkbasicpro
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 ( );
	}
}