Exemple #1
0
	static int[,] CreateRightSide(int[,] newMap, MapInfo mapInfo)
	{
		PseudoRandom rightPRnd = mapInfo.GetSeededPsuedoRnd ();
		int[] rightDirection = new int[2]{-1,0}; 		

		int numOfEntries = 0; 
		for (int i = 0; i < mapInfo.maxNumOfEntries; i++) 
		{
			int startPoint = rightPRnd.Next(1, newMap.GetLength(0)-1-mapInfo.maxEntrySize); 
			int entrySize  = rightPRnd.Next(2, mapInfo.maxEntrySize+1);

			int[] startCoord = new int[2]{newMap.GetLength(1)-1, startPoint}; 
			int[] connect = PathGenerator.FindEndPoint (startCoord, entrySize, rightDirection, newMap);

			//Debug.Log ("Connection: " + i + " (" + connect[0] + "," + connect[1] + ")"); 
			newMap = PathGenerator.CreateHorizontalPath(connect, startCoord, entrySize, newMap);
			/*for (int y = startPoint; y <= (startPoint + entrySize); y++) 
			{
				for (int x = newMap.GetLength (1) - 1; x >= connect [0]; x--) {
					newMap [y, x] = 0; 
				}
			}*/
		}

		return newMap; 
	}
	public static int[,] CreateVerticalPath(int[] startPoint, int[] endPoint, int openLength, int[,] map, MapInfo mapInfo)
	{
		PseudoRandom pRnd = mapInfo.GetSeededPsuedoRnd ();
		int initalLength = openLength;
		bool justChanged = true; 

		for (int y = startPoint[1]; y <= endPoint[1]; y++) 
		{
			if (y == startPoint [1] || y == endPoint[1]) 
			{
				initalLength = openLength; 
			}

			for (int x = 0; x < initalLength; x++) {
				map [y, startPoint [0] + x] = 0; 
			}

			if (!justChanged) {
				justChanged = true;
				double num = pRnd.Next ();
				if (num < (mapInfo.windiness / 2) && initalLength <= mapInfo.maxEntrySize) {
					initalLength += 1; 
				} else if (num >= (mapInfo.windiness / 2) && num < mapInfo.windiness && initalLength > 2) {
					initalLength -= 1; 
				}
			} 
			else 
			{
				justChanged = false; 
			}
		}

		return map; 
	}
Exemple #3
0
	public static int[,] CreateCAMap(int mapSize, MapInfo mapInfo)
	{
		PseudoRandom rnd = mapInfo.GetSeededPsuedoRnd ();
		CellularAutomata ca = new CellularAutomata();
		int[,] start = ca.InitialiseMap (0.4f, mapSize, rnd);
		int[,] map = ca.CreateCellularAutomataFromMap (start, rnd);
		map = MapEdges.CreateSurrounding (map, mapInfo);
		return map; 
	}
Exemple #4
0
	public static int[,] CreateAgentBasedMap(int _mapSize, MapInfo mapInfo)
	{
		int mapSize = _mapSize;  
        
		PseudoRandom rnd = mapInfo.GetSeededPsuedoRnd (); 
        int[,] map = InitialiseMap(mapSize);

        int[] startPoint = ChooseRandomPoint( (int)Math.Round(mapSize/3f), (int)Math.Round(2f*mapSize/3f), rnd);
        AgentBased agent = new AgentBased(0.05, 0.05, startPoint, rnd.Next(0,4));

		while(agent.CanContinue(map, rnd) && (!CheckFilled(map, 0.5f)) )
        {
            map = agent.PlaceRoom(map, rnd);
            map = agent.MoveInDirection(map, rnd);
        }

        return map;
    }
Exemple #5
0
	static int[,] CreateTopSide(int[,] newMap, MapInfo mapInfo)
	{
		PseudoRandom topPRnd = mapInfo.GetSeededPsuedoRnd ();
		int[] topDirection = new int[2]{0,-1}; 		

		int numOfEntries = 0; 
		for (int i = 0; i < mapInfo.maxNumOfEntries; i++) 
		{
			int startPoint = topPRnd.Next(1, newMap.GetLength(1)-1-mapInfo.maxEntrySize); 
			int entrySize  = topPRnd.Next(2, mapInfo.maxEntrySize+1);

			int[] startCoord = new int[2]{startPoint, newMap.GetLength(0)-1}; 

			int[] connect = PathGenerator.FindEndPoint(startCoord, entrySize, topDirection, newMap);

			newMap = PathGenerator.CreateVerticalPath(connect, startCoord, entrySize, newMap, mapInfo);
		}

		return newMap; 
	}
