Ejemplo n.º 1
0
/* Add in a number of specified stairs in a given direction
* 1 - positive x
* 2 - negative x
* 3 - positive z
* 4 - negative z
*/
GameEntitiesContainer EntityFactory::AddStairs(int number, int direction, D3DXVECTOR3 position, GameEntitiesContainer gc, int width, bool xStair)
{
	int x;
	for( x = 0 ; x < number ; x++)
	{
		switch( direction )
		{
		case 1:
			gc = AddWall(2, width + 1, D3DXVECTOR3(position.x + x  , position.y + x , position.z), gc, xStair);
			gc = AddFloor(width + 1, 2 , D3DXVECTOR3(position.x + x  , position.y + (x + 1) , position.z), gc);
			break;
		case 2:
			gc = AddWall( 2, width + 1, D3DXVECTOR3(position.x - x  , position.y + x  , position.z), gc, xStair);
			gc = AddFloor(width + 1, 2, D3DXVECTOR3(position.x - x , position.y + (x + 1) , position.z), gc);
			break;
		case 3:
			gc = AddWall( 2, width + 1, D3DXVECTOR3(position.x , position.y + x  , position.z + x ), gc, xStair);
			gc = AddFloor(2, width + 1, D3DXVECTOR3(position.x, position.y + (x + 1) , position.z + x ), gc);
			break;
		default:
			gc = AddWall( 2, width + 1, D3DXVECTOR3(position.x , position.y  + x , position.z - x ), gc, xStair);
			gc = AddFloor(2, width + 1, D3DXVECTOR3(position.x , position.y + (x + 1) , position.z - (x + 1) ), gc);
			break;

		}
	
	}
	return gc;
}
Ejemplo n.º 2
0
DWORD WINAPI HandleClients(LPVOID cl)
{
	SOCKET Client;
	Client = ((SOCKET *) cl)[0];
	cString string;	
	string.PutString(Client,"Welcome to your Smart-House Manager!\n>");
	while (string.ReadLine("", Client) && string != "exit")
	{		
		if (string == "add house")
		{			
			AddHouse(Client);
		}

		else if (string == "delete house")
		{
			DelHouse(Client);
		}

		else if (string == "print")
		{
			Print(Client);
		}
		else if (string == "add floor")
		{
			AddFloor(Client);
		}
		else if (string == "add room")
		{
			AddRoom(Client);
		}

		else if (string == "help")
		{
			PrintHelp(Client);
		}
		else if (string == "add window")
		{
			AddWindow(Client);
		}

		else
		{
			string.PutString(Client,"You've entered unknown command \n>");
			break;
		}
		string.PutString(Client, "");
	}

	return 0;
}
Ejemplo n.º 3
0
// placement of SGE's
void WorldGenerator::PopulateStatics()
{
	// divide the levelInfo.size
	// set x o y to negative, centering the
	// map around origo by going from -bound to +bound
	float bounds = mLI.size / 2;
	float x = -bounds;
	float y = -bounds;
	float cellSize = 200.0f;

	/*
		0-63	: reserved
		64-95	: wall
		96+		: floor
		129-160	: PacSpawn
		161-192	: GhostSpawn
		193-224	: Pill
		224+	: Boost
	*/
	for ( int i = 0; i < mapGrid.size(); i++ )
	{
		if ( mapGrid[i] <= 64 )
		{
			mGFS->quadtree->getNode( x * cellSize, y * cellSize  )->setWeight( INT_MAX );
		}
		if ( mapGrid[i] >= 64 && mapGrid[i] < 96)
		{
			AddWall( x * cellSize, y * cellSize );

			mGFS->quadtree->getNode( x * cellSize, y * cellSize  )->setWeight( INT_MAX );
		}
		if ( mapGrid[i] >= 96 )
		{
			AddFloor( x * cellSize, y * cellSize );
		}
		if ( mapGrid[i] > 192 && mapGrid[i] <= 224 )
		{
			AddPill( x * cellSize, y * cellSize );
		}

		x++;
		if ( x >= bounds )
		{
			x = -bounds;
			y++;
		}
		if ( y >= bounds )
			y = -bounds;
	}
}
Ejemplo n.º 4
0
GameEntitiesContainer EntityFactory::CreateLevel1(GameEntitiesContainer container, PlayerComponent *player, AIEntitiesInteractionContainer aiEntitiesContainer)
{
	int height = 25;
	int width = 50;
	int length = 50;
	// Create the bounding walls and floor
	// F1
	container = AddFloor( width , length, D3DXVECTOR3(0,0,0) , container);
	// W1
	container = AddWall( height, width, D3DXVECTOR3(0,0,0), container, true);
	// W2
	container = AddWall( height,length, D3DXVECTOR3(0,0,0) , container, false);
	// W3
	container = AddWall( height,width, D3DXVECTOR3( 49, 0,0), container, true);
	// W4
	container = AddWall(height,length, D3DXVECTOR3(0,0, 49 ), container, false);
	// F2
	container = AddFloor( width,length , D3DXVECTOR3(0,24 , 0), container);
	
	// Containing walls
	// W5
	container = AddWall( height, 26, D3DXVECTOR3(3 , 0, 0) , container, true);
	// W6
	container = AddWall( (int)(height/2), 18 , D3DXVECTOR3( 3 , 0 , 25 ), container, false);
	// W7
	container = AddWall( height, 7, D3DXVECTOR3( 24  , 0 , 25 ), container, false);
	// W8
	container = AddWall( (int)(height / 2), 8 , D3DXVECTOR3( 30 , 0, 25 ), container, false);
	// W9
	container = AddWall( height, 10 , D3DXVECTOR3( 37 , 0, 25 ) , container, false);
	// W10
	container = AddWall( height, 22, D3DXVECTOR3( 46 , 0, 4 ), container, true);
	// W11
	container = AddWall( height, 26, D3DXVECTOR3( 21 , 0, 4 ),  container, false);
	// W12
	container = AddWall( height, 5, D3DXVECTOR3( 21 , 0, 0), container, true, "Textures/door.png");
	// S1
	container = AddStairs( 6, 4, D3DXVECTOR3( 20 , 0 , 25 ), container, 4, false);
	// Plateau for staircase
	container = AddFloor( 5 , 5 , D3DXVECTOR3( 20  , 6 ,  16 ), container );
	// Second half of staircase
	container = AddStairs( 6, 1, D3DXVECTOR3( 24 , 6 , 16 ), container , 4, true);
	// Right  for 2nd floor
	container = AddWall( height, 10 , D3DXVECTOR3( 20 , 0 , 16 ), container, true);
	// Left stair wall
	container = AddWall( height, 6, D3DXVECTOR3( 24 , 0, 20 ), container, true);
	// W27
	container = AddWall( height, 6, D3DXVECTOR3( 30 , 0, 20 ), container, true);
	//
	container = AddWall( height, 7, D3DXVECTOR3( 24 , 0, 20 ), container, false);
	// 2nd floor at top of stairs
	container = AddFloor( 22 , 8, D3DXVECTOR3( 30  , (int)(height / 2) , 4 ), container);
	//
	container = AddWall( height, 11, D3DXVECTOR3(20 , 0, 16 ), container, false);
	// W21
	container = AddWall( (int)(height / 2) , 21 , D3DXVECTOR3( 37  , (int)(height / 2)  , 5 ), container, true);
	// W22
	container = AddWall( (int)(height / 2) , 8, D3DXVECTOR3(30  , (int)(height / 2) , 4 ), container, true);
	// W23
	container = AddWall( (int)(height / 2) , 18, D3DXVECTOR3(13  , (int)(height / 2) , 11 ), container, false);
	// W24
	container = AddWall( (int)(height / 2) , 30, D3DXVECTOR3( 13  , (int)(height / 2) , 11 ), container, true);
	// W25
	container = AddWall(( int)(height / 2), 16, D3DXVECTOR3( 20 , (int)(height / 2) , 25 ), container, true);

	// Floor for previous walls
	container = AddFloor( 6, 18 , D3DXVECTOR3( 13 , (int)(height/2)  , 11 ), container);
	container = AddFloor( 14, 8, D3DXVECTOR3( 13  , (int)(height/2)  , 16 ), container);

	// Add floor extending into main room
	container = AddFloor(8 , 2, D3DXVECTOR3( 19 , (int)(height/2) , 29 ), container);
	container = AddFloor(8 , 2, D3DXVECTOR3( 13 , (int)(height / 2) , 29 ), container);
	container = AddFloor(5 , 8, D3DXVECTOR3(13  , (int)(height / 2) , 36 ), container);

	// W26
	container = AddWall(height, 47 , D3DXVECTOR3( 0, 0, 40 ), container, false);
	// W27
	container = AddWall(height, 2, D3DXVECTOR3( 46 , 0 , 40 ), container, true);
	// W28
	container = AddWall( height, 47, D3DXVECTOR3( 0, 0, 41 ), container, false);


	vector<D3DRECT> collisions;
	D3DRECT c1;
	c1.x1 = 3*20;
	c1.y1 = 0;
	c1.x2 = 16*20;
	c1.y2 = 26*20;
	//collisions.push_back(c1);

	AStarPathfindingGraph* graph = PathfindingUtil::CreateAStarGraphFromFloors(50, 50, 20, 20, D3DXVECTOR3(0, 0, 0), collisions);
	//create AI controller character
	
	GameEntity* aiEntity1 = this->CreateAIEntity(
		&container, 
		D3DXVECTOR3(400, 60, 700), 
		D3DXVECTOR3(10, 40, 10), 
		5,
		D3DCOLOR_RGBA(255, 0, 0, 255),
		0, 
		BasicEnemy, 
		aiEntitiesContainer, 
		graph, 
		player);
	GameEntity* aiEntity2 = this->CreateAIEntity(
		&container, 
		D3DXVECTOR3(700, 60, 700),
		D3DXVECTOR3(10, 40, 10),
		5,
		D3DCOLOR_RGBA(0, 255, 0, 255), 
		1, 
		RangedEnemy, 
		aiEntitiesContainer,
		graph, 
		player);
	GameEntity* aiEntity3 = this->CreateAIEntity(
		&container, 
		D3DXVECTOR3(350, 60, 700), 
		D3DXVECTOR3(10, 40, 10),
		5,
		D3DCOLOR_RGBA(255, 0, 0, 255), 
		2, 
		BasicEnemy, 
		aiEntitiesContainer,
		graph, 
		player);
	GameEntity* aiEntity4 = this->CreateAIEntity(
		&container, 
		D3DXVECTOR3(650, 60, 650), 
		D3DXVECTOR3(10, 40, 10),
		5,
		D3DCOLOR_RGBA(0, 255, 0, 255), 
		3, 
		RangedEnemy, 
		aiEntitiesContainer, 
		graph, 
		player);
	GameEntity* aiEntity5 = this->CreateAIEntity(
		&container, 
		D3DXVECTOR3(550, 60, 550), 
		D3DXVECTOR3(10, 40, 10),
		5,
		D3DCOLOR_RGBA(255, 0, 0, 255), 
		4, 
		BasicEnemy, 
		aiEntitiesContainer, 
		graph,
		player);
	GameEntity* aiEntity6 = this->CreateAIEntity(
		&container, 
		D3DXVECTOR3(600, 60, 650), 
		D3DXVECTOR3(10, 40, 10),
		5,
		D3DCOLOR_RGBA(0, 0, 255, 255), 
		4, 
		HealerEnemy, 
		aiEntitiesContainer, 
		graph,
		player);
	//GameEntity* aiEntity6 = this->CreateAIEntity(&container, D3DXVECTOR3(650, 60, 700), D3DXVECTOR3(10, 40, 10), D3DCOLOR_RGBA(0, 255, 0, 255), 5, RangedEnemy, aiEntitiesContainer, graph);
	
	return container;

}
Ejemplo n.º 5
0
void Map::LoadMap(char* fileName, ResourceManager& resMan) {
	////////////////////////////////////////////////////////////////FILE I/O STUFF
	std::stringstream ss;
	std::ifstream file;
	char lineType;
	Terrain tempTerrain;
	D3DVECTOR pos, corner1, corner2, size;
	float rot;
	int zone;
	PrimStruct *tempPrim;
	PrimObj tempObj;
	sPoint tempSpawn;
	tempObj.mat = &mat;
	tempObj.Tex = resMan.loadTexture("uvtest.png",0,0,0,0,D3DFMT_UNKNOWN,D3DPOOL_MANAGED,D3DX_DEFAULT,D3DX_DEFAULT,D3DCOLOR_XRGB(255,0,255),0);
	file.open(fileName);
	if(file.is_open()) {
		while(!file.eof()) {
			lineType = ' ';
			file>>lineType;
			if(lineType == '#') {
				//comment line
				file.ignore(256,'\n');
			} else if(lineType == 'f'||lineType == 'F') {
				//floor
				//get top left
				file>>size.x;
				file>>size.z;
				file>>size.y;
				//get bottom right
				file>>pos.x;
				file>>pos.y;
				file>>pos.z;
				//zone
				file>>zone;
				ss<<"Floor"<<size.x<<"x"<<size.y<<"x"<<size.z;

				tempPrim = resMan.loadPrim(ss.str().c_str(),size.y,size.x,size.z);
				D3DXMatrixIdentity(&tempObj.matrix);
				D3DXMatrixTranslation(&tempObj.matrix,pos.x,pos.y,pos.z);
				tempObj.primInfo = tempPrim;
				renderInfo.push_back(tempObj);

				tempTerrain.Init(pos,tempPrim,FLOOR);

				AddFloor(tempTerrain);

				floorZone.push_back(zone);
				file.ignore();
			} else if(lineType == 'w' || lineType == 'W') {
				//walls
				//get top left
				file>>size.x;
				file>>size.z;
				file>>size.y;
				//get bottom right
				file>>pos.x;
				file>>pos.y;
				file>>pos.z;
				//zone
				file>>zone;

				ss<<"Wall"<<size.x<<"x"<<size.y<<"x"<<size.z;

				tempPrim = resMan.loadPrim(ss.str().c_str(),size.y,size.x,size.z);
				D3DXMatrixIdentity(&tempObj.matrix);
				D3DXMatrixTranslation(&tempObj.matrix,pos.x,pos.y,pos.z);
				tempObj.primInfo = tempPrim;
				renderInfo.push_back(tempObj);

				tempTerrain.Init(pos,tempPrim,WALL);

				AddWall(tempTerrain);
				wallZone.push_back(zone);
				file.ignore();
			} else if(lineType == 's' || lineType == 'S'){
Ejemplo n.º 6
0
void TestFunction1(scene& scene1)
{

	AddSphere(scene1, vector3(1.5, -1.5, 0), 0.5, rgbf(0, 0, 1), false);
	//AddSphere(scene1, vector3(1, 1, 0), 0.5, rgbf(0, 1, 1), true);
		
	sphere_object* s1 = new sphere_object(0.5, vector3(1.5, -1, 0));
	s1->natrual_colour = rgbf(0, 0, 0);
	s1->reflective = true;
	s1->I_refl = 1;
	s1->k_spec = 1;	
	s1->ambient_colour = rgbf(0, 0, 0);
	s1->shininess = 100;
	//scene1.add_object(s1);

	sphere_object* s2 = new sphere_object(0.5, vector3(1.5, 1, 0));
	s2->transparent = true;
	s2->transparency = 0.9;
	s2->refindex = 0.9;
	scene1.add_object(s2);

	rgbf red(1, 0, 0);
	rgbf green(0, 1, 0);
	rgbf blue(0, 0, 1);
	rgbf yellow = red + green;
	rgbf magenta = red + blue;
	rgbf cyan = green + blue;


	AddWall(scene1, vector3(3, 0, -0.5), vector3(0, 1, 0), green * 0.7);
	AddWall(scene1, vector3(0, 3, -0.5), vector3(-1, 0, 0), red* 0.7);
	AddWall(scene1, vector3(-3, 0, -0.5), vector3(0, -1, 0), blue* 0.7);
	AddWall(scene1, vector3(0, -3, -0.5), vector3(1, 0, 0), yellow* 0.7);
	

	AddCeiling(scene1, vector3(0, 0, +3.5), magenta * 0.7);
	AddFloor(scene1, vector3(0, 0, -0.5), cyan * 0.7);

	//AddBox(scene1, vector3(1, -0.5, -0.3), 0.2, rgbf(1, 0, 1), true);

	box* box1 = new box(vector3(1, -0.5, 0), vector3(-0.2, -0.2, -0.2), vector3(0.2, 0.2, 0.2));
	box1->natrual_colour = rgbf(0, 0, 0);
	box1->reflective = false;
	box1->transparent = true;
	box1->transparency = 1;
	box1->I_refr = 1;
	box1->refindex = 2;
	scene1.add_object(box1);

	//AddLightBall(scene1, vector3(-0.8, 0, 3), 3, 0.1);

	AddLight(scene1, vector3(-1.5, 1.5, 3));
	//AddLight(scene1, vector3(2, 0, 4));
	//AddLight(scene1, vector3(-5, 3, 2));

	//IcoSphere(scene1, vector3(4, 0, 2));

	torus_object* tor1 = new torus_object(0.1,0.5,vector3(1,0,-0.5));
	tor1->natrual_colour = rgbf(1, 0, 0);	
	//tor1->ambient_colour = rgbf(0, 0, 0.5);
	//scene1.add_object(tor1);

	mesh* m1 = ReadMesh("teapot.obj", vector3(1, -0.25, -0.5));
	m1->natrual_colour = rgbf(0, 0, 0);
	m1->reflective = false;
	m1->transparent = true;
	m1->transparency = 1;
	m1->I_refr = 1;

	//scene1.add_object(m1);
	
	
}
Ejemplo n.º 7
0
BemGame::BemGame( SDL_Surface* screen, bool useWindows )
{
	random.SetSeed( 0 );

	KrRGBA green;
	green.Set( 0, 200, 0 );
	
	if ( useWindows )
	{
		KrRect rects[5];
		
		const int lW = 280;
		const int lH = 180;
		const int r = 200;
		const int pad = 10;
		
		rects[0].Set( 0,   0, screen->w - 1 - pad - r, r + pad - 1 );
		rects[1].Set( 0, r + pad, screen->w-1, screen->h - 1 - pad - lH );
		rects[2].Set( lW + pad, screen->h - pad - lH, screen->w-1, screen->h - 1 );

		rects[3].Set( 0, screen->h - lH, lW-1, screen->h - 1 );
		rects[4].Set( screen->w - r, 0, screen->w-1, r-1 );

		engine = new KrEngine( screen, 5, rects, &green );
	}
	else
	{
		engine = new KrEngine( screen );
	}
	GLASSERT( engine );

	// The vault contains all the resources used by this
	// demo.
	if (!engine->Vault()->LoadDatFile( "bem.dat" ) )
	{
		GLOUTPUT(( "Error loading dat file: 'bem.dat'!\n" ));
		exit( 100 );
	}

	KrRGBA black;
	black.Set( 0, 0, 0 );
	if ( useWindows )
	{
		engine->FillBackgroundWindow( 0, 0 );			// main
		engine->FillBackgroundWindow( 1, 0 );			// main
		engine->FillBackgroundWindow( 2, 0 );			// main
		engine->FillBackgroundWindow( 3, &black );		// zoomed out
		engine->FillBackgroundWindow( 4, &black );		// moving zoom
	}
	else
	{
		// We have a space image so the engine should not draw
		// the background. Performance enhancement.
		engine->FillBackground( 0 );
	}

	// Set up some depth categories:
	backgroundTree = new KrImNode;
	underTree	   = new KrImNode;
	floorTree      = new KrImNode;
	standingTree   = new KrImNode;
	overTree       = new KrImNode;

	// Depth sort by order of addition. All the z-depths are
	// left at 0. In other words, when added at the same Z-depth (0
	// in this case) the object added most recently is on top.
	engine->Tree()->AddNode( 0, backgroundTree );
	engine->Tree()->AddNode( 0, underTree );
	engine->Tree()->AddNode( 0, floorTree );
	engine->Tree()->AddNode( 0, standingTree );
	engine->Tree()->AddNode( 0, overTree );

	// Store the floor size. Due to the way the sprites are defined,
	// the size in terms of positioning the tiles is slightly different
	// than the size in terms of the tile bitmap.
	KrSpriteResource* resource = engine->Vault()->GetSpriteResource( BEM_ROOM | BEM_FLOOR );
	GLASSERT( resource );
	tileWidth  = resource->GetActionByIndex( 0 )->Frame( 0 ).Width() +2;
	tileHeight = resource->GetActionByIndex( 0 )->Frame( 0 ).Height();

	isoMath = new GlIsoMath( tileWidth, tileHeight );
	isoMath->SetScreenCenterToTile( screen->w,
									screen->h,
									MAPX / 2, MAPY / 2, 0 );

	AddSpaceTiles();
	AddFloor();
	AddRoomObjects();
	AddActors( useWindows );

	// Add the mini-map
	KrCanvasResource* canvasResource =
					new KrCanvasResource(	"minimap",
											140, 140,
											true  );
	GLASSERT( canvasResource );


	// An example of a user-defined resource getting added to a vault.
	engine->Vault()->AddResource( canvasResource );

	canvas = new KrCanvas( canvasResource );
	canvas->SetPos( screen->w - canvasResource->Width(),
					screen->h - canvasResource->Height() );
	engine->Tree()->AddNode( overTree, canvas );

	subtick = 0;
	tick = 0;
	teleFrame = 0;
	teleSprite = 0;
	DrawMiniMap();

	if ( useWindows )
	{
		// Set the 3 "band" windows to be positioned
		// to the first.
 		engine->Tree()->Root()->SetPos( 0, 0, 0 );
		engine->Tree()->Root()->SetPos( -engine->ScreenBounds(1).min.x, -engine->ScreenBounds(1).min.y, 1 );
 		engine->Tree()->Root()->SetPos( -engine->ScreenBounds(2).min.x, -engine->ScreenBounds(2).min.y, 2 );

		SetupLeftWindow();
		SetupRightWindow();
	}
}
Ejemplo n.º 8
0
BOOL CALLBACK FloorInfoProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
	case WM_INITDIALOG:
		{
	        CListView floor_list(hwnd, IDC_L_FLOOR_INFO);
			floor_list.SetSelectAndGrid(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
			floor_list.InsertColumn(1,100,"楼层编号");
			floor_list.InsertColumn(2,100,"楼层名称");
			try {
			    ShowFloorList(hwnd);
			} catch (Err &err) {
				MessageBox(hwnd, err.what(), TEXT("基础信息管理"), MB_ICONERROR);
				return FALSE;
			}
			return TRUE;
		}
	case  WM_NOTIFY:
		{
			switch(LOWORD(wParam))
			{
			case IDC_L_FLOOR_INFO:
				{
					if (((LPNMHDR)lParam)->code == NM_CLICK)/*点击列表中的一项*/
					{
						int index=0;
						CEdit e_name,e_id;
						CListView floor_list;
						floor_list.Initialization(hwnd, IDC_L_FLOOR_INFO);
						e_id.Initialization(hwnd, IDC_E_FLOOR_ID);
						e_name.Initialization(hwnd, IDC_E_FLOOR_NAME);
						index = floor_list.GetSelectionMark();
						e_id.SetEditText(floor_list.GetItem(index,0));
						e_name.SetEditText(floor_list.GetItem(index,1));
					}
					break;
				}
			}
			return TRUE;
		}
	case WM_COMMAND:
		{
			switch (LOWORD(wParam))
			{
			case IDC_B_FLOOR_ADD:
				{
					try {
						AddFloor(hwnd);
						ShowFloorList(hwnd);
					} catch (Err &err) {
						MessageBox(hwnd, err.what(), TEXT("基础信息管理"), MB_ICONERROR);
						return FALSE;
					}
					break;
				}
			case IDC_B_FLOOR_MODIFY:
				{
					try {
						UpdateFloor(hwnd);
						ShowFloorList(hwnd);
					} catch (Err &err) {
						MessageBox(hwnd, err.what(), TEXT("基础信息管理"), MB_ICONERROR);
						return FALSE;
					}
					break;
				}
			case IDC_B_FLOOR_DELETE:
				{
					try {
						DeleteFloor(hwnd);
						ShowFloorList(hwnd);
					} catch (Err &err) {
						MessageBox(hwnd, err.what(), TEXT("基础信息管理"), MB_ICONERROR);
						return FALSE;
					}
					break;
				}
			case IDC_B_FLOOR_CANCEL:
				{
					EndDialog(hwnd,0);
					break;
				}
			}
			return TRUE;
		}
	case WM_CLOSE:
		{
			EndDialog(hwnd,0);
			return TRUE;
		}
	}
	return FALSE;
}