Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Audio;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.GamerServices;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Microsoft.Xna.Framework.Media;
- namespace TowerDefence
- {
- public class Tile
- {
- static int tileWidth = 64;
- static int tileHeight = 64;
- public Texture2D tileRect;
- public Rectangle Rect;
- KeyboardState keyState = Keyboard.GetState();
- List<Texture2D> tileTextures_;
- int[,] map;
- public Tile(ContentManager content_)
- {
- tileTextures_ = new List<Texture2D>();
- tileRect = content_.Load<Texture2D>("rect_tile");
- }
- public void LoadContent(ContentManager content_)
- {
- tileTextures_.Add(content_.Load<Texture2D>("Tiles/wall"));
- tileTextures_.Add(content_.Load<Texture2D>("Tiles/rockroad"));
- tileTextures_.Add(content_.Load<Texture2D>("Tiles/grassrockroad"));
- }
- public void Map(int[,] tileMap)
- {
- map = tileMap;
- }
- public void Draw(SpriteBatch batch)
- {
- int tileMapWidth = map.GetLength(1);
- int tileMapHeight = map.GetLength(0);
- for (int x = 0; x < tileMapWidth; x++)
- {
- for (int y = 0; y < tileMapHeight; y++)
- {
- int textureIndex = map[y, x];
- Texture2D texture = tileTextures_[textureIndex];
- Rect = new Rectangle(x * tileWidth, y * tileHeight, tileWidth, tileHeight);
- batch.Draw(texture, new Rectangle(x * tileWidth, y * tileHeight, tileWidth, tileHeight), Color.White);
- batch.Draw(tileRect, new Rectangle(x * tileWidth, y * tileHeight, tileWidth, tileHeight), Color.White);
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment