From 188525be158d8ba27fbbedf699eec5df59c5a2ee Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 26 Apr 2010 18:13:03 +0000 Subject: [PATCH] git-svn-id: https://bd85.net/svn/cs3505_group@152 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- CarFire/CarFire/CarFire/Game.cs | 6 ++++-- CarFire/CarFire/CarFire/Map.cs | 12 ++++-------- CarFire/CarFire/CarFire/PathFinder.cs | 3 +-- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/CarFire/CarFire/CarFire/Game.cs b/CarFire/CarFire/CarFire/Game.cs index a269367..7a1971c 100644 --- a/CarFire/CarFire/CarFire/Game.cs +++ b/CarFire/CarFire/CarFire/Game.cs @@ -333,6 +333,7 @@ namespace CarFire State.mDisplay = new Display(this); State.mDisplay.LoadContent(mContentManager); + // Load the tilemap. Texture2D mapTiles = mContentManager.Load("graphics/wallAndFloorTilesNoEdgeScale"); Tilemap tilemap = new Tilemap(mapTiles, 10, 7); tilemap.SetTile(' ', new Point(4, 5), TileFlags.Default); @@ -368,12 +369,13 @@ namespace CarFire tilemap.SetTile('>', new Point(7, 5), TileFlags.Default); tilemap.SetTile('/', new Point(8, 5), TileFlags.Default); tilemap.SetTile('?', new Point(9, 5), TileFlags.Default); + Map.Tilemap = tilemap; + // Load the first map. State.Map = mContentManager.Load("Maps/level1"); - State.Map.Tilemap = tilemap; State.Entities = State.Map.GetAllEntities(this); - State.AIData = new AI(this); + //State.AIData = new AI(this); /* mPlayers.Clear(); diff --git a/CarFire/CarFire/CarFire/Map.cs b/CarFire/CarFire/CarFire/Map.cs index ae49c8a..bc3fbbf 100644 --- a/CarFire/CarFire/CarFire/Map.cs +++ b/CarFire/CarFire/CarFire/Map.cs @@ -136,11 +136,7 @@ namespace CarFire /// 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; } - } + public static Tilemap Tilemap; /// /// Get and set the zoom of the map view. The default zoom is @@ -355,7 +351,6 @@ 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, @@ -365,6 +360,7 @@ namespace CarFire Debug.Assert(grid != null); Debug.Assert(entities != null); Debug.Assert(metadata.GridWidth * metadata.GridHeight == grid.Length); + Debug.Assert(Tilemap != null); mMetadata = metadata; mCleanGrid = grid; @@ -542,14 +538,14 @@ namespace CarFire public void Draw(SpriteBatch spriteBatch) { - if (mData.Tilemap == null) throw new Exception("Cannot draw map without first setting the tilemap."); + if (Tilemap == null) throw new Exception("Cannot draw map without first setting the tilemap."); mViewport = spriteBatch.GraphicsDevice.Viewport; for (int y = 0; y < mData.Metadata.GridHeight; y++) { for (int x = 0; x < mData.Metadata.GridWidth; x++) { - mData.Tilemap.Draw(spriteBatch, mData.GetCell(x, y), GetRectangleFromCoordinates(x, y)); + Tilemap.Draw(spriteBatch, mData.GetCell(x, y), GetRectangleFromCoordinates(x, y)); } } } diff --git a/CarFire/CarFire/CarFire/PathFinder.cs b/CarFire/CarFire/CarFire/PathFinder.cs index c37e518..02c645c 100644 --- a/CarFire/CarFire/CarFire/PathFinder.cs +++ b/CarFire/CarFire/CarFire/PathFinder.cs @@ -152,13 +152,12 @@ namespace CarFire #endif foreach (Point point in neighbors) { - Cell inQueue = mCells[point.X, point.Y]; - if (0 <= point.X && point.X < mGridWidth && 0 <= point.Y && point.Y < mGridHeight && mGrid[point.X, point.Y]) { int cost = cell.G + costFunction(cell.Point, point); + Cell inQueue = mCells[point.X, point.Y]; if (inQueue == null) { Cell neighbor = new Cell(point, cost, heuristic(point, finish), cell); -- 2.45.2