Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class LevelLoader
- {
- Texture2D tileSheet; //The sprite sheet that holds all the tiles used to make the levels
- //Rectangles for all different tiles so it makes it easier to switch them
- Rectangle skyTile; //Tile for the sky
- Rectangle grassTile; //Tile for the grass
- Rectangle stoneTile; //Tile for the stone
- Camera camera = new Camera();
- Player player;
- int cameraX;
- int[] currentLevel; //This array will be used as an array to hold the current level that is played
- //The level array of level one
- int[] level1 = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};
- public LevelLoader()
- {
- //The skyTile that will be used to draw the sky
- skyTile.X = 0; //The x cordinate to draw the tile from
- skyTile.Y = 0; //The y cordinate to draw the tile from
- skyTile.Width = 32; //Width of the tile
- skyTile.Height = 32; //Height of the tile
- //The grassTile that will be used to draw the grass
- grassTile.X = 0; //The x cordinate to draw the tile from
- grassTile.Y = 32; //The y cordinate to draw the tile from
- grassTile.Width = 32; //Width of the tile
- grassTile.Height = 32; //Height of the tile
- //The stoneTile that will be used to draw stones
- stoneTile.X = 0; //The x cordinate to draw the tile from
- stoneTile.Y = 64; //The y cordinate to draw the tile from
- stoneTile.Width = 32; //Width of the tile
- stoneTile.Height = 32; //Height of the tile
- }
- public void LoadContent(ContentManager Content, string filename)
- {
- //Loading the tile sheet that will be used for all the level sprites
- tileSheet = Content.Load<Texture2D>(filename);
- }
- public void setLevel(int level)
- {
- //See what level that should be set
- switch (level)
- {
- case 1:
- currentLevel = level1;
- break;
- }
- }
- public void Draw(SpriteBatch spriteBatch)
- {
- //Its here i need the value from Player class!
- int currentX = cameraX; //The current x cordiate to draw the tile too
- int currentY = 0; //The current y cordiate to draw the tile too
- for (int i = 0; i < currentLevel.Length; i++)
- {
- /*
- * A switch statement to see if the current level1[i] is either a grass, sky or stone tile
- */
- switch(currentLevel[i])
- {
- case 1:
- //Draw a sky tile
- spriteBatch.Draw(tileSheet, new Rectangle(currentX, currentY, 32, 32), skyTile, Color.White);
- break;
- case 2:
- //Draw a grass tile
- spriteBatch.Draw(tileSheet, new Rectangle(currentX, currentY, 32, 32), grassTile, Color.White);
- break;
- case 3:
- //Draw a stone tile
- spriteBatch.Draw(tileSheet, new Rectangle(currentX, currentY, 32, 32), stoneTile, Color.White);
- break;
- }
- //Add 32 to the current cordinate so we don't draw to the same spot all the time
- currentX = currentX + 32;
- if (currentX >= 800) //If we hit the width of the map we want:
- {
- //Start drawing from X cordinate zero
- cameraX = camera.getCameraX();
- currentX = cameraX;
- //And Y cordinate + 32
- currentY = currentY + 32;
- //This will make so we draw one line and when we hit a full line on the map then we draw next line and soo on.
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment