Exemple #1
0
 public BBSprite(BaseSprite baseSprite, Random r)
 {
     _baseSprite = baseSprite;
     _currentFrame = 0;
     _animated = _baseSprite.Frames.Count > 1;
     if (_animated)
     {
         _frameTimer = Utility.GetIntValue(_baseSprite.FrameLength[_currentFrame], r) / 1000.0f;
     }
 }
Exemple #2
0
        public static bool Initialize(out string reason)
        {
            if (_initalized)
            {
                reason = null;
                return true;
            }
            try
            {
                Sprites = new Dictionary<string, BaseSprite>();
                string file = Path.Combine(Environment.CurrentDirectory, "sprites.xml");
                string graphicDirectory = Path.Combine(Environment.CurrentDirectory, "graphics");
                if (!File.Exists(file))
                {
                    reason = "Sprites.xml file does not exist";
                    return false;
                }

                XDocument doc = XDocument.Load(file);
                XElement root = doc.Element("Sprites");
                foreach (XElement sprite in root.Elements())
                {
                    var newSprite = new BaseSprite();
                    if (!newSprite.LoadSprite(sprite, graphicDirectory, out reason))
                    {
                        return false;
                    }
                    Sprites.Add(newSprite.Name, newSprite);
                }
                _initalized = true;
                reason = null;
                return true;
            }
            catch (Exception e)
            {
                reason = e.Message;
                return false;
            }
        }