From: Charles Date: Sat, 24 Apr 2010 19:42:12 +0000 (+0000) Subject: Implemented map tiles; started new Key entity; added missing variables to Melee.cs... X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=fc34f843ea42a3496a7ff5dd04853695ba628e8b;p=chaz%2Fcarfire Implemented map tiles; started new Key entity; added missing variables to Melee.cs so it will compile git-svn-id: https://bd85.net/svn/cs3505_group@142 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- diff --git a/CarFire/CarFire/CarFire/CarFire.csproj b/CarFire/CarFire/CarFire/CarFire.csproj index f4c5b70..e59c3df 100644 --- a/CarFire/CarFire/CarFire/CarFire.csproj +++ b/CarFire/CarFire/CarFire/CarFire.csproj @@ -86,6 +86,7 @@ + @@ -107,6 +108,7 @@ + diff --git a/CarFire/CarFire/CarFire/Content/Maps/level1.cfmap b/CarFire/CarFire/CarFire/Content/Maps/level1.cfmap index db46b43..7431e08 100644 --- a/CarFire/CarFire/CarFire/Content/Maps/level1.cfmap +++ b/CarFire/CarFire/CarFire/Content/Maps/level1.cfmap @@ -1,9 +1,9 @@ [metadata] author = Chaz McGarvey - levelname = Stable + levelname = The Beginning type = Campaign dimensions = [80,21] - tileset = FuturisticBuilding + tileset = Warehouse numplayers = <1,4> [M] @@ -11,6 +11,11 @@ speed = 10 path = [16,8] [20,6] wait(5) [56,9] [71,17] [75,2] [11,13] +[k] + type = Key + condition = True() + event = PickUp() + [T] type = Trigger condition = Print("Trigger tested.") False() @@ -18,14 +23,14 @@ [maptable] +------------------------------------------------------------------------------+ -|T | -| 1 | -| M | -| 2 +---- | +| | +| 1 2 | +| T | +| 3 4 +---- | | | M | -| 3 | | +| k | | | |------------------------------------------ | -| 4 | | | +| | | | | | | | +-------------+----+ | \ / | | | | \ / | diff --git a/CarFire/CarFire/CarFire/Game.cs b/CarFire/CarFire/CarFire/Game.cs index 45b79d1..c2a7aaf 100644 --- a/CarFire/CarFire/CarFire/Game.cs +++ b/CarFire/CarFire/CarFire/Game.cs @@ -329,9 +329,45 @@ namespace CarFire State.mDisplay = new Display(this); State.mDisplay.LoadContent(mContentManager); + 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)); + State.Map = mContentManager.Load("Maps/level1"); + State.Map.Tilemap = tilemap; State.Entities = State.Map.GetAllEntities(this); - Map.DefaultTile = mContentManager.Load("default"); /* mPlayers.Clear(); diff --git a/CarFire/CarFire/CarFire/Key.cs b/CarFire/CarFire/CarFire/Key.cs new file mode 100644 index 0000000..0fab663 --- /dev/null +++ b/CarFire/CarFire/CarFire/Key.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; + +namespace CarFire +{ + /// + /// A key entity. Keys can be used to unlock doors... what a surprise. + /// + public class Key : Trigger + { + #region Public Methods + + /// + /// Construct a key entity. + /// + /// The entity identifier. + /// The position. + /// The key-value pairs. + /// The game reference. + public Key(char identifier, Point position, Dictionary info, Game game) : + base(identifier, position, info, game) + { + mPosition = new Vector2(position.X, position.Y); + mGame = game; + } + + public override void LoadContent(ContentManager contentManager) + { + mTexture = contentManager.Load("default"); + } + + public override void Draw(SpriteBatch spriteBatch) + { + Rectangle position = mGame.State.Map.GetRectangleFromCoordinates(mPosition); + spriteBatch.Draw(mTexture, position, Color.White); + } + + #endregion + + + #region Private Variables + + Texture2D mTexture; + Game mGame; + Vector2 mPosition; + + #endregion + } +} diff --git a/CarFire/CarFire/CarFire/Map.cs b/CarFire/CarFire/CarFire/Map.cs index 0e66b13..1970994 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. @@ -394,6 +403,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 +504,7 @@ namespace CarFire class View { public Vector2 CenterCell; + public Tilemap Tilemap; public float Zoom; @@ -510,21 +526,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)); } } } diff --git a/CarFire/CarFire/CarFire/Melee.cs b/CarFire/CarFire/CarFire/Melee.cs index 4c053a6..f523012 100644 --- a/CarFire/CarFire/CarFire/Melee.cs +++ b/CarFire/CarFire/CarFire/Melee.cs @@ -18,6 +18,8 @@ namespace CarFire int coolDown; Texture2D charModel; Texture2D projectileModel; + int velocityX; + int velocityY; #endregion #region Public Methods diff --git a/CarFire/CarFire/CarFire/Script.cs b/CarFire/CarFire/CarFire/Script.cs index 146bb22..9676bbb 100644 --- a/CarFire/CarFire/CarFire/Script.cs +++ b/CarFire/CarFire/CarFire/Script.cs @@ -7,10 +7,17 @@ using System.Diagnostics; namespace CarFire { + /// + /// The Script class handles the parsing and execution of lists + /// of functions. Scripts are closely related to triggers. + /// public class Script { #region Public Properties + /// + /// Determine if the script is in the process of being run. + /// public bool IsRunning { get { return mIsRunning; } } #endregion @@ -18,9 +25,14 @@ namespace CarFire #region Public Methods + /// + /// Construct a script object with code and a game reference. + /// + /// The script code. + /// A game reference. public Script(string code, Game game) { - mGame = game; + mImpl = new Impl(game); string[] functions = Parse.List(code); if (functions != null) @@ -44,6 +56,17 @@ namespace CarFire else throw new Exception("Script could not be parsed: " + code); } + /// + /// Start execution of the script. If there is no need to break + /// execution before the script ends, it will finish before this method + /// call ends. Otherwise, execution will be delayed and will finish sometime + /// in the future. This will execute each function in sequence as long + /// as each function evaluates to true. If a function does not evaluate to true, + /// this method will return and execution will be delayed. In either case, + /// the evaluation of the last function is returned by this method. + /// + /// The player associated with this script. + /// Evaluation of the last function call. public bool Run(Player player) { bool result = false; @@ -69,6 +92,12 @@ namespace CarFire #region Private Methods + /// + /// Call a function in the last at a certain index. + /// + /// The function index. + /// The associated player object. + /// The evaluation of the function. bool Call(int index, Player player) { Debug.Assert(0 <= index && index < mFunctions.Count); @@ -118,6 +147,14 @@ namespace CarFire } return true; } + + + public Impl(Game game) + { + mGame = game; + } + + Game mGame; } class Function @@ -140,11 +177,10 @@ namespace CarFire #region Private Variables - Game mGame; + Impl mImpl; List mFunctions = new List(); bool mIsRunning; int mRunningIndex; - Impl mImpl = new Impl(); #endregion } diff --git a/CarFire/CarFire/CarFire/Tilemap.cs b/CarFire/CarFire/CarFire/Tilemap.cs new file mode 100644 index 0000000..d044108 --- /dev/null +++ b/CarFire/CarFire/CarFire/Tilemap.cs @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Diagnostics; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +namespace CarFire +{ + /// + /// Small wrapper around a texture to provide easy access to + /// tile rectangles. + /// + public class Tilemap + { + #region Public Properties + + /// + /// Get the texture for this tilemap. + /// + public Texture2D Texture { get { return mTexture; } } + + #endregion + + + #region Public Methods + + /// + /// Construct a tilemap with a texture and dimensions in + /// tiles. + /// + /// The texture. + /// Number of tiles across. + /// Number of tiles down. + public Tilemap(Texture2D texture, int width, int height) + { + mTexture = texture; + mWidth = width; + mHeight = height; + mTileW = mTexture.Width / mWidth; + mTileH = mTexture.Height / mHeight; + } + + + /// + /// Get a tile rectangle from a tile coordinate. + /// + /// Tile coordinates; [0,0] being the + /// top-left tile. + /// Rectangle surrounding the tile. + public Rectangle GetRectangleForTile(Point point) + { + return GetRectangleForTile(point.X, point.Y); + } + + /// + /// Get a tile rectangle from a tile coordinate + /// + /// X-coordinate. + /// Y-coordinate. + /// Rectangle surrounding the tile. + public Rectangle GetRectangleForTile(int x, int y) + { + Debug.Assert(0 <= x && x < mWidth && 0 <= y && y < mHeight); + return new Rectangle(x * mTileW, y * mTileH, mTileW, mTileH); + } + + /// + /// Get a tile rectangle from a tile character. + /// + /// Tile character. + /// Rectangle surrounding the tile. + public Rectangle GetRectangleForTile(char tile) + { + return mTiles[tile]; + } + + + /// + /// Associate a tile character with tile coordinates. This + /// lets you access tile rectangles by character. + /// + /// Tile character. + /// Coordinates. + public void SetTile(char tile, Point point) + { + mTiles.Add(tile, GetRectangleForTile(point)); + } + + + /// + /// Draw a tile to the screen. + /// + /// The b2bomber. + /// The tile. + /// The screen rectangle to draw at. + public void Draw(SpriteBatch spriteBatch, char tile, Rectangle screenRect) + { + spriteBatch.Draw(mTexture, screenRect, GetRectangleForTile(tile), Color.White); + } + + #endregion + + + #region Private Variables + + Texture2D mTexture; + int mWidth; + int mHeight; + int mTileW; + int mTileH; + Dictionary mTiles = new Dictionary(); + + #endregion + } +} diff --git a/CarFire/CarFire/CarFire/Trigger.cs b/CarFire/CarFire/CarFire/Trigger.cs index 25cc11e..6d639d8 100644 --- a/CarFire/CarFire/CarFire/Trigger.cs +++ b/CarFire/CarFire/CarFire/Trigger.cs @@ -17,6 +17,13 @@ namespace CarFire { #region Public Methods + /// + /// Construct a trigger entity. + /// + /// The entity identifier. + /// The position. + /// The key-value pairs. + /// The game reference. public Trigger(char identifier, Point position, Dictionary info, Game game) { mGame = game; @@ -38,7 +45,11 @@ namespace CarFire else throw new Exception("Triggers must define an event script."); } - public void Update(TimeSpan timeSpan) + /// + /// Check the trigger condition and execute the event if the + /// condition evaluates to true. + /// + public void Call() { Player player = mGame.GetPlayerAtCoordinates(mCoordinates); if (player != null) @@ -56,12 +67,22 @@ namespace CarFire } } - public void LoadContent(ContentManager contentManager) + + /// + /// Calls the trigger. + /// + /// Unused. + public virtual void Update(TimeSpan timeSpan) + { + Call(); + } + + public virtual void LoadContent(ContentManager contentManager) { // No implementation needed. } - public void Draw(SpriteBatch spriteBatch) + public virtual void Draw(SpriteBatch spriteBatch) { // No implementation needed. }