From d861be5538dfe866f867a6e237311ba6b743e863 Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 26 Apr 2010 17:46:26 +0000 Subject: [PATCH] Implemented tile flags so we can define and determine what a tile is supposed to represent. This is needed to determine the walkability of certain tiles, and apparently the AI also needs to determine walls. git-svn-id: https://bd85.net/svn/cs3505_group@151 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- CarFire/CarFire/CarFire/Game.cs | 66 +++++++++++++++--------------- CarFire/CarFire/CarFire/Map.cs | 20 ++++----- CarFire/CarFire/CarFire/Tilemap.cs | 31 +++++++++++++- 3 files changed, 72 insertions(+), 45 deletions(-) diff --git a/CarFire/CarFire/CarFire/Game.cs b/CarFire/CarFire/CarFire/Game.cs index 8b9b075..a269367 100644 --- a/CarFire/CarFire/CarFire/Game.cs +++ b/CarFire/CarFire/CarFire/Game.cs @@ -335,39 +335,39 @@ namespace CarFire Texture2D mapTiles = mContentManager.Load("graphics/wallAndFloorTilesNoEdgeScale"); Tilemap tilemap = new Tilemap(mapTiles, 10, 7); - tilemap.SetTile(' ', new Point(4, 5)); - tilemap.SetTile('`', new Point(0, 1)); - tilemap.SetTile('~', new Point(1, 1)); - tilemap.SetTile('!', new Point(3, 1)); - tilemap.SetTile('@', new Point(4, 1)); - tilemap.SetTile('#', new Point(5, 1)); - tilemap.SetTile('$', new Point(6, 1)); - tilemap.SetTile('%', new Point(8, 1)); - tilemap.SetTile('^', new Point(9, 1)); - tilemap.SetTile('&', new Point(0, 2)); - tilemap.SetTile('=', new Point(1, 2)); - tilemap.SetTile('*', new Point(2, 2)); - tilemap.SetTile('(', new Point(4, 2)); - tilemap.SetTile(')', new Point(0, 3)); - tilemap.SetTile('_', new Point(2, 3)); - tilemap.SetTile('-', new Point(9, 3)); - tilemap.SetTile(',', new Point(1, 4)); - tilemap.SetTile('+', new Point(2, 4)); - tilemap.SetTile('[', new Point(3, 4)); - tilemap.SetTile(']', new Point(4, 4)); - tilemap.SetTile('{', new Point(5, 4)); - tilemap.SetTile('}', new Point(6, 4)); - tilemap.SetTile('\\', new Point(8, 4)); - tilemap.SetTile('|', new Point(9, 4)); - tilemap.SetTile(';', new Point(0, 5)); - tilemap.SetTile(':', new Point(1, 5)); - tilemap.SetTile('\'', new Point(2, 5)); - tilemap.SetTile('"', new Point(3, 5)); - tilemap.SetTile('.', new Point(5, 5)); - tilemap.SetTile('<', new Point(6, 5)); - tilemap.SetTile('>', new Point(7, 5)); - tilemap.SetTile('/', new Point(8, 5)); - tilemap.SetTile('?', new Point(9, 5)); + tilemap.SetTile(' ', new Point(4, 5), TileFlags.Default); + tilemap.SetTile('`', new Point(0, 1), TileFlags.Closed | TileFlags.Wall); + tilemap.SetTile('~', new Point(1, 1), TileFlags.Closed | TileFlags.Wall); + tilemap.SetTile('!', new Point(3, 1), TileFlags.Closed | TileFlags.Wall); + tilemap.SetTile('@', new Point(4, 1), TileFlags.Closed | TileFlags.Wall); + tilemap.SetTile('#', new Point(5, 1), TileFlags.Closed | TileFlags.Wall); + tilemap.SetTile('$', new Point(6, 1), TileFlags.Closed | TileFlags.Wall); + tilemap.SetTile('%', new Point(8, 1), TileFlags.Closed | TileFlags.Wall); + tilemap.SetTile('^', new Point(9, 1), TileFlags.Closed | TileFlags.Wall); + tilemap.SetTile('&', new Point(0, 2), TileFlags.Closed | TileFlags.Wall); + tilemap.SetTile('=', new Point(1, 2), TileFlags.Closed | TileFlags.Wall); + tilemap.SetTile('*', new Point(2, 2), TileFlags.Closed | TileFlags.Wall); + tilemap.SetTile('(', new Point(4, 2), TileFlags.Closed | TileFlags.Wall); + tilemap.SetTile(')', new Point(0, 3), TileFlags.Closed | TileFlags.Wall); + tilemap.SetTile('_', new Point(2, 3), TileFlags.Closed | TileFlags.Wall); + tilemap.SetTile('-', new Point(9, 3), TileFlags.Closed | TileFlags.Wall); + tilemap.SetTile(',', new Point(1, 4), TileFlags.Default); + tilemap.SetTile('+', new Point(2, 4), TileFlags.Default); + tilemap.SetTile('[', new Point(3, 4), TileFlags.Default); + tilemap.SetTile(']', new Point(4, 4), TileFlags.Default); + tilemap.SetTile('{', new Point(5, 4), TileFlags.Default); + tilemap.SetTile('}', new Point(6, 4), TileFlags.Default); + tilemap.SetTile('\\', new Point(8, 4), TileFlags.Default); + tilemap.SetTile('|', new Point(9, 4), TileFlags.Default); + tilemap.SetTile(';', new Point(0, 5), TileFlags.Default); + tilemap.SetTile(':', new Point(1, 5), TileFlags.Default); + tilemap.SetTile('\'', new Point(2, 5), TileFlags.Default); + tilemap.SetTile('"', new Point(3, 5), TileFlags.Default); + tilemap.SetTile('.', new Point(5, 5), TileFlags.Default); + tilemap.SetTile('<', new Point(6, 5), TileFlags.Default); + tilemap.SetTile('>', new Point(7, 5), TileFlags.Default); + tilemap.SetTile('/', new Point(8, 5), TileFlags.Default); + tilemap.SetTile('?', new Point(9, 5), TileFlags.Default); State.Map = mContentManager.Load("Maps/level1"); State.Map.Tilemap = tilemap; diff --git a/CarFire/CarFire/CarFire/Map.cs b/CarFire/CarFire/CarFire/Map.cs index 1b8b5a8..ae49c8a 100644 --- a/CarFire/CarFire/CarFire/Map.cs +++ b/CarFire/CarFire/CarFire/Map.cs @@ -138,8 +138,8 @@ namespace CarFire /// public Tilemap Tilemap { - get { return mView.Tilemap; } - set { mView.Tilemap = value; } + get { return mData.Tilemap; } + set { mData.Tilemap = value; } } /// @@ -355,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, @@ -399,17 +400,17 @@ 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 (mGrid[x, y] == '-' || mGrid[x, y] == '|' || mGrid[x, y] == '+' || mGrid[x, y] == '/' || mGrid[x, y] == '\\'); - return false; + 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) { if (IsOnMap(x, y)) @@ -520,7 +521,6 @@ namespace CarFire class View { public Vector2 CenterCell; - public Tilemap Tilemap; public float Zoom; @@ -542,14 +542,14 @@ namespace CarFire public void Draw(SpriteBatch spriteBatch) { - if (Tilemap == null) throw new Exception("Cannot draw map without first setting the tilemap."); + if (mData.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++) { - Tilemap.Draw(spriteBatch, mData.GetCell(x, y), GetRectangleFromCoordinates(x, y)); + mData.Tilemap.Draw(spriteBatch, mData.GetCell(x, y), GetRectangleFromCoordinates(x, y)); } } } diff --git a/CarFire/CarFire/CarFire/Tilemap.cs b/CarFire/CarFire/CarFire/Tilemap.cs index d044108..50906a8 100644 --- a/CarFire/CarFire/CarFire/Tilemap.cs +++ b/CarFire/CarFire/CarFire/Tilemap.cs @@ -8,6 +8,20 @@ using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; namespace CarFire { + /// + /// Flag options to define attributes for individual tiles. + /// + [Flags] + public enum TileFlags + { + Open = 0x01, + Closed = 0x02, + Floor = 0x04, + Wall = 0x08, + Default = 0x05 + } + + /// /// Small wrapper around a texture to provide easy access to /// tile rectangles. @@ -77,15 +91,27 @@ namespace CarFire } + /// + /// Get the flags associated with a tile character. + /// + /// Tile character. + /// Tile flags. + public TileFlags GetTileFlags(char tile) + { + return mFlags[tile]; + } + + /// /// Associate a tile character with tile coordinates. This - /// lets you access tile rectangles by character. + /// lets you access tiles by character. /// /// Tile character. /// Coordinates. - public void SetTile(char tile, Point point) + public void SetTile(char tile, Point point, TileFlags flags) { mTiles.Add(tile, GetRectangleForTile(point)); + mFlags.Add(tile, flags); } @@ -111,6 +137,7 @@ namespace CarFire int mTileW; int mTileH; Dictionary mTiles = new Dictionary(); + Dictionary mFlags = new Dictionary(); #endregion } -- 2.45.2