Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello, I'm trying to draw a terrain using the points given by this function:


C#
public static Level GenerateDummyLevel(int width, int height)
        {
            Level level = new Level();

            bool up = false;

            for (int i = 0; i <= width; i += 20)
            {

                level.Terrain.Add(new Vector2(i, height / 2 + (up ? -10 : 10)));

                up = !up;
            }

            return level;
        }


and this function draws the terrain:

C#
public void Draw(GraphicsDeviceManager graphics, SpriteBatch spriteBatch, PrimitiveBatch primitiveBatch)
{
    // Draw sprites
    this.Lander.Draw(graphics, spriteBatch, primitiveBatch);

    // Draw terrain
    primitiveBatch.Begin(PrimitiveType.TriangleList);

    if (this.Terrain.Count > 1)
    {
        for (int i = 0; i < (this.Terrain.Count - 1); i++)
        {
            primitiveBatch.AddVertex(new Vector2(this.Terrain[i].X, this.Terrain[i].Y), Color.Black);
            primitiveBatch.AddVertex(new Vector2(this.Terrain[i + 1].X, graphics.PreferredBackBufferHeight), Color.Black);
            primitiveBatch.AddVertex(new Vector2(this.Terrain[i].X, graphics.PreferredBackBufferHeight), Color.Black);


            primitiveBatch.AddVertex(new Vector2(this.Terrain[i].X, this.Terrain[i].Y), Color.Black);
            primitiveBatch.AddVertex(new Vector2(this.Terrain[i + 1].X, this.Terrain[i + 1].Y), Color.Black);
            primitiveBatch.AddVertex(new Vector2(this.Terrain[i + 1].X, graphics.PreferredBackBufferHeight), Color.Black);

        }
    }

    primitiveBatch.End();

}


The terrain drawn by this function begins from the bottom of screen and ends in the middle how can i start the terrain from the top of the screen instead of the bottom? Is there any way to simply mirror the terrain along x-axis?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900