static void initMap() { //Get data for maps CGraphicTileset generator = new CGraphicTileset(); mapObject = new maps(); mapObject.DTileIndices = generator.OrganizeTiles(tileObject.lines); Tuple <int[][], int[][], string[], int[][], string[][], int[][], string[][]> tempMapData = generator.LoadMap("map", tileObject.lines, mapObject.DTileIndices); mapObject.mapData = tempMapData.Item1; mapObject.mapDataIndices = tempMapData.Item2; mapObject.mapNames = tempMapData.Item3; int[][] tempMapXY = tempMapData.Item4; mapObject.mapX = tempMapXY[0]; mapObject.mapY = tempMapXY[1]; mapObject.allMapStrings = tempMapData.Item5; mapObject.mapPartials = tempMapData.Item6; mapObject.mapLines = tempMapData.Item7; int numMaps = mapObject.mapNames.Length; mapObject.entireMaps = new Bitmap[numMaps]; mapObject.entireMapsIndex = new EntireMapsIndex[numMaps]; for (int i = 0; i < numMaps; i++) { //mapObject.entireMaps[i] = new Bitmap(mapObject.mapX[i], mapObject.mapY[i]); //AZ: Optimized this step, no longer need to generate big bitmaps.. mapObject.entireMaps[i] = generator.generateMiniMap(i, SplashScreen.tileObject, mapObject); //Just need a 2D int array: mapObject.entireMapsIndex[i] = generator.generateMapIndex(i, SplashScreen.tileObject, mapObject); } }
public Bitmap generateMiniMap(int mapIndex, loader tileObj, maps mapObj) { int x = mapObj.mapX[mapIndex]; int y = mapObj.mapY[mapIndex]; int tileW = tileObj.tileWidth; int tileH = tileObj.tileHeight; Bitmap mapImage = new Bitmap(x, y); //Image tempImg = mapImage; // using (Graphics g = Graphics.FromImage(mapImage)) { for (int i = 0; i < x * y; i++) //y-1 to skip last row { int currPos = i; int currRow = 0; int typeIndex = mapObj.mapData[mapIndex][i]; int tileIndex = mapObj.mapDataIndices[mapIndex][i]; //True img is the index of tiles directly from the file.dat (but stored inside an array) int trueImgIndex = mapObj.DTileIndices[typeIndex][tileIndex]; while (currPos >= x) //x-1 to skip last column { currPos -= x; currRow += 1; } mapImage.SetPixel(currPos, currRow, tileObj.tiles[trueImgIndex].GetPixel(15, 15)); } } //mapImage = mapImage.Clone(new Rectangle(0,0,x-1,y-1),mapImage.PixelFormat); return(mapImage); }
public EntireMapsIndex generateMapIndex(int mapIndex, loader tileObj, maps mapObj) { int x = mapObj.mapX[mapIndex]; int y = mapObj.mapY[mapIndex]; int tileW = tileObj.tileWidth; int tileH = tileObj.tileHeight; EntireMapsIndex ans = new EntireMapsIndex(); ans.data = new int[y][]; for (int i = 0; i < y; i++) { ans.data[i] = new int[x]; } //Bitmap mapImage = new Bitmap(x * tileW, y * tileH); //Image tempImg = mapImage; for (int i = 0; i < x * y; i++) //y-1 to skip last row { int currPos = i; int currRow = 0; int typeIndex = mapObj.mapData[mapIndex][i]; int tileIndex = mapObj.mapDataIndices[mapIndex][i]; //True img is the index of tiles directly from the file.dat (but stored inside an array) int trueImgIndex = mapObj.DTileIndices[typeIndex][tileIndex]; while (currPos >= x) //x-1 to skip last column { currPos -= x; currRow += 1; } ans.data[currRow][currPos] = trueImgIndex; /*g.DrawImage(tileObj.tiles[trueImgIndex], new Rectangle(currPos * tileW, currRow * tileH, tileW, tileH), // destination rectangle * 0, // source rectangle x * 0, // source rectangle y * tileW, // source rectangle width * tileH, // source rectangle height * GraphicsUnit.Pixel);*/ } return(ans); }
public Bitmap generateMap(int mapIndex, loader tileObj, maps mapObj) { int x = mapObj.mapX[mapIndex]; int y = mapObj.mapY[mapIndex]; int tileW = tileObj.tileWidth; int tileH = tileObj.tileHeight; Bitmap mapImage = new Bitmap(x * tileW, y * tileH); Image tempImg = mapImage; using (Graphics g = Graphics.FromImage(mapImage)) { for (int i = 0; i < x * y; i++) //y-1 to skip last row { int currPos = i; int currRow = 0; int typeIndex = mapObj.mapData[mapIndex][i]; int tileIndex = mapObj.mapDataIndices[mapIndex][i]; //True img is the index of tiles directly from the file.dat (but stored inside an array) int trueImgIndex = mapObj.DTileIndices[typeIndex][tileIndex]; while (currPos >= x) //x-1 to skip last column { currPos -= x; currRow += 1; } g.DrawImage(tileObj.tiles[trueImgIndex], new Rectangle(currPos * tileW, currRow * tileH, tileW, tileH), // destination rectangle 0, // source rectangle x 0, // source rectangle y tileW, // source rectangle width tileH, // source rectangle height GraphicsUnit.Pixel); } g.Save(); } return(mapImage); }