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; }
public void doSlope(int baseHeight, int x, int y, HeightMap hmap) { s0 = getSlope(1, 0, baseHeight, x, y, hmap); s45 = getSlope(1, 1, baseHeight, x, y, hmap); s90 = getSlope(0, 1, baseHeight, x, y, hmap); s135 = getSlope(-1, 1, baseHeight, x, y, hmap); s180 = getSlope(-1, 0, baseHeight, x, y, hmap); s225 = getSlope(-1, -1, baseHeight, x, y, hmap); s270 = getSlope(0, -1, baseHeight, x, y, hmap); s315 = getSlope(1, -1, baseHeight, x, y, hmap); _xForce = 0; _yForce = 0; _xForce -= (s0 + s180 * -1); _yForce -= (s90 + s270 * -1); float angleSlope1 = s135 + s315 * -1; float angleSlope2 = s45 + s225 * -1; _xForce -= (angleSlope1 / 2 + angleSlope2 / 2); _yForce -= (angleSlope1 / 2 + angleSlope2 / 2); }
/// <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,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8,8,7,6,6,5,5,5,5,5,4,4,4,4,4,4,3,3,3,3,3,3,3,3}, {8,8,8,7,7,7,8,8,8,8,7,6,5,4,4,4,4,4,4,4,3,3,2,2,2,2,3,4,5,5,6,6,6,7,7,8,8,8,8,7,6,6,6,6,5,5,4,4,4,4,4,4,3,3,3,3,3,3,3,3}, {8,8,7,7,7,7,8,8,8,8,7,6,5,4,4,4,4,4,4,4,4,3,2,2,2,2,2,3,4,5,6,6,6,7,8,8,8,8,8,8,7,7,7,6,5,5,5,4,4,4,4,4,4,3,3,3,3,3,3,4}, {7,7,7,7,7,8,8,8,8,7,6,5,5,4,4,4,4,4,4,4,4,3,2,2,2,2,2,3,4,4,5,6,7,8,8,8,8,8,8,8,8,8,8,7,6,5,5,5,4,4,4,4,4,3,3,4,4,4,4,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(); }