Exemple #6
0
	static int[,] CreateDownSide(int[,] newMap, MapInfo mapInfo)
	{
		PseudoRandom downPRnd = mapInfo.GetSeededPsuedoRnd ();
		int[] downDirection = new int[2]{0,1}; 		

		int numOfEntries = 0; 
		for (int i = 0; i < mapInfo.maxNumOfEntries; i++) 
		{
			int startPoint = downPRnd.Next(1, newMap.GetLength(1)-1-mapInfo.maxEntrySize); 
			int entrySize  = downPRnd.Next(2, mapInfo.maxEntrySize+1);

			int[] startCoord = new int[2]{startPoint, 0}; 
			int[] connect = PathGenerator.FindEndPoint (startCoord, entrySize, downDirection, newMap);

			//Debug.Log ("Connection: " + i + " (" + connect[0] + "," + connect[1] + ")"); 
			newMap = PathGenerator.CreateVerticalPath(startCoord, connect, entrySize, newMap, mapInfo);
			/*for (int x = startPoint; x <= (startPoint + entrySize); x++) 
			{
				for (int y = 0; y <= connect[1]; y++) {
					newMap [y, x] = 0; 
				}
			}*/
		}

		return newMap; 
	}
	public static void CreateMineMeshFromMap(Layout layout, Grid grid, MapInfo mapInfo)
	{
		Texture2D tex = CreateMineTextureFromMap (layout, grid, mapInfo);
		string[,] nsewTileMap = NSEWMap.CreateNSEWMap(layout.layout);
		Rect rec = new Rect (0, 0, grid.width*16, grid.height*16);
		//Hardcoded Paths
		GameObject blankObj = Resources.Load ("Prefabs/BlankSprite") as GameObject;
		GameObject blockObj = Resources.Load ("Prefabs/BlankInter") as GameObject;

		Vector3 vec = new Vector3 ( ((float)(grid.width))/2, ((float)(grid.height))/2, 1);

		GameObject obj = (GameObject) Instantiate (blankObj, vec, Quaternion.identity);

		Sprite sprite = Sprite.Create(tex, rec, new Vector2(0.5f, 0.5f), 16);

		PseudoRandom prnd = mapInfo.GetSeededPsuedoRnd ();
		obj.GetComponent<SpriteRenderer> ().sprite = sprite;
		SceneObjects.AddObjectToScene (obj);


	}
	public static Texture2D CreateMineTextureFromMap(Layout layout, Grid grid, MapInfo mapInfo)
	{
		toggleLR = false;
		string[,] nsewTileMap = NSEWMap.CreateNSEWMap(layout.layout);
		//Hardcoded Paths
		if (dungeonSpriteList == null) {
			dungeonSpriteList = Resources.LoadAll<Sprite> ("MinesTilesTest");
		}
		PseudoRandom prnd = mapInfo.GetSeededPsuedoRnd();

		Texture2D tex = new Texture2D (grid.width*16, grid.height*16); 

		for (int y = 0; y < grid.height; y++) 
		{
			for (int x = 0; x < grid.width; x++) 
			{
				List<string> spriteNames = GetMineSpriteNameForTile (x, y, nsewTileMap, layout, grid, prnd);

				for (int f = 0; f < spriteNames.Count; f++) {
					string spriteName = spriteNames [f];
					Sprite spr = GetSprite (spriteName);
					Texture2D tileTex = new Texture2D ((int)spr.rect.width, (int)spr.rect.height);
					Color[] pixels = spr.texture.GetPixels ((int)spr.textureRect.x, 
						                 (int)spr.textureRect.y, 
						                 (int)spr.textureRect.width, 
						                 (int)spr.textureRect.height);

					if(spriteName.Contains("Shadow")){
						for (int a = 0; a < 16; a++) {
							for (int b = 0; b < 16; b++) {
								if (pixels [(a * 16) + b].a > .0) {
									Color shadow = pixels [(a * 16) + b]; 
									Color baseColor = tex.GetPixel((x * 16) + b, (y * 16) + a);
									baseColor.r -= 0.15f;
									baseColor.g -= 0.15f;
									baseColor.b -= 0.15f;
									tex.SetPixel ((x * 16) + b, (y * 16) + a, baseColor);
								}
							}
						}
					}
					else if (f != 0) {
						for (int a = 0; a < 16; a++) {
							for (int b = 0; b < 16; b++) {
								if (pixels [(a * 16) + b].a > .0) {
									tex.SetPixel ((x * 16) + b, (y * 16) + a, pixels [(a * 16) + b]);
								}
							}
						}
					} else {
						tex.SetPixels (x * 16, y * 16, 16, 16, pixels);
					}
				}
			}
		}

		tex.Apply (); 
		return tex;
	}