public static void RectangleAroundCell(ref Frame frame, ESprite sprite, double x, double y) { double xx = Const.FieldOriginX + x * Const.TileWidth; double yy = Const.FieldOriginY + y * Const.TileHeight; Rectangle(ref frame, sprite, xx, yy, Const.TileWidth, Const.TileHeight); }
public static void Rectangle(ref Frame frame, ESprite sprite, double x, double y, double w, double h) { double pointSz = Const.TileHeight / 15; frame.Add(new Sprite(sprite, w, pointSz, new Vector2(x + w / 2, y))); frame.Add(new Sprite(sprite, pointSz, h, new Vector2(x, y + h / 2))); frame.Add(new Sprite(sprite, w, pointSz, new Vector2(x + w / 2, y + h))); frame.Add(new Sprite(sprite, pointSz, h, new Vector2(x + w, y + h / 2))); }
public void Draw(ref Frame frame, double stage, int turnNumber) { if (currAnim == null) { if (anims.Count == 0) { isFinished = true; return; } currAnim = anims.Dequeue(); if (!Utility.doubleEqual(lastPos.x, -1)) { currAnim.Pos = lastPos; } } if (Utility.doubleGreaterOrEqual(stage, currAnim.GetAnimationsStart())) { currAnim.Draw(ref frame, stage, turnNumber); } if (currAnim.CurrentSprite == ESprite.explosionNuclear && !currAnim.IsAnimationsFinished()) { double pointSz = Const.TileHeight / 15; ESprite sprite = ESprite.explosionPoint; double x = currAnim.Pos.x - Const.TileWidth * 2.5; double y = currAnim.Pos.y - Const.TileHeight * 2.5; double w = Const.TileWidth * 5; double h = Const.TileHeight * 5; double alpha = -2 * Math.Pow((currAnim.CurrentInnerStage - 0.5), 2) + 1; frame.Add(new Sprite(sprite, w, pointSz, new Vector2(x + w / 2, y)) { Alpha = alpha }); frame.Add(new Sprite(sprite, pointSz, h, new Vector2(x, y + h / 2)) { Alpha = alpha }); frame.Add(new Sprite(sprite, w, pointSz, new Vector2(x + w / 2, y + h)) { Alpha = alpha }); frame.Add(new Sprite(sprite, pointSz, h, new Vector2(x + w, y + h / 2)) { Alpha = alpha }); } if (currAnim.IsAnimationsFinished()) { lastPos = currAnim.Pos; currAnim = null; Draw(ref frame, stage, turnNumber); } }
/// <param name="name">какой спрайт</param> /// <param name="frame">номер кадра, если анимация. Начинаем с 0</param> /// <param name="width">ширина</param> /// <param name="height">высота</param> /// <param name="pos">Где находится спрайт и угол поворота</param> public Sprite(ESprite name, double width, double height, Vector2 pos, int frame = 0) { if (name != ESprite.end) { this.frameCount = Config.Sprites[name.ToString()].horFrames * Config.Sprites[name.ToString()].vertFrames; } else { this.frameCount = 0; } this.name = name; this.frame = frame; this.width = width; this.height = height; this.pos = pos; this.texture = name.ToString(); }
public static int GetSpriteFramesCount(ESprite sprite) { return(Sprites[sprite.ToString()].horFrames * Sprites[sprite.ToString()].vertFrames); }
public void drawSprite(ESprite eSprite, Vector2 textPos, SpriteEffects effectFlag = SpriteEffects.None) { spriteBatch_.Draw(spriteTex_, textPos, spriteRec_[eSprite][0], Color.White, 0f, Vector2.Zero, 2, effectFlag, 0f); }
public void drawAtRecPos(ESprite es, Rectangle rec, float transparency = 1f) { App.SpriteBatch.Draw(textureManager.getTexture(sprites[es].Value), rec, sprites[es].Key, Color.White * transparency); }
public void drawAtPos(ESprite es, Vector2 pos, float transparency = 1f) { App.SpriteBatch.Draw(textureManager.getTexture(sprites[es].Value), pos, sprites[es].Key, Color.White * transparency); }
internal void drawZoom(ESprite sprite, Vector2 pos, float sprtSize, float ort = 0f) { App.SpriteBatch.Draw(TextureManager.Instance.getTexture(sprites[sprite].Value), new Vector2(pos.X + (sprites[sprite].Key.Width * sprtSize) / 2, pos.Y + (sprites[sprite].Key.Height * sprtSize) / 2), sprites[sprite].Key, Color.White, ort, new Vector2(sprites[sprite].Key.Width / 2f, sprites[sprite].Key.Height /2f), sprtSize, Microsoft.Xna.Framework.Graphics.SpriteEffects.None, 0); }
public void drawRotatedAtPos(ESprite es, Vector2 pos, float ort, float sprtSize, float transparency = 1f) { // WHY DO WE NEED TO ADD PADDING ? App.SpriteBatch.Draw(textureManager.getTexture(sprites[es].Value), new Vector2(pos.X + sprtSize / 2, pos.Y + sprtSize / 2), sprites[es].Key, Color.White * transparency, ort, new Vector2(Constants.Measures.spriteSquareSize / 2f), sprtSize / Constants.Measures.spriteSquareSize, Microsoft.Xna.Framework.Graphics.SpriteEffects.None, 0); }
bool GetTurn(State state, Player player, IGetKeyboardState keyboard, out Turn retTurn, ref Frame frame) { retTurn = null; if (player.programAddress != null) { retTurn = GetTurnFromProgramExecuter(state, player); return(true); } ESprite color = player.Owner == OwnerType.Player1 ? ESprite.gridPoint1 : ESprite.gridPoint2; player.moneySpent = _commandsFromKeyboard.Where(x => x.type == Turn.CommandType.Buy).Sum(x => CreateUnit(x.arguments[0]).Cost); int cellLine, cellPosition; bool mouseInField = GetCellUnderMouse(keyboard, out cellLine, out cellPosition); if (mouseInField) { Animator.RectangleAroundCell(ref frame, color, cellPosition, cellLine); if (keyboard.MouseClick) { bool unitAtBase = player.Units[cellLine] != null && player.Units[cellLine].AtBase(); bool unitJustCreated = _commandsFromKeyboard.Exists(x => x.type == Turn.CommandType.Buy && x.arguments[1] == cellLine); if (unitAtBase || unitJustCreated) { _commandsFromKeyboard.Add(new Turn.Command(Turn.CommandType.Start, cellLine, cellPosition)); } else { state.Message = "Нет юнита на базе"; } } for (var unitAction = EKeyboardAction.Unit1; unitAction <= EKeyboardAction.Unit5; unitAction++) { if (keyboard.GetActionTime(unitAction) == 1) { int type = (int)unitAction - (int)EKeyboardAction.Unit1 + 1; var unit = CreateUnit(type); int playerMoney = player.Money - player.moneySpent; if (player.Units[cellLine] != null && !player.Units[cellLine].AtBase()) { state.Message = "Горизонталь занята"; } else if (playerMoney >= unit.Cost) { //предыдущее убираем, чтобы деньги зря не расходовали _commandsFromKeyboard.RemoveAll(x => x.type == Turn.CommandType.Buy && x.arguments[1] == cellLine); // _commandsFromKeyboard.Add(new Turn.Command(Turn.CommandType.Remove,cellLine )); _commandsFromKeyboard.Add(new Turn.Command(Turn.CommandType.Buy, type, cellLine, 1)); _commandsFromKeyboard.Add(new Turn.Command(Turn.CommandType.Start, cellLine, cellPosition)); } else { state.Message = "Недостаточно денег"; } } } } //рисуем выделенные ранее клетки и цифры , если создан юнит for (int i = 0; i < Const.NumberOfLines; i++) { var lastStartCommandonThisLine = _commandsFromKeyboard.LastOrDefault(x => x.type == Turn.CommandType.Start && x.arguments[0] == i); if (lastStartCommandonThisLine != null) { Animator.RectangleAroundCell(ref frame, color, lastStartCommandonThisLine.arguments[1], i); } var lastBuyCommandonThisLine = _commandsFromKeyboard.LastOrDefault(x => x.type == Turn.CommandType.Buy && x.arguments[1] == i); if (lastBuyCommandonThisLine != null) { Animator.TextInCell(ref frame, player.Owner == OwnerType.Player1 ? EFont.green : EFont.red, lastBuyCommandonThisLine.arguments[0].ToString(), lastStartCommandonThisLine.arguments[1], i); } } //dont forget to reflect everything in the end if (keyboard.GetActionTime(EKeyboardAction.Enter) == 1) { if (player.Owner == OwnerType.Player2) { _commandsFromKeyboard.Where(x => x.type == Turn.CommandType.Start).ToList().ForEach(x => x.arguments[1] = Reflect(x.arguments[1])); _commandsFromKeyboard.Where(x => x.type == Turn.CommandType.Buy).ToList().ForEach(x => x.arguments[2] = Reflect(x.arguments[2])); } retTurn = new Turn { commands = _commandsFromKeyboard, TurnStatus = ExternalProgramExecuteResult.Ok }; _commandsFromKeyboard = new List <Turn.Command>(); retTurn.input = GetInput(state, player, player.Owner == OwnerType.Player1 ? state.players[1]: state.players[0]); return(true); } return(false); }