2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Content;
7 using Microsoft.Xna.Framework.Graphics;
22 public class SaberMonster : IMonster
24 public SaberMonster(char identifier, Point position, Dictionary<string, string> info, Game game)
27 mMotion = new MovementManager(position);
31 if (info.TryGetValue("speed", out speedString))
33 int? speed = Parse.Integer(speedString);
34 if (speed != null) mMotion.Speed = speed.Value;
37 // Get the "idle path" coordinates loaded from the map.
39 if (info.TryGetValue("path", out idlePath))
41 string[] idlePathPoints = Parse.List(idlePath);
42 foreach (string pathPoint in idlePathPoints)
44 Point? point = Parse.Coordinates(pathPoint);
45 if (point != null) mIdlePath.Add(point.Value);
53 public void StartPacing()
55 mState = AiState.Pacing;
57 if (mIdlePath.Count == 0) return;
59 // Determine the best (closest) waypoint to start at.
61 int closest = int.MaxValue;
62 for (int i = 0; i < mIdlePath.Count; i++)
64 int distance = PathFinder.GetManhattanDistance(Coordinates, mIdlePath[i]);
65 if (distance < closest)
72 PathFinder pathFinder = new PathFinder(mGame.Grid);
73 mPath = new List<Point>(32);
74 mPath.Add(Coordinates);
75 mPath.AddRange(pathFinder.GetPath(mMotion.Coordinates, mIdlePath[mIdlePathIndex]));
76 mPath.Add(mIdlePath[mIdlePathIndex]);
80 Direction GetDirectionToNextCell()
82 if (mPathIndex >= mPath.Count)
85 PathFinder pathFinder = new PathFinder(mGame.Grid);
86 mPath = new List<Point>(32);
87 mPath.Add(Coordinates);
88 mPath.AddRange(pathFinder.GetPath(mMotion.Coordinates, mIdlePath[mIdlePathIndex % mIdlePath.Count]));
89 mPath.Add(mIdlePath[mIdlePathIndex % mIdlePath.Count]);
93 if (mPath[mPathIndex % mPath.Count] == mMotion.Coordinates)
96 mPathDirection = MovementManager.GetDirection(mMotion.Coordinates, mPath[mPathIndex % mPath.Count]);
99 return mPathDirection;
103 #region IMonster Members
107 get { throw new NotImplementedException(); }
113 #region ICharacter Members
115 public void LoadContent(ContentManager contentManager)
117 mTexture = contentManager.Load<Texture2D>("menuItem");
120 public void Update(TimeSpan timeSpan)
122 if (mState == AiState.Pacing)
124 mMotion.Update(timeSpan, GetDirectionToNextCell());
128 public void Draw(SpriteBatch spriteBatch)
130 Rectangle position = mGame.State.Map.GetRectangleFromCoordinates(mMotion.Position);
131 spriteBatch.Draw(mTexture, position, Color.White);
136 get { throw new NotImplementedException(); }
139 public void causeDamageTo(int amount)
141 throw new NotImplementedException();
144 public Vector2 Position { get { return mMotion.Position; } }
146 public Point Coordinates { get { return mMotion.Coordinates; } }
151 #region Private Variables
156 MovementManager mMotion;
158 List<Point> mIdlePath = new List<Point>();
163 Direction mPathDirection;