private float getSlope(int h, int v, int baseHeight, int x, int y, HeightMap hmap) { float sum = 0; int h1 = baseHeight; int h2; for (int i = 0; i < range; i++) { h2 = hmap.getHeight(x + h * i, y + v * i); sum += h2 - h1; h1 = h2; } return sum / range; }
/// <summary> /// Allows the game component to perform any initialization it needs to before starting /// to run. This is where it can query for any required services and load content. /// </summary> public override void Initialize() { // TODO: Add your initialization code here spriteBatch = new SpriteBatch(Game1.graphics.GraphicsDevice); hmap = new HeightMap(Game1.MAP_SIZE, 0); // Init the map in a dumb way for now. grid = new int[width, height]; /* int[,] elevationMap = new int[width, height]; // ***** This hard-coded elevation map is 21x11 ****** elevationMap = new int[,] { {4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,6,6,7,8,8,8,8,8,8,8,8,8,8,8,8,7,6,5,4,3,3,3,3,3,3,4,4,5,5,5,5,6,6,7,7,7,7,7,7,7,7,7,7,7}, {4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,6,6,7,7,8,8,8,8,8,8,8,8,8,8,8,7,6,5,4,3,3,3,3,3,4,4,4,5,5,5,5,5,6,6,7,7,7,7,7,7,7,7,7,7}, {3,3,4,4,4,4,4,4,4,5,5,5,5,5,5,6,6,7,7,8,8,8,8,8,8,8,8,8,8,8,8,7,6,5,4,4,3,3,3,3,3,3,4,4,4,5,5,5,5,6,6,6,7,7,7,7,7,7,7,6}, {3,3,3,4,4,4,4,4,4,5,5,5,5,5,6,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,7,6,5,5,4,3,3,3,3,3,4,4,4,4,5,5,5,5,5,5,6,6,6,7,7,7,7,6,6}, {3,3,3,4,4,4,4,4,4,5,5,5,5,5,6,7,8,8,8,8,8,8,8,8,8,8,8,7,8,7,7,7,6,6,5,4,3,3,3,3,3,3,3,4,4,4,5,5,5,5,5,5,6,6,6,7,7,7,7,6}, {3,3,3,3,4,4,4,4,4,5,5,5,5,5,6,7,8,8,8,8,8,8,8,8,8,7,7,7,7,7,7,7,7,6,5,4,4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,4}, {7,7,7,7,7,7,7,7,7,6,5,5,4,4,4,4,4,4,4,4,4,3,2,2,2,2,2,2,3,4,5,6,7,8,8,8,8,8,8,8,8,8,8,7,6,5,5,4,5,4,4,4,4,3,3,4,4,4,4,4}, {7,7,7,7,7,7,7,7,6,5,5,4,4,4,4,4,4,4,4,4,3,3,2,2,2,2,2,2,3,4,5,6,7,8,8,8,8,8,8,8,8,8,8,8,7,6,6,5,5,4,4,4,4,4,3,3,4,4,4,4}, {7,7,7,7,7,7,7,7,7,6,5,5,4,4,4,4,4,4,4,4,3,2,2,2,2,2,2,2,3,4,5,6,7,8,8,8,8,8,8,8,8,8,8,8,8,7,6,5,5,4,4,4,4,3,3,4,4,4,4,4}, {7,7,7,7,7,7,7,7,7,7,6,5,5,4,4,4,4,4,4,3,3,2,2,2,2,2,2,2,3,4,5,6,7,8,8,8,8,8,8,8,8,8,8,8,8,7,6,6,5,4,4,4,4,3,3,4,4,4,4,4} }; */ for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { //grid[i, j] = new Tile(game, i, j, hmap.getHeight(i, j)); grid[i, j] = hmap.getHeight(i, j); } } Console.WriteLine("map initialization complete."); base.Initialize(); }