Ejemplo n.º 1
0
        public void Draw(SpriteBatch Target, Camera cam)//TODO: Dobavit param dla begin
        {
            foreach (var Tile in Tiles)
            {
                foreach (var Til in Tile)
                {
                    if (Til != null)
                    {
                        Til.DrawDecoration(Target);
                        Til.Draw(Target);
                    }
                }
            }

            foreach (var CP in ControlPoints)
            {
                CP.Draw(Target);
            }

            Attack_Radius.Draw(Target);

            Target.End();

            Target.Begin(SpriteSortMode.BackToFront);
            foreach (var arrow in PathFindingArrows)
            {
                arrow.Draw(Target);
            }
            Target.End();

            Target.Begin(SpriteSortMode.BackToFront, null, null, null, null, null, cam.GetTransform());
            foreach (var Tile in Tiles)
            {
                foreach (var Til in Tile)
                {
                    if (Til != null)
                    {
                        Til.DrawUnit(Target);
                    }
                }
            }

            FlyingTextProcessor.Draw(Target);
            Target.End();

            Target.Begin(SpriteSortMode.BackToFront);
            Info.Draw(Target);
            foreach (var Tile in Tiles)
            {
                foreach (var Til in Tile)
                {
                    if (Til != null && Til.UnitOnTile != null)
                    {
                        Til.UnitOnTile.DrawUI(Target, cam);
                    }
                }
            }
            Target.End();

            Target.Begin(SpriteSortMode.BackToFront, null, null, null, null, null, cam.GetTransform());
        }
