Guest User

Untitled

a guest
May 22nd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. using Microsoft.Xna.Framework;
  7. using Microsoft.Xna.Framework.Audio;
  8. using Microsoft.Xna.Framework.Content;
  9. using Microsoft.Xna.Framework.GamerServices;
  10. using Microsoft.Xna.Framework.Graphics;
  11. using Microsoft.Xna.Framework.Input;
  12. using Microsoft.Xna.Framework.Media;
  13.  
  14. namespace TowerDefence
  15. {
  16.     public class Tile
  17.     {
  18.         static int tileWidth = 64;
  19.         static int tileHeight = 64;
  20.  
  21.  
  22.         public Texture2D tileRect;
  23.         public Rectangle Rect;
  24.  
  25.  
  26.         KeyboardState keyState = Keyboard.GetState();
  27.  
  28.         List<Texture2D> tileTextures_;
  29.         int[,] map;
  30.  
  31.         public Tile(ContentManager content_)
  32.         {
  33.             tileTextures_ = new List<Texture2D>();
  34.             tileRect = content_.Load<Texture2D>("rect_tile");
  35.         }
  36.        
  37.         public void LoadContent(ContentManager content_)
  38.         {
  39.             tileTextures_.Add(content_.Load<Texture2D>("Tiles/wall"));
  40.             tileTextures_.Add(content_.Load<Texture2D>("Tiles/rockroad"));
  41.             tileTextures_.Add(content_.Load<Texture2D>("Tiles/grassrockroad"));
  42.         }
  43.  
  44.         public void Map(int[,] tileMap)
  45.         {
  46.             map = tileMap;
  47.         }
  48.  
  49.         public void Draw(SpriteBatch batch)
  50.         {
  51.             int tileMapWidth = map.GetLength(1);
  52.             int tileMapHeight = map.GetLength(0);
  53.  
  54.             for (int x = 0; x < tileMapWidth; x++)
  55.             {
  56.                 for (int y = 0; y < tileMapHeight; y++)
  57.                 {
  58.                     int textureIndex = map[y, x];
  59.                     Texture2D texture = tileTextures_[textureIndex];
  60.  
  61.                     Rect = new Rectangle(x * tileWidth, y * tileHeight, tileWidth, tileHeight);
  62.  
  63.                     batch.Draw(texture, new Rectangle(x * tileWidth, y * tileHeight, tileWidth, tileHeight), Color.White);
  64.                     batch.Draw(tileRect, new Rectangle(x * tileWidth, y * tileHeight, tileWidth, tileHeight), Color.White);
  65.  
  66.                    
  67.                 }
  68.             }
  69.            
  70.         }
  71.  
  72.  
  73.     }
  74. }
Add Comment
Please, Sign In to add comment