示例#1
0
        /// <summary>
        /// Initiliaze a new alien army.
        /// </summary>
        /// <param name="centre">Centre of the army.</param>
        /// <param name="width">Number of columns composing the army.</param>
        /// <param name="height">Number of rows in each column.</param>
        /// <param name="alienSize">Size of aliens.</param>
        /// <param name="margin">Space to leave between aliens.</param>
        public void Initialize(Vector2 centre, int width, int height, Vector2 alienSize, Vector2 margin)
        {
            float armyWidth = width * (alienSize.X + margin.X) - margin.X;
              float armyHeight = height * (alienSize.Y + margin.Y) - margin.Y;

              float lowestPos = centre.Y - armyHeight * .5f;
              float rightMostPos = centre.X - armyWidth * .5f;
              float leftMostPos = centre.X + armyWidth * .5f;

              columns = new AlienColumn[width];

              for (int i = 0; i < width; ++i) {
            columns[i] = new AlienColumn();
            columns[i].Initialize(
              height,
              new Vector2(rightMostPos + alienSize.X * .5f + i * (alienSize.X + margin.X), lowestPos),
              alienSize,
              margin.Y);
              }

              Position = centre;
              Size = new Vector2(
            columns[width - 1].Area.TopRight.X - columns[0].Area.TopLeft.X,
            columns[0].Area.TopLeft.Y - columns[0].Area.BottomLeft.Y);

              Game.Updatables.Add(this);
        }
示例#2
0
 public Alien(AlienColumn column, AlienType type, Vector2 position, Vector2 size)
     : base(position, size)
 {
     Column = column;
     Type = type;
 }