/// <summary> /// Создаёт новый экземпляр класса <see cref="CheckBox"/>. /// </summary> /// <param name="game">Ссылка на игру</param> /// <param name="caption">Заголовок</param> public CheckBox(SourceryGame game, string caption) { Caption = caption; _Sprite = new AnimateSprite(game.CheckBox,4,1); _Font = game.Font; _Checked = false; }
/// <summary>Загружаем все необходимое для отрисовки</summary> private void LoadSprites(SourceryGame game) { _Font = game.Font; _BigFont = game.BigFont; _Back = new AnimateSprite(game.Content.Load <Texture2D>("controls/ReloadingButton"), 3, 1); LoadSprite(game); }
/// <summary> /// Создаёт новый экземпляр класса <see cref="CheckBox"/>. /// </summary> /// <param name="game">Ссылка на игру</param> /// <param name="caption">Заголовок</param> public CheckBox(SourceryGame game, string caption) { Caption = caption; _Sprite = new AnimateSprite(game.CheckBox, 4, 1); _Font = game.Font; _Checked = false; }
/// <summary>Создаёт новый экземпляр класса <see cref="Movement"/>.</summary> /// <param name="board">Вся доска.</param> /// <param name="state">Прямоугольник отрисовки.</param> /// <param name="current">Текущая ячейка.</param> /// <param name="speed">Скорость перемещения.</param> /// <param name="sprite">Анимация объекта.</param> /// <param name="animation">Параметры анимации объекта.</param> public Movement(Rectangle state, Cell current, int speed, AnimateSprite sprite, PlayerAnimation animation, bool IsMagic) { IsEnd = true; _CurrentState = state; _Current = current; _Speed = speed; _Tile = sprite; _Animation = animation; _Field = Helper.Field; _Field = new PathNode[Helper.Board.GetLength(0), Helper.Board.GetLength(1)]; bool pass; for (int i = 0; i < Helper.Board.GetLength(0); i++) for (int j = 0; j < Helper.Board.GetLength(1); j++) { if (IsMagic) pass = false; else pass = (Helper.Board[i, j].Type != CellType.Passable); _Field[i, j] = new PathNode() { IsWall = pass , X = Helper.Board[i, j].Rect.X, Y = Helper.Board[i, j].Rect.Y, i = i, j = j, }; } }
/// <summary>Создаёт новый экземпляр класса <see cref="Movement"/>.</summary> /// <param name="board">Вся доска.</param> /// <param name="state">Прямоугольник отрисовки.</param> /// <param name="current">Текущая ячейка.</param> /// <param name="speed">Скорость перемещения.</param> /// <param name="sprite">Анимация объекта.</param> /// <param name="animation">Параметры анимации объекта.</param> public Movement(Rectangle state, Cell current, int speed, AnimateSprite sprite, PlayerAnimation animation, bool IsMagic) { IsEnd = true; _CurrentState = state; _Current = current; _Speed = speed; _Tile = sprite; _Animation = animation; _Field = Helper.Field; _Field = new PathNode[Helper.Board.GetLength(0), Helper.Board.GetLength(1)]; bool pass; for (int i = 0; i < Helper.Board.GetLength(0); i++) { for (int j = 0; j < Helper.Board.GetLength(1); j++) { if (IsMagic) { pass = false; } else { pass = (Helper.Board[i, j].Type != CellType.Passable); } _Field[i, j] = new PathNode() { IsWall = pass, X = Helper.Board[i, j].Rect.X, Y = Helper.Board[i, j].Rect.Y, i = i, j = j, }; } } }
/// <summary> /// Создаёт новый экземпляр класса <see cref="Button"/>. /// </summary> /// <param name="texture">Текстура кнопки</param> /// <param name="text">Текст кнопки</param> /// <param name="font">Шрифт кнопки</param> public Button(SourceryGame game, string text) { _Sprite = new AnimateSprite(game.Button, 3, 1); Caption = text; _Font = game.Font; _Sound = game.ClickSound; _Game = game; }
/// <summary>Создаёт новый экземпляр класса <see cref="ColorZone"/>.</summary> /// <param name="game">Ссылка на игру.</param> /// <param name="MaxResource">Максимум.</param> /// <param name="CurrentResourse">Текущее положение.</param> /// <param name="Position">Номер спрайта.</param> public ColorZone(SourceryGame game, int MaxResource, int CurrentResourse, int Position) { _MaxResourse = MaxResource; _CurrentResourse = CurrentResourse; _Sprite = new AnimateSprite(game.AllMagic, 1, 5); _Sprite.CurrentFrame = Position; _Font = game.BigFont; _Back = game.Content.Load <Texture2D>("Controls/Back"); }
/// <summary>Создаёт новый экземпляр класса <see cref="Edit"/>.</summary> /// <param name="game">Ссылка на игру.</param> /// <param name="text">Текст.</param> public Edit(SourceryGame game) { _Texture = new AnimateSprite(game.Edit, 2, 1); _Font = game.Font; _Text = game.PlayerName; _Cursor = game.Editing; _Draw = false; _Game = game; }
/// <summary>Создаёт новый экземпляр класса <see cref="ColorZone"/>.</summary> /// <param name="game">Ссылка на игру.</param> /// <param name="MaxResource">Максимум.</param> /// <param name="CurrentResourse">Текущее положение.</param> /// <param name="Position">Номер спрайта.</param> public ColorZone(SourceryGame game, int MaxResource, int CurrentResourse, int Position) { _MaxResourse = MaxResource; _CurrentResourse = CurrentResourse; _Sprite = new AnimateSprite(game.AllMagic, 1, 5); _Sprite.CurrentFrame = Position; _Font = game.BigFont; _Back = game.Content.Load<Texture2D>("Controls/Back"); }
/// <summary> /// Создаёт новый экземпляр класса <see cref="TrackBar"/>. /// </summary> /// <param name="game">The game.</param> /// <param name="caption">The caption.</param> public TrackBar(SourceryGame game, string caption) { Caption = caption; _Game = game; _Sound = game.Content.Load <SoundEffect>("Sounds/Click"); _Font = game.Font; _Lent = new AnimateSprite(game.TrackLent, 11, 1); _Plus = new AnimateSprite(game.PlusButton, 2, 1); _Minus = new AnimateSprite(game.MinusButton, 2, 1); }
/// <summary> /// Создаёт новый экземпляр класса <see cref="PanelItem"/>. /// </summary> /// <param name="game">The game.</param> /// <param name="text">The text.</param> public PanelItem(SourceryGame game, string text,string fontName="") { Caption = text; _Texture = new AnimateSprite(game.ItemButton, 3, 1); if (fontName == "") _Font = game.BigFont; else _Font = game.Content.Load<SpriteFont>("Fonts/"+fontName); _Texture.CurrentFrame = 2; }
/// <summary> /// Создаёт новый экземпляр класса <see cref="TrackBar"/>. /// </summary> /// <param name="game">The game.</param> /// <param name="caption">The caption.</param> public TrackBar(SourceryGame game, string caption) { Caption = caption; _Game = game; _Sound = game.Content.Load<SoundEffect>("Sounds/Click"); _Font = game.Font; _Lent = new AnimateSprite(game.TrackLent, 11, 1); _Plus = new AnimateSprite(game.PlusButton, 2, 1); _Minus = new AnimateSprite(game.MinusButton, 2, 1); }
/// <summary>Создаёт новый экземпляр класса <see cref="Tower"/>.</summary> /// <param name="game">Ссылка на игру.</param> /// <param name="node">Запись в файле.</param> public Tower(XmlNode node) { Type = BuildingType.Tower; //Сам замок Sprite = new AnimateSprite(Helper.Game.Content.Load <Texture2D>("game/" + node.SelectSingleNode("Texture").InnerText), 1, 4); Sprite.CurrentFrame = Convert.ToInt32(node.SelectSingleNode("position").InnerText); //Подпись Signature = new AnimateSprite(Helper.Game.ColorStripe, 1, 5); Signature.CurrentFrame = Convert.ToInt32(node.SelectSingleNode("signaturePosition").InnerText); //Хоязин OwnerName = node.SelectSingleNode("ownerName").InnerText; //Положение X = Convert.ToInt32(node.SelectSingleNode("x").InnerText); Y = Convert.ToInt32(node.SelectSingleNode("y").InnerText); //Ресурс здания MaxResource = int.Parse(node.SelectSingleNode("maxResource").InnerText); CurrentResource = MaxResource; Reduction = MaxResource / 10; Font = Helper.Game.SmallFont; //Размеры здания var param = node.SelectSingleNode("width"); int width = 0; int height = 0; if (param != null) { width = Convert.ToInt32(param.InnerText); } param = node.SelectSingleNode("height"); if (param != null) { height = Convert.ToInt32(param.InnerText); } if (width != 0 && height != 0) { Rect = new Rectangle(X, Y, width, height); Width = width; Height = height; } else { Width = Sprite.Width; Height = Sprite.Height; Rect = new Rectangle(X, Y, Width, Height); } EnemySelector = Helper.Game.Selectors[0]; OurSelector = Helper.Game.Selectors[1]; }
/// <summary> /// Создаёт новый экземпляр класса <see cref="ComboBox"/>. /// </summary> /// <param name="game">The game.</param> /// <param name="values">The values.</param> public ComboBox(SourceryGame game, List<String> values) { _Values = new List<Control>(); foreach (string str in values) _Values.Add(new PanelItem(game, str,"Font")); foreach (Control item in _Values) item.OnValueChanged += OnElementSelected; _Sprite = new AnimateSprite(game.ComboBox, 3, 1); _Panel = game.ItemPanel; _Font = game.Font; }
//Загрузим соответствующий спрайт private void LoadSprite(SourceryGame game) { string name = _Node.SelectSingleNode("Animations/Texture").InnerText; int start = int.Parse(_Node.SelectSingleNode("Animations/Start").InnerText); int stop = int.Parse(_Node.SelectSingleNode("Animations/Stop").InnerText); int current = int.Parse(_Node.SelectSingleNode("Animations/Current").InnerText); _Sprite = new AnimateSprite(game.Content.Load <Texture2D>("animation/" + name), 8, 8); From = start; To = stop; Static = current; _Sprite.CurrentFrame = Static; }
/// <summary>Загружает параметры игрока из XML-файла</summary> /// <param name="node">Запись об игроке.</param> /// <param name="game">Ссылка на игру.</param> public void LoadPlayerParameters(XmlNode node, SourceryGame game) { //Читаем параметры из *.lvl string playerName = node.SelectSingleNode("Name").InnerText; string fileName = node.SelectSingleNode("File").InnerText; int x = Convert.ToInt32(node.SelectSingleNode("x").InnerText); int y = Convert.ToInt32(node.SelectSingleNode("y").InnerText); int startAnimation = Convert.ToInt32(node.SelectSingleNode("StartAnimation").InnerText); var type = node.SelectSingleNode("Type").InnerText; PlayerType playerType = (PlayerType)Enum.Parse(typeof(PlayerType), type); type = node.SelectSingleNode("Color").InnerText; Colors color = (Colors)Enum.Parse(typeof(Colors), type); //Читаем параметры героя XmlDocument doc = new XmlDocument(); doc.Load("data/players/" + fileName); string textureName = doc.SelectSingleNode("Player/Texture").InnerText; int width = int.Parse(doc.SelectSingleNode("Player/width").InnerText); int height = int.Parse(doc.SelectSingleNode("Player/height").InnerText); int speed = int.Parse(doc.SelectSingleNode("Player/speed").InnerText); _Animation = new PlayerAnimation(doc.SelectSingleNode("Player/Animation")); //Задаем начальные параметры _Tile = new AnimateSprite(game.Content.Load <Texture2D>("animation/" + textureName), 8, 24); _Tile.CurrentFrame = startAnimation; LoadColor(color); _CurrentState = new Rectangle(x - width / 2, y - height / 2, width, height); _Type = playerType; if (playerName == "") { Name = game.PlayerName; } else { Name = playerName; } foreach (Cell cell in Helper.Board) { if (cell.Rect.Contains(x, y)) { _CurrentCell = cell; break; } } CurrentMagic = MaxMagic; _Movement = new Movement(_CurrentState, _CurrentCell, speed, _Tile, _Animation, false); }
/// <summary> /// Создаёт новый экземпляр класса <see cref="PanelItem"/>. /// </summary> /// <param name="game">The game.</param> /// <param name="text">The text.</param> public PanelItem(SourceryGame game, string text, string fontName = "") { Caption = text; _Texture = new AnimateSprite(game.ItemButton, 3, 1); if (fontName == "") { _Font = game.BigFont; } else { _Font = game.Content.Load <SpriteFont>("Fonts/" + fontName); } _Texture.CurrentFrame = 2; }
/// <summary>Создаёт новый экземпляр класса <see cref="Tower"/>.</summary> /// <param name="game">Ссылка на игру.</param> /// <param name="node">Запись в файле.</param> public Tower(XmlNode node) { Type = BuildingType.Tower; //Сам замок Sprite = new AnimateSprite(Helper.Game.Content.Load<Texture2D>("game/" + node.SelectSingleNode("Texture").InnerText), 1, 4); Sprite.CurrentFrame = Convert.ToInt32(node.SelectSingleNode("position").InnerText); //Подпись Signature = new AnimateSprite(Helper.Game.ColorStripe, 1, 5); Signature.CurrentFrame = Convert.ToInt32(node.SelectSingleNode("signaturePosition").InnerText); //Хоязин OwnerName = node.SelectSingleNode("ownerName").InnerText; //Положение X = Convert.ToInt32(node.SelectSingleNode("x").InnerText); Y = Convert.ToInt32(node.SelectSingleNode("y").InnerText); //Ресурс здания MaxResource = int.Parse(node.SelectSingleNode("maxResource").InnerText); CurrentResource = MaxResource; Reduction = MaxResource / 10; Font = Helper.Game.SmallFont; //Размеры здания var param = node.SelectSingleNode("width"); int width = 0; int height = 0; if (param != null) width = Convert.ToInt32(param.InnerText); param = node.SelectSingleNode("height"); if (param != null) height = Convert.ToInt32(param.InnerText); if (width != 0 && height != 0) { Rect = new Rectangle(X, Y, width, height); Width = width; Height = height; } else { Width = Sprite.Width; Height = Sprite.Height; Rect = new Rectangle(X, Y, Width, Height); } EnemySelector = Helper.Game.Selectors[0]; OurSelector = Helper.Game.Selectors[1]; }
/// <summary> /// Создаёт новый экземпляр класса <see cref="ComboBox"/>. /// </summary> /// <param name="game">The game.</param> /// <param name="values">The values.</param> public ComboBox(SourceryGame game, List <String> values) { _Values = new List <Control>(); foreach (string str in values) { _Values.Add(new PanelItem(game, str, "Font")); } foreach (Control item in _Values) { item.OnValueChanged += OnElementSelected; } _Sprite = new AnimateSprite(game.ComboBox, 3, 1); _Panel = game.ItemPanel; _Font = game.Font; }
/// <summary>Загружаем параметры из документа</summary> /// <param name="node">Запись.</param> /// <param name="game">Ссылка на игру.</param> private void LoadFromDocument(XmlNode node, SourceryGame game) { //Читаем настройки из файла _UpdateDelay = int.Parse(node.SelectSingleNode("UpdateDelay").InnerText); _MaxLevel = int.Parse(node.SelectSingleNode("MaxLevel").InnerText); Sprite = new AnimateSprite(game.Content.Load <Texture2D>("Game/" + node.SelectSingleNode("Texture").InnerText), 5, 5); Sprite.CurrentFrame = Convert.ToInt32(node.SelectSingleNode("position").InnerText); Signature = new AnimateSprite(game.ColorStripe, 1, 5); Signature.CurrentFrame = int.Parse(node.SelectSingleNode("signaturePosition").InnerText); X = Convert.ToInt32(node.SelectSingleNode("x").InnerText); Y = Convert.ToInt32(node.SelectSingleNode("y").InnerText); _Level = Convert.ToInt32(node.SelectSingleNode("level").InnerText); OwnerName = node.SelectSingleNode("ownerName").InnerText; MaxResource = 50 + 25 * (_Level - 1); CurrentResource = MaxResource; Reduction = MaxResource / 10; var param = node.SelectSingleNode("width"); int width = 0; int height = 0; if (param != null) { width = Convert.ToInt32(param.InnerText); } param = node.SelectSingleNode("height"); if (param != null) { height = Convert.ToInt32(param.InnerText); } //Задаем начальные параметры if (width != 0 && height != 0) { Rect = new Rectangle(X, Y, width, height); Width = width; Height = height; } else { Width = Sprite.Width; Height = Sprite.Height; Rect = new Rectangle(X, Y, Width, Height); } }
/// <summary>Загружаем все необходимое для отрисовки</summary> private void LoadSprites(SourceryGame game) { _Font = game.Font; _BigFont = game.BigFont; _Back = new AnimateSprite(game.Content.Load<Texture2D>("controls/ReloadingButton"), 3, 1); LoadSprite(game); }
/// <summary>Загружаем необходиоме</summary> public override void LoadContent() { _Font = Helper.Game.BigFont; _Loader = new AnimateSprite(Helper.Game.Loader, 1, 11); }
/// <summary>Загружает параметры игрока из XML-файла</summary> /// <param name="node">Запись об игроке.</param> /// <param name="game">Ссылка на игру.</param> public void LoadPlayerParameters(XmlNode node, SourceryGame game) { //Читаем параметры из *.lvl string playerName = node.SelectSingleNode("Name").InnerText; string fileName = node.SelectSingleNode("File").InnerText; int x = Convert.ToInt32(node.SelectSingleNode("x").InnerText); int y = Convert.ToInt32(node.SelectSingleNode("y").InnerText); int startAnimation = Convert.ToInt32(node.SelectSingleNode("StartAnimation").InnerText); var type = node.SelectSingleNode("Type").InnerText; PlayerType playerType = (PlayerType)Enum.Parse(typeof(PlayerType), type); type = node.SelectSingleNode("Color").InnerText; Colors color = (Colors)Enum.Parse(typeof(Colors), type); //Читаем параметры героя XmlDocument doc = new XmlDocument(); doc.Load("data/players/" + fileName); string textureName = doc.SelectSingleNode("Player/Texture").InnerText; int width = int.Parse(doc.SelectSingleNode("Player/width").InnerText); int height = int.Parse(doc.SelectSingleNode("Player/height").InnerText); int speed = int.Parse(doc.SelectSingleNode("Player/speed").InnerText); _Animation = new PlayerAnimation(doc.SelectSingleNode("Player/Animation")); //Задаем начальные параметры _Tile = new AnimateSprite(game.Content.Load<Texture2D>("animation/" + textureName), 8, 24); _Tile.CurrentFrame = startAnimation; LoadColor(color); _CurrentState = new Rectangle(x-width/2, y-height/2, width, height); _Type = playerType; if (playerName == "") Name = game.PlayerName; else Name = playerName; foreach (Cell cell in Helper.Board) if (cell.Rect.Contains(x, y)) { _CurrentCell = cell; break; } CurrentMagic = MaxMagic; _Movement = new Movement(_CurrentState, _CurrentCell, speed, _Tile, _Animation,false); }
//Загрузим соответствующий спрайт private void LoadSprite(SourceryGame game) { string name = _Node.SelectSingleNode("Animations/Texture").InnerText; int start = int.Parse(_Node.SelectSingleNode("Animations/Start").InnerText); int stop = int.Parse(_Node.SelectSingleNode("Animations/Stop").InnerText); int current = int.Parse(_Node.SelectSingleNode("Animations/Current").InnerText); _Sprite = new AnimateSprite(game.Content.Load<Texture2D>("animation/"+name),8,8); From = start; To = stop; Static = current; _Sprite.CurrentFrame = Static; }
/// <summary>Загружаем параметры из документа</summary> /// <param name="node">Запись.</param> /// <param name="game">Ссылка на игру.</param> private void LoadFromDocument(XmlNode node, SourceryGame game) { //Читаем настройки из файла _UpdateDelay = int.Parse(node.SelectSingleNode("UpdateDelay").InnerText); _MaxLevel = int.Parse(node.SelectSingleNode("MaxLevel").InnerText); Sprite = new AnimateSprite(game.Content.Load<Texture2D>("Game/" + node.SelectSingleNode("Texture").InnerText), 5, 5); Sprite.CurrentFrame = Convert.ToInt32(node.SelectSingleNode("position").InnerText); Signature = new AnimateSprite(game.ColorStripe, 1, 5); Signature.CurrentFrame = int.Parse(node.SelectSingleNode("signaturePosition").InnerText); X = Convert.ToInt32(node.SelectSingleNode("x").InnerText); Y = Convert.ToInt32(node.SelectSingleNode("y").InnerText); _Level= Convert.ToInt32(node.SelectSingleNode("level").InnerText); OwnerName = node.SelectSingleNode("ownerName").InnerText; MaxResource = 50 + 25 * (_Level - 1); CurrentResource = MaxResource; Reduction = MaxResource / 10; var param = node.SelectSingleNode("width"); int width = 0; int height = 0; if (param != null) width = Convert.ToInt32(param.InnerText); param = node.SelectSingleNode("height"); if (param != null) height = Convert.ToInt32(param.InnerText); //Задаем начальные параметры if (width != 0 && height != 0) { Rect = new Rectangle(X, Y, width, height); Width = width; Height = height; } else { Width = Sprite.Width; Height = Sprite.Height; Rect = new Rectangle(X,Y,Width,Height); } }