X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=CarFire%2FCarFire%2FCarFire%2FMap.cs;h=ae49c8a8c3bc2f635329f3e57615de4069020cd5;hb=d861be5538dfe866f867a6e237311ba6b743e863;hp=0e66b139221bf27d1206517e32461d3993fa879c;hpb=3ca5852a7df47d4129743ed449816c7c7347b699;p=chaz%2Fcarfire
diff --git a/CarFire/CarFire/CarFire/Map.cs b/CarFire/CarFire/CarFire/Map.cs
index 0e66b13..ae49c8a 100644
--- a/CarFire/CarFire/CarFire/Map.cs
+++ b/CarFire/CarFire/CarFire/Map.cs
@@ -19,10 +19,6 @@ namespace CarFire
///
public class Map
{
- // DEBUG: Tilesets not implemented at all.
- public static Texture2D DefaultTile;
-
-
#region Public Constants
public const float PixelsToUnitSquares = 64.0f;
@@ -101,7 +97,9 @@ namespace CarFire
///
public int Height { get { return mData.Metadata.GridHeight; } }
- // TODO: This should return whatever object we end up using for tilesets.
+ ///
+ /// Get the name of the tileset.
+ ///
public string Tileset { get { return mData.Metadata.Tileset; } }
///
@@ -133,6 +131,17 @@ namespace CarFire
set { mView.CenterCell = value; }
}
+ ///
+ /// Get and set the tilemap with its associated texture and tile
+ /// character to coordinate mappings. This effects what the map looks
+ /// like when it is drawn.
+ ///
+ public Tilemap Tilemap
+ {
+ get { return mData.Tilemap; }
+ set { mData.Tilemap = value; }
+ }
+
///
/// Get and set the zoom of the map view. The default zoom is
/// Map.PixelsToUnitSquares.
@@ -226,6 +235,16 @@ namespace CarFire
return mData.IsCellOpen(x, y);
}
+ ///
+ /// created by Brady for AI precalculations
+ ///
+ /// X-coordinate.
+ /// Y-coordinate.
+ public bool IsWall(int x, int y)
+ {
+ return mData.IsWall(x, y);
+ }
+
///
/// Determine whether or not a cell can be occupied by a game entity.
///
@@ -336,6 +355,7 @@ namespace CarFire
public List Entities { get { return mEntities; } }
public Point[] PlayerPositions { get { return mPlayerPositions; } }
public bool[,] Grid { get { return mBooleanGrid; } }
+ public Tilemap Tilemap;
public Model(Metadata metadata, char[,] grid, char defaultTile,
@@ -380,9 +400,15 @@ namespace CarFire
public bool IsCellOpen(int x, int y)
{
- // TODO: Still need to define characters for types of scenery.
- if (IsOnMap(x, y)) return mGrid[x, y] == ' ';
- return false;
+ if (!IsOnMap(x, y)) return false;
+ return (Tilemap.GetTileFlags(mGrid[x, y]) & TileFlags.Open) == TileFlags.Open;
+ }
+
+ //created by Brady for AI precalculations
+ public bool IsWall(int x, int y)
+ {
+ if (!IsOnMap(x, y)) return false;
+ return (Tilemap.GetTileFlags(mGrid[x, y]) & TileFlags.Wall) == TileFlags.Wall;
}
public void SetCell(int x, int y, char tile)
@@ -394,6 +420,12 @@ namespace CarFire
}
}
+ public char GetCell(int x, int y)
+ {
+ if (IsOnMap(x, y)) return mGrid[x, y];
+ return mDefaultTile;
+ }
+
public void ClearCell(int x, int y)
{
SetCell(x, y, mDefaultTile);
@@ -510,21 +542,14 @@ namespace CarFire
public void Draw(SpriteBatch spriteBatch)
{
+ if (mData.Tilemap == null) throw new Exception("Cannot draw map without first setting the tilemap.");
mViewport = spriteBatch.GraphicsDevice.Viewport;
- // TODO: There is no culling yet, but it runs so fast that it probably won't ever need it.
for (int y = 0; y < mData.Metadata.GridHeight; y++)
{
for (int x = 0; x < mData.Metadata.GridWidth; x++)
{
- if (mData.IsCellOpen(x, y))
- {
- spriteBatch.Draw(Map.DefaultTile, GetRectangleFromCoordinates(x, y), Color.White);
- }
- else
- {
- spriteBatch.Draw(Map.DefaultTile, GetRectangleFromCoordinates(x, y), Color.DarkBlue);
- }
+ mData.Tilemap.Draw(spriteBatch, mData.GetCell(x, y), GetRectangleFromCoordinates(x, y));
}
}
}