Пример #1
0
        public static void SetVisitTime(Vector2 pos)
        {
            CellInformation cel = GetCell(pos);

            if (cel != null)
            {
                cel.SetVisitTime();
            }
        }
Пример #2
0
        public static Direction GetOldestDirection(Vector2 position, List <Direction> allowedDirection)
        {
            Direction resultDirection     = Direction.None;
            int       minTimeToVisibility = int.MaxValue;

            if (allowedDirection.Contains(Direction.Left))
            {
                Vector2         leftPos     = new Vector2(position.X - Default.CellSetting.CellSize.X, position.Y);
                CellInformation currentCell = GetCell(leftPos);

                if (currentCell != null && minTimeToVisibility > currentCell.GetVisitTime())
                {
                    minTimeToVisibility = currentCell.GetVisitTime();
                    resultDirection     = Direction.Left;
                }
            }

            if (allowedDirection.Contains(Direction.Down))
            {
                Vector2         leftPos     = new Vector2(position.X, position.Y + Default.CellSetting.CellSize.Y);
                CellInformation currentCell = GetCell(leftPos);

                if (currentCell != null && minTimeToVisibility > currentCell.GetVisitTime())
                {
                    minTimeToVisibility = currentCell.GetVisitTime();
                    resultDirection     = Direction.Down;
                }
            }

            if (allowedDirection.Contains(Direction.Right))
            {
                Vector2         leftPos     = new Vector2(position.X + Default.CellSetting.CellSize.X, position.Y);
                CellInformation currentCell = GetCell(leftPos);

                if (currentCell != null && minTimeToVisibility > currentCell.GetVisitTime())
                {
                    minTimeToVisibility = currentCell.GetVisitTime();
                    resultDirection     = Direction.Right;
                }
            }

            if (allowedDirection.Contains(Direction.Up))
            {
                Vector2         leftPos     = new Vector2(position.X, position.Y - Default.CellSetting.CellSize.Y);
                CellInformation currentCell = GetCell(leftPos);

                if (currentCell != null && minTimeToVisibility > currentCell.GetVisitTime())
                {
                    minTimeToVisibility = currentCell.GetVisitTime();
                    resultDirection     = Direction.Up;
                }
            }

            return(resultDirection);
        }
Пример #3
0
        private static bool?Check(Vector2 v)
        {
            if (!Map.ContainsKey(v))
            {
                return(false);
            }

            CellInformation cell = Map[v];

            if (cell.GetOwnerType() == AnimatedSprites.GameSettings.Default.WallSetting.IndestructibleWall || cell.GetOwnerType() == AnimatedSprites.GameSettings.Default.WallSetting.Wall)
            {
                return(false);
            }
            else
            {
                if (user.collisionRect.Intersects(new Rectangle((int)v.X, (int)v.Y, (int)(Default.TankSetting.FrameSize.X * SpriteSettings.Scale), (int)(Default.TankSetting.FrameSize.Y * SpriteSettings.Scale))))
                {
                    return(true);
                }
            }

            return(null);
        }
Пример #4
0
        void UpdateSprites(GameTime gameTime)
        {
            if (tanks.Count > 0)
            {
                List <Sprite> spawnedSprites = new List <Sprite>();
                for (int i = 0; i < tanks.Count; ++i)
                {
                    Sprite s = tanks[i];

                    s.Update(gameTime);

                    if (s is Missile)
                    {
                        for (int j = 0; j < tanks.Count; j++)
                        {
                            if (i == j)
                            {
                                continue;
                            }

                            if (tanks[j].State == SpriteState.Alive &&
                                s.State == SpriteState.Alive &&
                                s.collisionRect.Intersects(tanks[j].collisionRect))
                            {
                                Collisions.ReleaseCollision(s, tanks[j]);
                                break;
                            }
                        }

                        CellInformation cell = MapInfo.Intersects(s.collisionRect);
                        if (cell != null)
                        {
                            cell.ClearOwner();
                            s.Destroy();
                        }
                    }

                    if (s is Tank)
                    {
                        Missile m = (s as Tank).CurrentMissle;
                        if (m != null && m.State == SpriteState.Alive && !tanks.Contains(m) && !spawnedSprites.Contains(m))
                        {
                            spawnedSprites.Add(m);
                        }
                    }

                    // Удаляем объект, если он вне поля
                    if (Game.Window.ClientBounds.X > 0 && s.IsOutOfBounds(Game.Window.ClientBounds))
                    {
                        s.State = SpriteState.Destroyed;
                    }

                    if (s.State == SpriteState.Destroyed)
                    {
                        tanks.RemoveAt(i);
                        --i;
                    }
                }

                tanks.AddRange(spawnedSprites);
            }
        }