X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=CarFire%2FCarFire%2FCarFire%2FMap.cs;h=1b8b5a89bc992a9279f324102379674ce0a5ef73;hb=8f212205c32b283d9a7730e15044d706db2f08bf;hp=0e66b139221bf27d1206517e32461d3993fa879c;hpb=3ca5852a7df47d4129743ed449816c7c7347b699;p=chaz%2Fcarfire
diff --git a/CarFire/CarFire/CarFire/Map.cs b/CarFire/CarFire/CarFire/Map.cs
index 0e66b13..1b8b5a8 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 mView.Tilemap; }
+ set { mView.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.
///
@@ -385,6 +404,12 @@ namespace CarFire
return false;
}
+ //created by Brady for AI precalculations
+ public bool IsWall(int x, int y)
+ {
+ if (IsOnMap(x, y)) return (mGrid[x, y] == '-' || mGrid[x, y] == '|' || mGrid[x, y] == '+' || mGrid[x, y] == '/' || mGrid[x, y] == '\\');
+ return false;
+ }
public void SetCell(int x, int y, char tile)
{
if (IsOnMap(x, y))
@@ -394,6 +419,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);
@@ -489,6 +520,7 @@ namespace CarFire
class View
{
public Vector2 CenterCell;
+ public Tilemap Tilemap;
public float Zoom;
@@ -510,21 +542,14 @@ namespace CarFire
public void Draw(SpriteBatch spriteBatch)
{
+ if (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);
- }
+ Tilemap.Draw(spriteBatch, mData.GetCell(x, y), GetRectangleFromCoordinates(x, y));
}
}
}