X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fcarfire;a=blobdiff_plain;f=CarFire%2FCarFire%2FCarFire%2FGame.cs;h=9a44ff37f16629945ff18469cf4e862935903167;hp=f91882e047c08f85e578ec0e3716d3cce5986d9d;hb=f4202b11a1891486216aab3c6b1370fc9a3eb89a;hpb=398bc41a3075cfa9c9ad5dc607a86c56a4e7e913 diff --git a/CarFire/CarFire/CarFire/Game.cs b/CarFire/CarFire/CarFire/Game.cs index f91882e..9a44ff3 100644 --- a/CarFire/CarFire/CarFire/Game.cs +++ b/CarFire/CarFire/CarFire/Game.cs @@ -15,6 +15,9 @@ namespace CarFire public class GameState { #region Public Properties + + public int HitMonsterScore { get { return hitMonsterScore; } } + public int KillMonsterScore { get { return killMonsterScore; } } public long FrameNumber { get { return mFrameNumber; } } @@ -27,7 +30,6 @@ namespace CarFire public List mProjectiles = new List(); public Player[] mCharacters; public Display mDisplay; - public AI AIData; #endregion @@ -157,7 +159,8 @@ namespace CarFire #region Private Variables - + private const int hitMonsterScore = 20; + private const int killMonsterScore = 100; int mNumberOfPlayers; public Point[] mMouseLocation; public bool[] mMouseButton; @@ -221,11 +224,17 @@ namespace CarFire { get { - bool[,] grid = State.Map.Grid; + bool[,] grid = (bool[,])State.Map.Grid.Clone(); foreach (IEntity entity in State.Entities) { Point coordinates = entity.Coordinates; - if (State.Map.IsCellOpen(coordinates)) grid[coordinates.X, coordinates.Y] = false; + grid[coordinates.X, coordinates.Y] = false; + } + foreach (Player player in State.mCharacters) + { + if (player == null) continue; + Point coordinates = player.Coordinates; + grid[coordinates.X, coordinates.Y] = false; } return grid; } @@ -236,6 +245,11 @@ namespace CarFire #region Public Methods + /// + /// Get an entity at a certain place on the map. + /// + /// The coordinates. + /// The entity, or null if none is at that location. public IEntity GetEntityAtCoordinates(Point point) { foreach (IEntity entity in State.Entities) @@ -245,6 +259,11 @@ namespace CarFire return null; } + /// + /// Get a player at a certain place on the map. + /// + /// The coordinates. + /// The player, or null if none is at that location. public Player GetPlayerAtCoordinates(Point point) { foreach (Player player in State.mCharacters) @@ -254,32 +273,66 @@ namespace CarFire return null; } + /// + /// Determine if a cell is open, depending on the static scenery + /// of the map and if there are any collidable entities. + /// + /// The coordinates. + /// True if the cell is open; false otherwise. public bool IsCellOpen(Point point) { if (!State.Map.IsCellOpen(point)) return false; - if (GetEntityAtCoordinates(point) != null) return false; + IEntity entity = GetEntityAtCoordinates(point); + if (entity != null && entity.IsCollidable) return false; + Player player = GetPlayerAtCoordinates(point); + if (player != null) return false; return true; } - public Game() + /// + /// Remove a specific entity from the game. The entity can still + /// be tracked some other way, but it won't included when the game is + /// updating and drawing stuff. + /// + /// The entity. + /// The entity that was removed, or null if no entity was removed. + public IEntity RemoveEntity(IEntity entity) { - + if (State.Entities.Remove(entity)) return entity; + return null; } + /// - /// This method should be called whenever the players want to move to a new map. - /// Not implemented yet. Need some way to get next map. + /// Move on to the next map, and advance the level. /// - public void startNewMap() + public void AdvanceLevel() { + // TODO: Load the next map, etc... //TODO somehow get next map State.Entities.Clear(); - //State.Map = State.Map.getNextMap(); + String nextMap = State.Map.Next; + State.Map = mContentManager.Load("Maps/"+nextMap); for (int i = 0; i < State.mCharacters.Length; i++) { State.mCharacters[i].Coordinates = State.Map.GetStartingPositionForPlayer(i + 1); } State.Entities = State.Map.GetAllEntities(this); } + + /// + /// Restart the current level. + /// + public void Reset() + { + State.Map.Reset(); + // TODO: Do other stuff to reset everything. + } + + + public Game() + { + + } public void LoadContent(ContentManager contentManager) { mContentManager = contentManager; @@ -329,47 +382,49 @@ 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)); - 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; + 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(3, 2), TileFlags.Closed | TileFlags.Wall); + tilemap.SetTile('#', new Point(4, 2), TileFlags.Closed | TileFlags.Wall); + tilemap.SetTile('$', new Point(5, 2), TileFlags.Closed | TileFlags.Wall); + tilemap.SetTile('%', new Point(6, 2), TileFlags.Closed | TileFlags.Wall); + tilemap.SetTile('^', new Point(8, 2), TileFlags.Closed | TileFlags.Wall); + tilemap.SetTile('&', new Point(9, 2), TileFlags.Closed | TileFlags.Wall); + tilemap.SetTile('*', new Point(0, 3), TileFlags.Closed | TileFlags.Wall); + tilemap.SetTile('(', new Point(1, 3), TileFlags.Closed | TileFlags.Wall); + tilemap.SetTile(')', new Point(2, 3), TileFlags.Closed | TileFlags.Wall); + tilemap.SetTile('-', new Point(3, 3), TileFlags.Closed | TileFlags.Wall); + tilemap.SetTile('=', new Point(4, 3), TileFlags.Closed | TileFlags.Wall); + tilemap.SetTile('_', new Point(5, 3), TileFlags.Closed | TileFlags.Wall); + tilemap.SetTile('+', new Point(6, 3), TileFlags.Closed | TileFlags.Wall); + tilemap.SetTile('|', new Point(8, 3), TileFlags.Closed | TileFlags.Wall); + tilemap.SetTile('[', new Point(0, 4), TileFlags.Default); + 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(7, 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(4, 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); + Map.Tilemap = tilemap; + + // Load the first map. + State.Map = mContentManager.Load("Maps/colosseumClosed"); State.Entities = State.Map.GetAllEntities(this); - State.AIData = new AI(this); + mAIData = new AI(this); /* mPlayers.Clear(); @@ -437,7 +492,23 @@ namespace CarFire { State.AdvanceFrame(mInputs, elapsedTime.Milliseconds); // Apply the inputs, advance game state. State.mDisplay.Update(elapsedTime, mThisPlayerID); - State.Entities.ForEach(delegate(IEntity e) { e.Update(elapsedTime); }); + State.Entities.ForEach(delegate(IEntity e) + { + IMonster m = e as IMonster; + if (m != null) + { + if (State.mCharacters[0] != null && mAIData.spaceVisible(e.Coordinates, State.mCharacters[0].Coordinates)) + { + m.Chasing(State.mCharacters[0].Coordinates); + } + else + { + m.DefaultAction(); + } + } + e.Update(elapsedTime); + }); + //State.Entities.ForEach(delegate(IEntity e) { e.Update(elapsedTime); }); mInputs = new NextInputs(State.NumberOfPlayers); // Start with inputs cleared on the next frame. //mDisplay.Update(elapsedTime); return State.FrameNumber; @@ -484,7 +555,7 @@ namespace CarFire #region Private Variables SpriteFont menu; - + AI mAIData; ContentManager mContentManager; NextInputs mInputs;