Ejemplo n.º 2
0
 public void Update(Map map, Camera cam)
 {
     UpdateAnims();
     if (!IsAttacking && IsDestroying)
     {
         if (CurrAnimName == null || CurrAnimName == "NONE")
         {
             if (IsDestroyAnimPlayed)
             {
                 Visible = false;
                 map.RemoveUnit(this);
             }
             else
             {
                 PlayAnimation("Destroy");
                 IsDestroyAnimPlayed = true;
             }
         }
     }
     else
     {
         if (MoveList.Count > 0 && !(IsSpawning || IsMoving))
         {
             var NextMove = MoveList.Dequeue();
             AddVector = new Vector2((NextMove.FirstPoint.X - NextMove.LastPoint.X) / 20, (NextMove.FirstPoint.Y - NextMove.LastPoint.Y) / 20);
             SetFrame(NextMove.Direct);
             IsMoving  = true;
             iteration = 0;
         }
         if (iteration < 20)
         {
             if (IsMoving)
             {
                 Position -= AddVector;
                 if (iteration == 19)
                 {
                     IsMoving = false;
                 }
             }
             else
             if (IsSpawning && iteration < 10)
             {
                 Scale    = new Vector2(Scale.X - 0.05f, Scale.Y - 0.05f);
                 Position = new Vector2(Position.X, Position.Y + 5);
                 if (iteration == 9)
                 {
                     IsSpawning = false;
                 }
             }
             iteration++;
         }
         if (IsAttacking)
         {
             var tmp = AttScr_Update.Call(this, ScriptRuntimeInfo, IsAttacking);
             if (tmp == null)
             {
                 ScriptRuntimeInfo = null;
             }
             else
             {
                 ScriptRuntimeInfo = tmp[0] as LuaTable;
                 IsAttacking       = (bool)tmp[1];
                 if (!IsAttacking)
                 {
                     FlyingTextProcessor.CreateText(EnemyDamageFLPos, EnemyDamageFLPos - new Vector2(0, 300), 160, "-" + AttackDamage.ToString(), FLFont, Color.Red, new Vector2(4), 0.1f);
                     AttackedUnit.HP -= AttackDamage;
                     if (AttackedUnit.HP <= 0)
                     {
                         AttackedUnit.Destroy();
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
        public void Update(ref bool IsMouseHandled, Hand hand, Camera cam, bool IsPlayerTurn, MapZones Opponent, GameState gameState)
        {
            if (MouseControl.IsRightBtnClicked)
            {
                if (IsPathFinding)
                {
                    IsPathFinding = false;
                    SetDefault();
                    UpdateAllTiles(cam);
                    CreatePathArrows(null, cam);
                }
                else
                if (IsAttack)
                {
                    IsAttack = false;
                    SetDefault();
                    UpdateAllTiles(cam);
                    CreatePathArrows(null, cam);
                }
                else
                {
                    DeSelectTile(SelectedTile);
                }
            }
            if (_ChoosedTileI == -1 || _ChoosedTileJ == -1)
            {
                for (var i = 0; i < Tiles.Length; i++)
                {
                    for (var j = 0; j < Tiles[0].Length; j++)
                    {
                        if (Tiles[i][j] != null)
                        {
                            Tiles[i][j].UpdateAnims();
                            if (!IsMouseHandled && Tiles[i][j].Update(cam: cam) != ButtonStates.NONE)
                            {
                                IsMouseHandled = true;
                                _ChoosedTileI  = i;
                                _ChoosedTileJ  = j;
                            }
                            else
                            {
                                Tiles[i][j].StopAnimation(true, Tiles[i][j].NotSelectedFrame);
                            }
                            Tiles[i][j].UpdateUnit(this, cam);
                        }
                    }
                }
            }
            else
            if (Tiles[_ChoosedTileI][_ChoosedTileJ] != null)
            {
                Tiles[_ChoosedTileI][_ChoosedTileJ].UpdateAnims();
                var UpdateResult = Tiles[_ChoosedTileI][_ChoosedTileJ].Update(cam: cam);
                if (!IsMouseHandled && UpdateResult != ButtonStates.NONE)
                {
                    IsMouseHandled = true;
                    if (UpdateResult == ButtonStates.CLICKED)
                    {
                        if (IsPathFinding)
                        {
                            IsPathFinding = false;
                            int          PL;
                            List <Point> Marked;

                            var Path = PathFinding(ActionStartPoint.X, ActionStartPoint.Y, _ChoosedTileI, _ChoosedTileJ, Tiles[ActionStartPoint.X][ActionStartPoint.Y].UnitOnTile.MovePointsLeft, out PL, out Marked, Opponent);
                            if (Path != null)
                            {
                                var Command = new string[Path.Count + 1];
                                Command[0] = "MOVE";
                                for (var i = 1; i < Command.Length; i++)
                                {
                                    Command[i] = Path[i - 1].X.ToString() + " " + Path[i - 1].Y.ToString();
                                }
                                CommandParser.SendCommandToGameServer(Command);
                                gameState.SetEnemyTurn();
                            }
                            //UnitMove(PathFinding(ActionStartPoint.X, ActionStartPoint.Y, _ChoosedTileI, _ChoosedTileJ, Tiles[ActionStartPoint.X][ActionStartPoint.Y].UnitOnTile.MovePointsLeft, out PL, out Marked, Opponent));

                            SetDefault();
                            UpdateAllTiles(cam);
                            CreatePathArrows(null, cam);
                            DeSelectTile(SelectedTile);
                            SelectTile(new Point(_ChoosedTileI, _ChoosedTileJ));
                            //Переместить
                        }
                        else
                        if (IsAttack)
                        {
                            IsAttack = false;

                            if (EnemyFinding(ActionStartPoint.X, ActionStartPoint.Y, Tiles[ActionStartPoint.X][ActionStartPoint.Y].UnitOnTile.AttackDistance).Contains(new Point(_ChoosedTileI, _ChoosedTileJ)))
                            {
                                //Tiles[ActionStartPoint.X][ActionStartPoint.Y].UnitOnTile.Attack(Tiles[_ChoosedTileI][_ChoosedTileJ].UnitOnTile);
                                CommandParser.SendCommandToGameServer(new string[] { "ATTACK", ActionStartPoint.X.ToString(), ActionStartPoint.Y.ToString(), _ChoosedTileI.ToString(), _ChoosedTileJ.ToString() });
                                gameState.SetEnemyTurn();
                            }

                            SetDefault();
                            UpdateAllTiles(cam);
                            CreatePathArrows(null, cam);
                        }
                        else
                        {
                            if (SelectedTile.X != -1)
                            {
                                DeSelectTile(SelectedTile);
                            }
                            if (IsPlayerTurn)
                            {
                                SelectTile(new Point(_ChoosedTileI, _ChoosedTileJ));
                            }
                        }
                    }

                    if (IsPathFinding)
                    {
                        int          PL;
                        List <Point> Marked;
                        CreatePathArrows(PathFinding(ActionStartPoint.X, ActionStartPoint.Y, _ChoosedTileI, _ChoosedTileJ, Tiles[ActionStartPoint.X][ActionStartPoint.Y].UnitOnTile.MovePointsLeft, out PL, out Marked, Opponent), cam);
                        foreach (var Til in Marked)
                        {
                            if (!ChangedAnimTiles.Contains(Til))
                            {
                                ChangedAnimTiles.Add(Til);
                            }
                        }
                        foreach (var TilCoords in Marked)
                        {
                            ChangeTilesAnims(2, 1, new Animation(1, 1, true), TilCoords);
                        }
                    }
                    else
                    if (IsAttack)
                    {
                        Attack_Radius.Visible = true;
                        var EnFind = EnemyFinding(ActionStartPoint.X, ActionStartPoint.Y, Tiles[ActionStartPoint.X][ActionStartPoint.Y].UnitOnTile.AttackDistance);
                        foreach (var Til in EnFind)
                        {
                            if (!ChangedAnimTiles.Contains(Til))
                            {
                                ChangedAnimTiles.Add(Til);
                            }
                        }
                        foreach (var TilCoords in EnFind)
                        {
                            ChangeTilesAnims(2, 1, new Animation(1, 1, true), TilCoords);
                        }
                        if (EnFind.Contains(new Point(_ChoosedTileI, _ChoosedTileJ)))
                        {
                            var TmpList = new List <Point>();
                            TmpList.Add(new Point(ActionStartPoint.X, ActionStartPoint.Y));
                            TmpList.Add(new Point(_ChoosedTileI, _ChoosedTileJ));
                            CreatePathArrows(TmpList, cam);
                        }
                        else
                        {
                            CreatePathArrows(null, cam);
                        }
                    }

                    if (hand.ChoosedCard == -1)
                    {
                        Info.Appear();
                        Info.Position           = new Vector2(MouseControl.X - Info.Texture.Width / 2, MouseControl.Y + 20);
                        Info.NeedMovePointsText = Tiles[_ChoosedTileI][_ChoosedTileJ].MovingPointsNeeded.ToString();
                        Info.DefenseText        = Tiles[_ChoosedTileI][_ChoosedTileJ].GiveArmor.ToString();
                    }
                }
                else
                {
                    Info.Disappear();
                    Tiles[_ChoosedTileI][_ChoosedTileJ].StopAnimation(true, Tiles[_ChoosedTileI][_ChoosedTileJ].NotSelectedFrame);
                    _ChoosedTileI = -1;
                    _ChoosedTileJ = -1;
                }
                for (var i = 0; i < Tiles.Length; i++)
                {
                    for (var j = 0; j < Tiles[0].Length; j++)
                    {
                        if (Tiles[i][j] != null)
                        {
                            Tiles[i][j].UpdateUnit(this, cam);
                        }
                    }
                }
            }
            Info.Update();
            FlyingTextProcessor.Update();
        }