krzat

Tile and TileType

Feb 4th, 2013
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.59 KB | None | 0 0
  1. struct Tile
  2. {
  3.     short typeId;
  4.     public TileType Type
  5.     {
  6.         get
  7.         {
  8.             return TileType.Get(typeId);
  9.         }
  10.         set
  11.         {
  12.             typeId = value.Id;
  13.         }
  14.     }
  15. }
  16.  
  17. class TileType
  18. {  
  19.     //you may want to encapsulate these
  20.     public int Id;
  21.     public string Name;
  22.     public Texture2D Texture;
  23.     public Rectangle TextureSource;
  24.     public bool IsObstacle;
  25.    
  26.  
  27.     static List<TileType> types;
  28.     static TileType()
  29.     {
  30.         types = new List<TileType>();
  31.         var type = new TileType();
  32.         type.Name = "Dirt";
  33.         //initialize here
  34.        
  35.         types.Add(type);
  36.     }
  37.    
  38.     public static TileType Get(int id)
  39.     {
  40.         return types[id];
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment