Beispiel #1
0
/*
Creates a really simple scene for our game - A cube robot standing on
a floor. As the module progresses you'll see how to get the robot moving
around in a physically accurate manner, and how to stop it falling
through the floor as gravity is added to the scene. 

You can completely change all of this if you want, it's your game!

*/
MyGame::MyGame()	{
	gameCamera = new Camera(-30.0f,0.0f,Vector3(0,450,850));

	Renderer::GetRenderer().SetCamera(gameCamera);

	CubeRobot::CreateCube();

	ammo = 0;
	force = 0;
	/*
	We're going to manage the meshes we need in our game in the game class!

	You can do this with textures, too if you want - but you might want to make
	some sort of 'get / load texture' part of the Renderer or OGLRenderer, so as
	to encapsulate the API-specific parts of texture loading behind a class so
	we don't care whether the renderer is OpenGL / Direct3D / using SOIL or 
	something else...
	*/
	cube	= new OBJMesh(MESHDIR"cube.obj");
	cube->SetTexture(SOIL_load_OGL_texture(
			TEXTUREDIR"Barren Reds.jpg", SOIL_LOAD_AUTO,
			SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));
	quad	= Mesh::GenerateQuad();
	
	sphere	= new OBJMesh(MESHDIR"ico2.obj");
	sphere->SetTexture(SOIL_load_OGL_texture(
			TEXTUREDIR"swirl.tga", SOIL_LOAD_AUTO,
			SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));

	//fireEmitter = new FireEmitter();
	
	heightmap = new HeightMap(TEXTUREDIR"gametech.raw");
	heightmap->SetTexture(SOIL_load_OGL_texture(
			TEXTUREDIR"cliff.jpg", SOIL_LOAD_AUTO,
			SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));
	heightmap->SetBumpMap(SOIL_load_OGL_texture(
			TEXTUREDIR"Barren Reds DOT3.jpg", SOIL_LOAD_AUTO,
			SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));

	/*
	A more 'robust' system would check the entities vector for duplicates so as
	to not cause problems...why not give it a go?
	*/
	for(int i = 0; i < NO_PROJECTILES; ++i) {
		projectiles[i] = BuildSphereEntity(25.0f);
		projectiles[i]->GetPhysicsNode().SetPosition(Vector3((51.0f* i) + 100.0f,500.0f,30.0f * i));
		projectiles[i]->GetPhysicsNode().sleep = true;
	}

	//allEntities.push_back(BuildFireEntity());
//	tempRobot = BuildRobotEntity();
//	tempRobot->GetPhysicsNode().SetPosition(Vector3(500.0f));
//	allEntities.push_back(tempRobot);
	allEntities.push_back(BuildQuadEntity(1000.0f));
	allEntities.push_back(BuildHeightmapEntity());
	
	BuildSprings();
	
	RenderCloth = new Cloth(cloth);
	RenderCloth->SetTexture(SOIL_load_OGL_texture(
			TEXTUREDIR"teatowel.jpg", SOIL_LOAD_AUTO,
			SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));
	allEntities.push_back(BuildClothEntity());
	
	for(int i = 0; i < NO_PROJECTILES; ++i) {
		allEntities.push_back(projectiles[i]);
	}

	for(vector<GameEntity*>::iterator i = clothEntities.begin(); i!=clothEntities.end() - 1; i++) {
		allEntities.push_back((*i));
	}

	

}
Beispiel #2
0
MyGame::MyGame()	{
	//Init variables
	ammo = 0;
	force = 0;
	waveno=0;
	
	cube	= new OBJMesh(MESHDIR"cube.obj");
	cube->SetTexture(SOIL_load_OGL_texture(
			TEXTUREDIR"Barren Reds.jpg", SOIL_LOAD_AUTO,
			SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));
	if(!cube->GetTexture()) {
		cout << "barren reds is playing up" << endl;
	}
	quad	= Mesh::GenerateQuad();


	enemy = new OBJMesh(MESHDIR"ico2.obj");
	enemy ->SetTexture(SOIL_load_OGL_texture(
			TEXTUREDIR"leo.png", SOIL_LOAD_AUTO,
			SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));
	if(!enemy->GetTexture()) {
		cout << "leopard skins f****d" << endl;
	}
	
	sphere	= new OBJMesh(MESHDIR"ico2.obj");
	sphere->SetTexture(SOIL_load_OGL_texture(
			TEXTUREDIR"swirl.tga", SOIL_LOAD_AUTO,
			SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));
	if(!sphere->GetTexture()) {
		cout << "swirl is BUM" << endl;
	}

	player  = new OBJMesh(MESHDIR"ico2.obj");
	player->SetTexture(SOIL_load_OGL_texture(
			TEXTUREDIR"cliff.jpg", SOIL_LOAD_AUTO,
			SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));
	if(!player->GetTexture()) {
		cout << "cliff is f****d" << endl;
	}
	
	CubeMap = SOIL_load_OGL_cubemap(
		TEXTUREDIR"interstellar_ft.tga", TEXTUREDIR"interstellar_bk.tga",
		TEXTUREDIR"interstellar_up.tga", TEXTUREDIR"interstellar_dn.tga",
		TEXTUREDIR"interstellar_rt.tga", TEXTUREDIR"interstellar_lf.tga", 
		SOIL_LOAD_RGB,
		SOIL_CREATE_NEW_ID,0);
	enemy->SetCubeMap(CubeMap);
	if(!CubeMap)
		cout << "cube maps f*****g broken";
	

	bumpShader = new Shader(SHADERDIR"bumpVertex.glsl",SHADERDIR"bumpFragment.glsl");
	if(!bumpShader->LinkProgram()) {
		return;
	}

	
	enemyShader = new Shader(SHADERDIR"perPixelVertex.glsl",SHADERDIR"enemyFragment.glsl");
	if(!enemyShader->LinkProgram()) {
		return;
	}

	heightmap = new HeightMap(TEXTUREDIR"stage1.raw");
	heightmap->SetTexture(SOIL_load_OGL_texture(
			TEXTUREDIR"grass.jpg", SOIL_LOAD_AUTO,
			SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));
	heightmap->SetBumpMap(SOIL_load_OGL_texture(
			TEXTUREDIR"grassbump.jpg", SOIL_LOAD_AUTO,
			SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));
	SetTextureRepeating(heightmap->GetBumpMap(),true);

	if(!heightmap->GetTexture()){
		cout << "height maps f*****g broken" << endl;
	}

	if(!heightmap->GetBumpMap()) {	
		cout << "height map bump map f*****g broken" << endl;
	}

	for(int i = 0; i < NO_PROJECTILES; ++i) {
		projectiles[i] = BuildSphereEntity(25.0f);
		projectiles[i]->GetPhysicsNode().SetPosition(Vector3((51.0f* i) + 100.0f,500.0f,30.0f * i));
		projectiles[i]->GetPhysicsNode().sleep = true;
	}

	for(int i = 0; i < NO_LASERS; ++i) {
		PhysicsSystem::GetPhysicsSystem().AddLaser(buildLaserEntity());

	}
	
	PlanePos = Vector3(2048.0f,100.0f,2048.0f); // y = 450.0f
	playerEntity = buildPlayerEntity();
	PhysicsSystem::GetPhysicsSystem().SetPlayer(playerEntity);
	allEntities.push_back(playerEntity);
	allEntities.push_back(BuildHeightmapEntity());
	
	for(int i = 0; i < NO_PROJECTILES; ++i) {
		allEntities.push_back(projectiles[i]);
	}

	for(int i = 0; i < 10; ++i) {
		EnemyEntity* ee = buildEnemyEntity(Vector3(PlanePos.x + 150,PlanePos.y + 150, PlanePos.z + (i * 90) - 270));
		ee->SetY(100.0f + (100.0f * i));
		allEntities.push_back(ee);
		PhysicsSystem::GetPhysicsSystem().AddEnemy((ee));
	}


	
	//gameCamera = new Camera(-2.0f,270.0f,Vector3(-360.0f,450.0f,3408.0f));
	//gameCamera = new TPCamera();
	gameCamera = new CameraMan(playerEntity->circleT);
	gameCamera->toggleLock();
	Renderer::GetRenderer().SetCamera(gameCamera);

	ret = new Reticule(WIDTH,HEIGHT,FOV,ASPECT, gameCamera);
	//ret->c = gameCamera;
	Renderer::GetRenderer().SetReticule(ret);
	PhysicsSystem::GetPhysicsSystem().SetReticule(ret);

	//ret = new Reticule();
}
/*
Creates a really simple scene for our game - A cube robot standing on
a floor. As the module progresses you'll see how to get the robot moving
around in a physically accurate manner, and how to stop it falling
through the floor as gravity is added to the scene. 

You can completely change all of this if you want, it's your game!

*/
MyGame::MyGame()	{

	destroyedEntities.clear();

	gameCamera = new Camera(-25, 180, 0.0f, Vector3(2000, 1350, -1100), Vector3(2, 2, 2));

	Renderer::GetRenderer().SetCamera(gameCamera);

	CubeRobot::CreateCube();

	/*
	We're going to manage the meshes we need in our game in the game class!

	You can do this with textures, too if you want - but you might want to make
	some sort of 'get / load texture' part of the Renderer or OGLRenderer, so as
	to encapsulate the API-specific parts of texture loading behind a class so
	we don't care whether the renderer is OpenGL / Direct3D / using SOIL or 
	something else...
	*/

	

	cube	= new OBJMesh(MESHDIR"cube.obj");
	quad	= Mesh::GenerateQuad();
	sphere	= new OBJMesh(MESHDIR"sphere.obj");
	quad->SetTexture(SOIL_load_OGL_texture(TEXTUREDIR"brick.tga", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, 0));
	quad->SetBumpMap(SOIL_load_OGL_texture(TEXTUREDIR"brickDOT3.tga", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, 0));
	heightmap = new HeightMap(TEXTUREDIR"terrain.raw");
	heightmap->SetTexture(SOIL_load_OGL_texture(TEXTUREDIR"GRASS.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));
	heightmap->SetBumpMap(SOIL_load_OGL_texture(TEXTUREDIR"GRASS_NORMAL.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));
	

	sphereTexture = (SOIL_load_OGL_texture(TEXTUREDIR"earth.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, 0));

	

	if (!quad->GetTexture() || !heightmap->GetTexture() || !heightmap->GetBumpMap())
	{
		return;
	}
	
	auto SetTextureRepeating = [](GLuint target, bool repeating)	{
		glBindTexture(GL_TEXTURE_2D, target);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, repeating ? GL_REPEAT : GL_CLAMP);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, repeating ? GL_REPEAT : GL_CLAMP);
		glBindTexture(GL_TEXTURE_2D, 0);
	};


	SetTextureRepeating(heightmap->GetTexture(), true);
	SetTextureRepeating(heightmap->GetBumpMap(), true);
 	SetTextureRepeating(quad->GetTexture(), true);
	SetTextureRepeating(quad->GetBumpMap(), true);
	SetTextureRepeating(sphereTexture, true);

	/*
	A more 'robust' system would check the entities vector for duplicates so as
	to not cause problems...why not give it a go?
	*/
//	allEntities.push_back(BuildRobotEntity());
	Quaternion newQuaternion = Quaternion::AxisAngleToQuaterion(Vector3(1.0f, 0, 0), 90);
	Vector3 position = Vector3(5000,-5000.0f,5000);
	allEntities.push_back(BuildQuadEntity(50000.0f,newQuaternion,position));
	//allEntities.push_back(BuildSphereEntity(200.0f));

	allEntities.push_back(BuildHeightmapEntity(HEIGHTMAP_SIZE, Vector3(0, 0, 0)));

	speedFactor = 10;
	sizeFactor = 5;

	CreateRestSpheres(Vector3(0, 2000.0f, 0), 250.0f);

	InitalizeTreesEntities();

	BuildDodgingEntities(250.0f, Vector3(0, 5000.0f, 0));
}